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)
| 193 | // and stores results along with labels from column labNm into results table. |
| 194 | // Must have already called PCA() method. |
| 195 | func (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 | } |