More logs.
authorTom Clegg <tom@tomclegg.ca>
Fri, 18 Sep 2020 13:47:21 +0000 (09:47 -0400)
committerTom Clegg <tom@tomclegg.ca>
Fri, 18 Sep 2020 13:47:21 +0000 (09:47 -0400)
Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom@tomclegg.ca>

exportnumpy.go
pca.go

index fd198116b1512c01f6fb51db67bc82354edd40d5..2d9434e6f280a94b399bee54348145bc4bc0320a 100644 (file)
@@ -157,16 +157,25 @@ func recodeOnehot(in []uint16, incols int) ([]uint16, int) {
        }
        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
diff --git a/pca.go b/pca.go
index b23838d771060d9f0eb4168ba8380b2f1ff16f2a..f668e01557786e5d0829a14be5cb48d789bd44bb 100644 (file)
--- a/pca.go
+++ b/pca.go
@@ -155,20 +155,27 @@ func (cmd *goPCA) RunCommand(prog string, args []string, stdin io.Reader, stdout
                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)
                }
        }