// // createSynthetic will create synthetics row from original row `p` and their // `neighbors`. // func (in *Runtime) createSynthetic(p *tabula.Row, neighbors knn.Neighbors) ( synthetic *tabula.Row, ) { // choose one of the K nearest neighbors randIdx := rand.Intn(neighbors.Len()) n := neighbors.Row(randIdx) // Check if synthetic sample can be created from p and n. canit, slp, sln := in.canCreate(p, n) if !canit { if DEBUG >= 2 { fmt.Println("[lnsmote] can not create synthetic") } if slp.Len() <= 0 { in.outliers.PushBack(p) } // we can not create from p and synthetic. return nil } synthetic = p.Clone() for x, srec := range *synthetic { // Skip class attribute. if x == in.ClassIndex { continue } delta := in.randomGap(p, n, slp.Len(), sln.Len()) pv := (*p)[x].Float() diff := (*n)[x].Float() - pv srec.SetFloat(pv + delta*diff) } return }