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)
| 205 | // and stores results along with labels from column labNm into results table. |
| 206 | // Must have already called SVD() method. |
| 207 | func (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 | } |