Documentation
¶
Overview ¶
Package pca performs principal component's analysis and associated covariance matrix computations, operating on table.Table or tensor.Tensor data.
Index ¶
- func CovarTableColumn(cmat tensor.Tensor, ix *table.IndexView, column string, mfun metric.Func64) error
- func CovarTableColumnStd(cmat tensor.Tensor, ix *table.IndexView, column string, met metric.StdMetrics) error
- func CovarTensor(cmat tensor.Tensor, tsr tensor.Tensor, mfun metric.Func64) error
- func CovarTensorStd(cmat tensor.Tensor, tsr tensor.Tensor, met metric.StdMetrics) error
- func TableColumnRowsVec(vec []float64, ix *table.IndexView, col tensor.Tensor, cidx int)
- func TensorRowsVec(vec []float64, tsr tensor.Tensor, cidx int)
- type PCA
- func (pa *PCA) Init()
- func (pa *PCA) PCA() error
- func (pa *PCA) ProjectColumn(vals *[]float64, ix *table.IndexView, column string, idx int) error
- func (pa *PCA) ProjectColumnToTable(projections *table.Table, ix *table.IndexView, column, labNm string, ...) error
- func (pa *PCA) TableColumn(ix *table.IndexView, column string, mfun metric.Func64) error
- func (pa *PCA) TableColumnStd(ix *table.IndexView, column string, met metric.StdMetrics) error
- func (pa *PCA) Tensor(tsr tensor.Tensor, mfun metric.Func64) error
- func (pa *PCA) TensorStd(tsr tensor.Tensor, met metric.StdMetrics) error
- type SVD
- func (svd *SVD) Init()
- func (svd *SVD) ProjectColumn(vals *[]float64, ix *table.IndexView, column string, idx int) error
- func (svd *SVD) ProjectColumnToTable(projections *table.Table, ix *table.IndexView, column, labNm string, ...) error
- func (svd *SVD) SVD() error
- func (svd *SVD) TableColumn(ix *table.IndexView, column string, mfun metric.Func64) error
- func (svd *SVD) TableColumnStd(ix *table.IndexView, column string, met metric.StdMetrics) error
- func (svd *SVD) Tensor(tsr tensor.Tensor, mfun metric.Func64) error
- func (svd *SVD) TensorStd(tsr tensor.Tensor, met metric.StdMetrics) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CovarTableColumn ¶ added in v0.3.3
func CovarTableColumn(cmat tensor.Tensor, ix *table.IndexView, column string, mfun metric.Func64) error
CovarTableColumn generates a covariance matrix from given column name in given IndexView of an table.Table, and given metric function (typically Covariance or Correlation -- use Covar if vars have similar overall scaling, which is typical in neural network models, and use Correl if they are on very different scales -- Correl effectively rescales). A Covariance matrix computes the *row-wise* vector similarities for each pairwise combination of column cells -- i.e., the extent to which each cell co-varies in its value with each other cell across the rows of the table. This is the input to the PCA eigenvalue decomposition of the resulting covariance matrix.
func CovarTableColumnStd ¶ added in v0.3.3
func CovarTableColumnStd(cmat tensor.Tensor, ix *table.IndexView, column string, met metric.StdMetrics) error
CovarTableColumnStd generates a covariance matrix from given column name in given IndexView of an table.Table, and given metric function (typically Covariance or Correlation -- use Covar if vars have similar overall scaling, which is typical in neural network models, and use Correl if they are on very different scales -- Correl effectively rescales). A Covariance matrix computes the *row-wise* vector similarities for each pairwise combination of column cells -- i.e., the extent to which each cell co-varies in its value with each other cell across the rows of the table. This is the input to the PCA eigenvalue decomposition of the resulting covariance matrix. This Std version is usable e.g., in Python where the func cannot be passed.
func CovarTensor ¶
CovarTensor generates a covariance matrix from given tensor.Tensor, where the outer-most dimension is rows, and all other dimensions within that are covaried against each other, using given metric function (typically Covariance or Correlation -- use Covar if vars have similar overall scaling, which is typical in neural network models, and use Correl if they are on very different scales -- Correl effectively rescales). A Covariance matrix computes the *row-wise* vector similarities for each pairwise combination of column cells -- i.e., the extent to which each cell co-varies in its value with each other cell across the rows of the table. This is the input to the PCA eigenvalue decomposition of the resulting covariance matrix.
func CovarTensorStd ¶
CovarTensorStd generates a covariance matrix from given tensor.Tensor, where the outer-most dimension is rows, and all other dimensions within that are covaried against each other, using given metric function (typically Covariance or Correlation -- use Covar if vars have similar overall scaling, which is typical in neural network models, and use Correl if they are on very different scales -- Correl effectively rescales). A Covariance matrix computes the *row-wise* vector similarities for each pairwise combination of column cells -- i.e., the extent to which each cell co-varies in its value with each other cell across the rows of the table. This is the input to the PCA eigenvalue decomposition of the resulting covariance matrix. This Std version is usable e.g., in Python where the func cannot be passed.
func TableColumnRowsVec ¶ added in v0.3.3
TableColumnRowsVec extracts row-wise vector from given cell index into vec. vec must be of size ix.Len() -- number of rows
Types ¶
type PCA ¶
type PCA struct { // the covariance matrix computed on original data, which is then eigen-factored Covar tensor.Tensor `display:"no-inline"` // the eigenvectors, in same size as Covar - each eigenvector is a column in this 2D square matrix, ordered *lowest* to *highest* across the columns -- i.e., maximum eigenvector is the last column Vectors tensor.Tensor `display:"no-inline"` // the eigenvalues, ordered *lowest* to *highest* Values []float64 `display:"no-inline"` }
PCA computes the eigenvalue decomposition of a square similarity matrix, typically generated using the correlation metric.
func (*PCA) PCA ¶
PCA performs the eigen decomposition of the existing Covar matrix. Vectors and Values fields contain the results.
func (*PCA) ProjectColumn ¶ added in v0.3.3
ProjectColumn projects values from the given column of given table (via IndexView) onto the idx'th eigenvector (0 = largest eigenvalue, 1 = next, etc). Must have already called PCA() method.
func (*PCA) ProjectColumnToTable ¶ added in v0.3.3
func (pa *PCA) ProjectColumnToTable(projections *table.Table, ix *table.IndexView, column, labNm string, idxs []int) error
ProjectColumnToTable 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.
func (*PCA) TableColumn ¶ added in v0.3.3
TableColumn is a convenience method that computes a covariance matrix on given column of table and then performs the PCA on the resulting matrix. If no error occurs, the results can be read out from Vectors and Values or used in Projection methods. mfun is metric function, typically Covariance or Correlation -- use Covar if vars have similar overall scaling, which is typical in neural network models, and use Correl if they are on very different scales -- Correl effectively rescales). A Covariance matrix computes the *row-wise* vector similarities for each pairwise combination of column cells -- i.e., the extent to which each cell co-varies in its value with each other cell across the rows of the table. This is the input to the PCA eigenvalue decomposition of the resulting covariance matrix, which extracts the eigenvectors as directions with maximal variance in this matrix.
func (*PCA) TableColumnStd ¶ added in v0.3.3
TableColumnStd is a convenience method that computes a covariance matrix on given column of table and then performs the PCA on the resulting matrix. If no error occurs, the results can be read out from Vectors and Values or used in Projection methods. mfun is a Std metric function, typically Covariance or Correlation -- use Covar if vars have similar overall scaling, which is typical in neural network models, and use Correl if they are on very different scales -- Correl effectively rescales). A Covariance matrix computes the *row-wise* vector similarities for each pairwise combination of column cells -- i.e., the extent to which each cell co-varies in its value with each other cell across the rows of the table. This is the input to the PCA eigenvalue decomposition of the resulting covariance matrix, which extracts the eigenvectors as directions with maximal variance in this matrix. This Std version is usable e.g., in Python where the func cannot be passed.
func (*PCA) Tensor ¶
Tensor is a convenience method that computes a covariance matrix on given tensor and then performs the PCA on the resulting matrix. If no error occurs, the results can be read out from Vectors and Values or used in Projection methods. mfun is metric function, typically Covariance or Correlation -- use Covar if vars have similar overall scaling, which is typical in neural network models, and use Correl if they are on very different scales -- Correl effectively rescales). A Covariance matrix computes the *row-wise* vector similarities for each pairwise combination of column cells -- i.e., the extent to which each cell co-varies in its value with each other cell across the rows of the table. This is the input to the PCA eigenvalue decomposition of the resulting covariance matrix, which extracts the eigenvectors as directions with maximal variance in this matrix.
func (*PCA) TensorStd ¶
TensorStd is a convenience method that computes a covariance matrix on given tensor and then performs the PCA on the resulting matrix. If no error occurs, the results can be read out from Vectors and Values or used in Projection methods. mfun is Std metric function, typically Covariance or Correlation -- use Covar if vars have similar overall scaling, which is typical in neural network models, and use Correl if they are on very different scales -- Correl effectively rescales). A Covariance matrix computes the *row-wise* vector similarities for each pairwise combination of column cells -- i.e., the extent to which each cell co-varies in its value with each other cell across the rows of the table. This is the input to the PCA eigenvalue decomposition of the resulting covariance matrix, which extracts the eigenvectors as directions with maximal variance in this matrix. This Std version is usable e.g., in Python where the func cannot be passed.
type SVD ¶
type SVD struct { // type of SVD to run: SVDNone is the most efficient if you only need the values which are always computed. Otherwise, SVDThin is the next most efficient for getting approximate vectors Kind mat.SVDKind // condition value -- minimum normalized eigenvalue to return in values Cond float64 `default:"0.01"` // the rank (count) of singular values greater than Cond Rank int // the covariance matrix computed on original data, which is then eigen-factored Covar tensor.Tensor `display:"no-inline"` // the eigenvectors, in same size as Covar - each eigenvector is a column in this 2D square matrix, ordered *lowest* to *highest* across the columns -- i.e., maximum eigenvector is the last column Vectors tensor.Tensor `display:"no-inline"` // the eigenvalues, ordered *lowest* to *highest* Values []float64 `display:"no-inline"` }
SVD computes the eigenvalue decomposition of a square similarity matrix, typically generated using the correlation metric.
func (*SVD) ProjectColumn ¶ added in v0.3.3
ProjectColumn projects values from the given column of given table (via IndexView) onto the idx'th eigenvector (0 = largest eigenvalue, 1 = next, etc). Must have already called SVD() method.
func (*SVD) ProjectColumnToTable ¶ added in v0.3.3
func (svd *SVD) ProjectColumnToTable(projections *table.Table, ix *table.IndexView, column, labNm string, idxs []int) error
ProjectColumnToTable 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.
func (*SVD) SVD ¶
SVD performs the eigen decomposition of the existing Covar matrix. Vectors and Values fields contain the results.
func (*SVD) TableColumn ¶ added in v0.3.3
TableColumn is a convenience method that computes a covariance matrix on given column of table and then performs the SVD on the resulting matrix. If no error occurs, the results can be read out from Vectors and Values or used in Projection methods. mfun is metric function, typically Covariance or Correlation -- use Covar if vars have similar overall scaling, which is typical in neural network models, and use Correl if they are on very different scales -- Correl effectively rescales). A Covariance matrix computes the *row-wise* vector similarities for each pairwise combination of column cells -- i.e., the extent to which each cell co-varies in its value with each other cell across the rows of the table. This is the input to the SVD eigenvalue decomposition of the resulting covariance matrix, which extracts the eigenvectors as directions with maximal variance in this matrix.
func (*SVD) TableColumnStd ¶ added in v0.3.3
TableColumnStd is a convenience method that computes a covariance matrix on given column of table and then performs the SVD on the resulting matrix. If no error occurs, the results can be read out from Vectors and Values or used in Projection methods. mfun is a Std metric function, typically Covariance or Correlation -- use Covar if vars have similar overall scaling, which is typical in neural network models, and use Correl if they are on very different scales -- Correl effectively rescales). A Covariance matrix computes the *row-wise* vector similarities for each pairwise combination of column cells -- i.e., the extent to which each cell co-varies in its value with each other cell across the rows of the table. This is the input to the SVD eigenvalue decomposition of the resulting covariance matrix, which extracts the eigenvectors as directions with maximal variance in this matrix. This Std version is usable e.g., in Python where the func cannot be passed.
func (*SVD) Tensor ¶
Tensor is a convenience method that computes a covariance matrix on given tensor and then performs the SVD on the resulting matrix. If no error occurs, the results can be read out from Vectors and Values or used in Projection methods. mfun is metric function, typically Covariance or Correlation -- use Covar if vars have similar overall scaling, which is typical in neural network models, and use Correl if they are on very different scales -- Correl effectively rescales). A Covariance matrix computes the *row-wise* vector similarities for each pairwise combination of column cells -- i.e., the extent to which each cell co-varies in its value with each other cell across the rows of the table. This is the input to the SVD eigenvalue decomposition of the resulting covariance matrix, which extracts the eigenvectors as directions with maximal variance in this matrix.
func (*SVD) TensorStd ¶
TensorStd is a convenience method that computes a covariance matrix on given tensor and then performs the SVD on the resulting matrix. If no error occurs, the results can be read out from Vectors and Values or used in Projection methods. mfun is Std metric function, typically Covariance or Correlation -- use Covar if vars have similar overall scaling, which is typical in neural network models, and use Correl if they are on very different scales -- Correl effectively rescales). A Covariance matrix computes the *row-wise* vector similarities for each pairwise combination of column cells -- i.e., the extent to which each cell co-varies in its value with each other cell across the rows of the table. This is the input to the SVD eigenvalue decomposition of the resulting covariance matrix, which extracts the eigenvectors as directions with maximal variance in this matrix. This Std version is usable e.g., in Python where the func cannot be passed.