}
outcol := make([]int, incols)
outcols := 0
+ dropped := 0
for incol, v := range maxvalue {
outcol[incol] = outcols
- outcols += int(v)
+ if v == 0 {
+ dropped++
+ } else {
+ outcols += int(v)
+ }
}
+ log.Printf("recodeOnehot: dropped %d input cols with zero maxvalue", dropped)
+
out := make([]uint16, rows*outcols)
- for row := 0; row < rows; row++ {
+ for inidx, row := 0, 0; row < rows; row++ {
+ outrow := out[row*outcols:]
for col := 0; col < incols; col++ {
- if v := in[row*incols+col]; v > 0 {
- out[row*outcols+outcol[col]+int(v)-1] = 1
+ if v := in[inidx]; v > 0 {
+ outrow[outcol[col]+int(v)-1] = 1
}
+ inidx++
}
}
return out, outcols
log.Printf("recode one-hot: %d rows, %d cols", rows, cols)
data, cols = recodeOnehot(data, cols)
}
- log.Printf("running fit+transform: %d rows, %d cols", rows, cols)
- pca, err := nlp.NewPCA(*components).FitTransform(array2matrix(rows, cols, data).T())
+ cgs = nil
+
+ log.Printf("creating matrix backed by array: %d rows, %d cols", rows, cols)
+ mtx := array2matrix(rows, cols, data).T()
+
+ log.Print("fitting")
+ transformer := nlp.NewPCA(*components)
+ transformer.Fit(mtx)
+ log.Printf("transforming")
+ mtx, err = transformer.Transform(mtx)
if err != nil {
return 1
}
+ mtx = mtx.T()
- log.Print("transposing result")
- pca = pca.T()
- rows, cols = pca.Dims()
+ rows, cols = mtx.Dims()
log.Printf("copying result to numpy output array: %d rows, %d cols", rows, cols)
out := make([]float64, rows*cols)
for i := 0; i < rows; i++ {
for j := 0; j < cols; j++ {
- out[i*cols+j] = pca.At(i, j)
+ out[i*cols+j] = mtx.At(i, j)
}
}