id
stringlengths
2
7
text
stringlengths
17
51.2k
title
stringclasses
1 value
c164900
for i := 0; i < n_obs; i++ { max_ix := 0 max_pr := math.Inf(-1) x := X.RawRowView(i) for k := 0; k < n_comps; k++ { pr := N[k].LogProb(x) if pr > max_pr { max_ix = k max_pr = pr } } y_new.SetVec(i, float64(max_ix)) } return y_new }
c164901
append(points, X.At(i, j)) } variance := stat.Variance(points, nil) // set the jth diagonal entry to the variance covs.SetSym(j, j, variance) } return covs }
c164902
:= vectorMax(v) r := min + rand.Float64()*(max-min) results = append(results, r) } } means := mat.NewDense(n_comps, n_feats, results) return means }
c164903
for k := 0; k < n_comps; k++ { matrix := mat.NewSymDense(n_feats, floats) result = append(result, matrix) } return result }
c164904
p.Means.RawRowView(i) means_new_i := p_new.Means.RawRowView(i) for j := 0; j < n_feats; j++ { dist += math.Pow((means_i[j] - means_new_i[j]), 2) } } return math.Sqrt(dist) }
c164905
i++ { if v.At(i, 0) < min { min = v.At(i, 0) } } return min }
c164906
i++ { if v.At(i, 0) > max { max = v.At(i, 0) } } return max }
c164907
< n_obs; i++ { ints[i] = int(v.At(i, 0)) } return ints }
c164908
sum_j = sum_j + X.At(i, j) } mean := (sum_j / float64(n_obs)) result = append(result, mean) } return result }
c164909
n_obs; i++ { if int(y.At(i, 0)) == target { for j := 0; j < n_feats; j++ { result = append(result, X.At(i, j)) } rows++ } } X_i := mat.NewDense(rows, n_feats, result) return X_i }
c164910
results = append(results, 1) } else { results = append(results, 0) } } } return results }
c164911
{ results = append(results, v) } return results }
c164912
NonClassAttributes(inst) cAttrs := inst.AllClassAttributes() for _, c := range cAttrs { attrs = append(attrs, c) } return SerializeInstancesToDenseARFFWithAttributes(inst, attrs, path, relation) }
c164913
} defer f.Close() return SerializeInstancesToWriterDenseARFFWithAttributes(f, inst, rawAttrs, relation) }
c164914
continue } if line[0] == '%' { continue } count++ continue } if line[0] == '@' { line = strings.ToLower(line) if line == "@data" { counting = true } } } return count, nil }
c164915
// Set the last Attribute as the class ret.AddClassAttribute(attrs[len(attrs)-1]) ret.Extend(rows) f, err := os.Open(filepath) if err != nil { return nil, err } defer f.Close() // Read the data // Seek past the header err = ParseDenseARFFBuildInstancesFromReader(f, attrs, ret) if err != nil { ret = n...
c164916
f, nil, nil, 0, nil, nil, } }
c164917
len(data) == 1 { t.firstDiv = &node{feature: -1, srcRowNo: 0} t.firstDiv.value = make([]float64, len(data[0])) copy(t.firstDiv.value, data[0]) } else { t.firstDiv = t.buildHandle(newData, 0) } return nil }
c164918
n.left = t.buildHandle(data[:divPoint], (featureIndex+1)%len(t.data[data[0]])) } if divPoint == (len(data) - 2) { n.right = &node{feature: -1} n.right.value = make([]float64, len(t.data[data[divPoint+1]])) copy(n.right.value, t.data[data[divPoint+1]]) n.right.srcRowNo = data[divPoint+1] } else if divPoint...
c164919
make(map[Attribute]bool), true, } for i, a := range rows { ret.rows[i] = a } ret.addClassAttrsFromSrc(src) return ret }
c164920
nil, make(map[Attribute]bool), false, } ret.addClassAttrsFromSrc(src) return ret }
c164921
v.attrs == nil { return v.src.GetAttribute(a) } // Otherwise for _, r := range v.attrs { // If the attribute matches... if r.GetAttribute().Equals(a) { return r, nil } } return AttributeSpec{}, fmt.Errorf("Requested Attribute has been filtered") }
c164922
for i, a := range v.attrs { ret[i] = a.GetAttribute() } return ret }
c164923
} } if !matched { return fmt.Errorf("Attribute has been filtered") } v.classAttrs[a] = true return nil }
c164924
v.classAttrs[a] = false return nil }
c164925
if v.classAttrs[a] { ret = append(ret, a) } } return ret }
c164926
rows if v.rows != nil { if v.maskRows { vSize = len(v.rows) } else if len(v.rows) > vSize { vSize = len(v.rows) } } return hSize, vSize }
c164927
maxRows; i++ { buffer.WriteString("\t") for _, a := range as { val := v.Get(a, i) buffer.WriteString(fmt.Sprintf("%s ", a.attr.GetStringFromSysVal(val))) } buffer.WriteString("\n") } missingRows := rows - maxRows if missingRows != 0 { buffer.WriteString(fmt.Sprintf("\t...\n%d row(s) undisplayed", m...
c164928
len(f.attributes)) // Add Attributes for i, a := range f.attributes { ret[i] = a } return ret }
c164929
= append(f.attributes, a) return nil }
c164930
KNN.NearestNeighbours = neighbours KNN.Weighted = false KNN.AllowOptimisations = true return &KNN }
c164931
error { KNN.TrainingData = trainingData return nil }
c164932
return err } fmt.Printf("writer: %v", writer) return KNN.SaveWithPrefix(writer, "") }
c164933
"TrainingInstances"), KNN.TrainingData, true) if err != nil { return err } err = writer.Close() return err }
c164934
if err != nil { return err } return KNN.LoadWithPrefix(reader, "") }
c164935
= metadata["neighbours"].(int) KNN.Weighted = metadata["weighted"].(bool) KNN.AllowOptimisations = metadata["allow_optimizations"].(bool) // 101 on why JSON is a bad serialization format floatNeighbours := metadata["neighbours"].(float64) KNN.NearestNeighbours = int(floatNeighbours) KNN.TrainingData, err = rea...
c164936
:= &KNNClassifier{} err := stub.Load(filePath) if err != nil { return nil, err } return stub, nil }
c164937
KNNRegressor{} KNN.DistanceFunc = distfunc return &KNN }
c164938
make(map[base.Attribute]int), layers, 0, 0, 0.001, 500, 0.90, } }
c164939
m.layers, m.network, m.Convergence, m.LearningRate, m.MaxIterations) }
c164940
i < m.network.size; i++ { a.Set(i, 0, 0.0) } // Build the activation vector for i, vb := range row { if cIndex, ok := m.attrs[inputAs[i].GetAttribute()]; !ok { panic("Can't resolve the Attribute!") } else { a.Set(cIndex, 0, base.UnpackBytesToFloat(vb)) } } // Robots, activate! m.network...
c164941
} ret.classAttrs = make(map[int]bool) ret.Data = data ret.rows = rows return &ret }
c164942
} return AttributeSpec{}, fmt.Errorf("Couldn't find a matching attribute") }
c164943
a := range m.attributes { ret[i] = a } return ret }
c164944
return err } m.classAttrs[as.position] = true return nil }
c164945
return err } m.classAttrs[as.position] = false return nil }
c164946
if m.classAttrs[i] { ret = append(ret, m.attributes[i]) } } return ret }
c164947
:= m.Data.At(row, as.position) return PackFloatToBytes(val) }
c164948
rowData[j] = make([]byte, 8) } for i := 0; i < m.rows; i++ { for j, as := range as { PackFloatToBytesInline(m.Data.At(i, as.position), rowData[j]) } stat, err := f(rowData, i) if !stat { return err } } return nil }
c164949
len(m.attributes), m.rows }
c164950
math.Log(float64(s[a][c])/float64(count)) / math.Log(2) } } ret += total / float64(count) * math.Log(total/float64(count)) / math.Log(2) } return ret }
c164951
for c := range s[a] { total += float64(s[a][c]) } for c := range s[a] { ret -= float64(s[a][c]) / float64(count) * math.Log(float64(s[a][c])/float64(count)) / math.Log(2) } ret += total / float64(count) * math.Log(total/float64(count)) / math.Log(2) } return ret }
c164952
s[k] } for k := range s { ret -= float64(s[k]) / float64(count) * math.Log(float64(s[k])/float64(count)) / math.Log(2) } return ret }
c164953
return err } defer syscall.Close(fd) // grab the dimensions for the console if err = kernel32_GetConsoleScreenBufferInfo(fd, &bi); err != nil { return err } *csbi = bi return nil }
c164954
config.ImageLicenses) var err error select { case err = <-errCh: case <-time.After(config.stateTimeout): err = errors.New("time out while waiting for image to register") } if err != nil { err := fmt.Errorf("Error waiting for image: %s", err) state.Put("error", err) ui.Error(err.Error()) return multist...
c164955
Replace: true, } err := reflectwalk.Walk(v, walker) if err != nil { return nil, err } if walker.Top != nil { v = walker.Top } return v, nil }
c164956
f, Replace: false, } err := reflectwalk.Walk(v, walker) if err != nil { return err } return nil }
c164957
if len(f.excludeSet) > 0 { _, ok := f.excludeSet[k] return !ok } return true }
c164958
{ return nil, fmt.Errorf("provided floating IP '%s' is already associated with port '%s'", id, floatingIP.PortID) } return floatingIP, nil }
c164959
false, err // stop and throw error out } for _, candidate := range candidates { if candidate.PortID != "" { continue // this floating IP is associated with port, move to next in list } // Floating IP is able to be allocated. freeFloatingIP = &candidate return false, nil // stop iterating over ...
c164960
return "", err } if len(interfaces) == 0 { return "", fmt.Errorf("instance '%s' has no interfaces", id) } return interfaces[0].PortID, nil }
c164961
nil { return GetFloatingIPNetworkIDByName(client, networkRef) } return networkRef, nil }
c164962
networkName) } // Check and return the first external network. if !externalNetworks[0].External { return "", fmt.Errorf("network %s is not external", networkName) } return externalNetworks[0].ID, nil }
c164963
if err != nil { return err } if state == target { return nil } return fmt.Errorf("retrying for state %s, got %s", target, state) }) errCh <- err return err }
c164964
locationString = "at" } message := fmt.Sprintf( "Pausing %s step '%s'. Press enter to continue.", locationString, name) result := make(chan string, 1) go func() { line, err := ui.Ask(message) if err != nil { log.Printf("Error asking for input: %s", err) } result <- line }() for ...
c164965
ioutil.TempDir(s.TempPath, "hyperv") } if err != nil { err = fmt.Errorf("Error creating build directory: %s", err) state.Put("error", err) ui.Error(err.Error()) return multistep.ActionHalt } log.Printf("Created build directory: %s", s.buildDir) // Record the build directory location for later steps st...
c164966
ui.Say("Deleting build directory...") err := os.RemoveAll(s.buildDir) if err != nil { ui.Error(fmt.Sprintf("Error deleting build directory: %s", err)) } }
c164967
&enumFlag{target: target, options: options} }
c164968
for _, p := range h.Provisioners { ts := CheckpointReporter.AddSpan(p.TypeName, "provisioner", p.Config) err := p.Provisioner.Provision(ctx, ui, comm) ts.End(err) if err != nil { return err } } return nil }
c164969
the '%s' flavor! Please, check the\n"+ "value of 'parallels_tools_flavor'. Valid flavors are: 'win', 'lin',\n"+ "'mac', 'os2' and 'other'", s.ParallelsToolsFlavor)) return multistep.ActionHalt } state.Put("parallels_tools_path", path) return multistep.ActionContinue }
c164970
err != nil { err = fmt.Errorf("Couldn't write to output directory: %s", err) state.Put("error", err) return multistep.ActionHalt } f.Close() os.Remove(f.Name()) s.success = true return multistep.ActionContinue }
c164971
tpl config.Variables = m.flagVars // Init the core core, err := packer.NewCore(&config) if err != nil { return nil, fmt.Errorf("Error initializing core: %s", err) } return core, nil }
c164972
nameSet[n] = struct{}{} } // Build our result set which is the names of all builds except // those in the given set. names := c.BuildNames() result := make([]string, 0, len(names)) for _, n := range names { if _, ok := nameSet[n]; !ok { result = append(result, n) } } return result } // W...
c164973
for errors. // This is kind of a hack, but it does the job. Basically: create // a pipe, use a scanner to break it into lines, and output each line // to the UI. Do this forever. errR, errW := io.Pipe() errScanner := bufio.NewScanner(errR) go func() { for errScanner.Scan() { m.Ui.Error(errScanner.Text()) ...
c164974
info (%s)", version)) var data bytes.Buffer data.WriteString(version) if err := comm.Upload(s.Path, &data, nil); err != nil { state.Put("error", fmt.Errorf("Error uploading Parallels version: %s", err)) return multistep.ActionHalt } return multistep.ActionContinue }
c164975
append(errs, fmt.Errorf("An image_version must be specified")) } if len(errs) > 0 { return errs } return nil }
c164976
the new CD/DVD drive...") cdrom, err := driver.DeviceAddCDROM(vmName, parallelsToolsPath) if err != nil { err = fmt.Errorf("Error attaching Parallels Tools ISO: %s", err) state.Put("error", err) ui.Error(err.Error()) return multistep.ActionHalt } // Track the device name so that we can can delete later ...
c164977
"--device-del", s.cdromDevice, } if err := driver.Prlctl(command...); err != nil { ui.Error(fmt.Sprintf("Error detaching Parallels Tools ISO: %s", err)) } }
c164978
if unnecessary, _ := regexp.MatchString(unnecessaryFile, path); unnecessary { return os.RemoveAll(path) } } if !info.IsDir() { files = append(files, path) } return nil } if err := filepath.Walk(dir, visit); err != nil { return nil, err } return &artifact{ dir: dir, f: files, }, nil...
c164979
fmt.Printf("Pausing %s step '%s'. Press any key to continue.\n", locationString, name) var line string fmt.Scanln(&line) }
c164980
r.exitStatus = status r.Unlock() close(r.exitCh) }
c164981
defer r.Unlock() return r.exitStatus }
c164982
} ip, err := driver.IPAddress(mac) if err != nil { return "", err } return ip, nil }
c164983
end = start + idx } // Count the line number we're on plus the offset in the line line := bytes.Count(data[:start], newline) + 1 pos := int(syntaxErr.Offset) - start - 1 err = fmt.Errorf("Error in line %d, char %d: %s\n%s", line, pos, syntaxErr, data[start:end]) return err } return nil }
c164984
// DeployVirtualMachine uses POST by default which allows 32K of // userdata. If using GET instead the userdata is limited to 2K. maxUD := 32768 if httpGETOnly { maxUD = 2048 } if len(ud) > maxUD { return "", fmt.Errorf( "The supplied user_data contains %d bytes after encoding, "+ "this exceeds the li...
c164985
&md, WeaklyTypedInput: true, DecodeHook: mapstructure.ComposeDecodeHookFunc( uint8ToStringHook, mapstructure.StringToSliceHookFunc(","), mapstructure.StringToTimeDurationHookFunc(), ), }) if err != nil { return err } for _, raw := range raws { if err := decoder.Decode(raw); err != nil { ...
c164986
:= mapstructure.Decode(r, &s); err != nil { return nil, err } } return &interpolate.Context{ BuildName: s.BuildName, BuildType: s.BuildType, TemplatePath: s.TemplatePath, UserVariables: s.Vars, SensitiveVariables: s.SensitiveVars, }, nil }
c164987
err.Errors = append(err.Errors, verr) } } return err default: newErrs := make([]error, len(errs)+1) newErrs[0] = err copy(newErrs[1:], errs) return &MultiError{ Errors: newErrs, } } }
c164988
if _, ok := err.(gophercloud.ErrDefault404); ok { log.Printf("[INFO] 404 on ServerStateRefresh, returning DELETED") return nil, "DELETED", 0, nil } log.Printf("[ERROR] Error on ServerStateRefresh: %s", err) return nil, "", 0, err } return serverNew, serverNew.Status, serverNew.Progress, nil }...
c164989
!= nil { if _, ok := conf.StepState.GetOk(multistep.StateCancelled); ok { return nil, errors.New("interrupted") } } found := false for _, allowed := range conf.Pending { if currentState == allowed { found = true break } } if !found { return nil, fmt.Errorf("unexpected state '%s',...
c164990
c.l.Lock() defer c.l.Unlock() return c.exited }
c164991
nil, err } return &cmdBuilder{client.Builder(), c}, nil }
c164992
nil, err } return &cmdHook{client.Hook(), c}, nil }
c164993
if err != nil { return nil, err } return &cmdPostProcessor{client.PostProcessor(), c}, nil }
c164994
return nil, err } return &cmdProvisioner{client.Provisioner(), c}, nil }
c164995
== "" { err := fmt.Errorf("%s", "No mac address.") return res, err } return res, err }
c164996
== "" { err := fmt.Errorf("%s", "No ip address.") return res, err } return res, err }
c164997
return powershell.GetHostName(ip) }
c164998
== "" { err := fmt.Errorf("%s", "No ip address.") return res, err } return res, err }
c164999
return hyperv.TypeScanCodes(vmName, scanCodes) }