MCPcopy Create free account
hub / github.com/cogentcore/core / ProjectColToTable

Method ProjectColToTable

tensor/stats/pca/svd.go:207–242  ·  view source on GitHub ↗

ProjectColToTable projects values from the given column of given table (via IndexView) onto the given set of eigenvectors (idxs, 0 = largest eigenvalue, 1 = next, etc), and stores results along with labels from column labNm into results table. Must have already called SVD() method.

(projections *table.Table, ix *table.IndexView, column, labNm string, idxs []int)

Source from the content-addressed store, hash-verified

205// and stores results along with labels from column labNm into results table.
206// Must have already called SVD() method.
207func (svd *SVD) ProjectColToTable(projections *table.Table, ix *table.IndexView, column, labNm string, idxs []int) error {
208 _, err := ix.Table.ColumnByNameTry(column)
209 if err != nil {
210 return err
211 }
212 if svd.Vectors == nil {
213 return fmt.Errorf("SVD.ProjectCol Vectors are nil -- must call SVD first")
214 }
215 rows := ix.Len()
216 projections.DeleteAll()
217 pcolSt := 0
218 if labNm != "" {
219 projections.AddStringColumn(labNm)
220 pcolSt = 1
221 }
222 for _, idx := range idxs {
223 projections.AddFloat64Column(fmt.Sprintf("Projection%v", idx))
224 }
225 projections.SetNumRows(rows)
226
227 for ii, idx := range idxs {
228 pcol := projections.Columns[pcolSt+ii].(*tensor.Float64)
229 svd.ProjectCol(&pcol.Values, ix, column, idx)
230 }
231
232 if labNm != "" {
233 lcol, err := ix.Table.ColumnByNameTry(labNm)
234 if err == nil {
235 plcol := projections.Columns[0]
236 for row := 0; row < rows; row++ {
237 plcol.SetString1D(row, lcol.String1D(row))
238 }
239 }
240 }
241 return nil
242}

Callers 1

TestSVDIrisFunction · 0.95

Calls 10

ProjectColMethod · 0.95
ColumnByNameTryMethod · 0.80
AddStringColumnMethod · 0.80
AddFloat64ColumnMethod · 0.80
ErrorfMethod · 0.65
LenMethod · 0.65
SetNumRowsMethod · 0.65
SetString1DMethod · 0.65
String1DMethod · 0.65
DeleteAllMethod · 0.45

Tested by 1

TestSVDIrisFunction · 0.76