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

Method ProjectColToTable

tensor/stats/pca/pca.go:195–230  ·  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 PCA() method.

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

Source from the content-addressed store, hash-verified

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

Callers 1

TestPCAIrisFunction · 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

TestPCAIrisFunction · 0.76