pca

package
v1.1.22 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 9, 2023 License: BSD-3-Clause Imports: 5 Imported by: 13

README

pca

Docs: GoDoc

This performs principal component's analysis and associated covariance matrix computations, operating on etable.Table or etensor.Tensor data, using the gonum matrix interface.

There is support for the SVD version, which is much faster and produces the same results, with options for how much information to compute trading off with compute time.

Documentation

Overview

Package pca performs principal component's analysis and associated covariance matrix computations, operating on etable.Table or etensor.Tensor data.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CovarTableCol

func CovarTableCol(cmat etensor.Tensor, ix *etable.IdxView, colNm string, mfun metric.Func64) error

CovarTableCol generates a covariance matrix from given column name in given IdxView of an etable.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 CovarTableColStd added in v1.0.16

func CovarTableColStd(cmat etensor.Tensor, ix *etable.IdxView, colNm string, met metric.StdMetrics) error

CovarTableColStd generates a covariance matrix from given column name in given IdxView of an etable.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

func CovarTensor(cmat etensor.Tensor, tsr etensor.Tensor, mfun metric.Func64) error

CovarTensor generates a covariance matrix from given etensor.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 added in v1.0.16

func CovarTensorStd(cmat etensor.Tensor, tsr etensor.Tensor, met metric.StdMetrics) error

CovarTensorStd generates a covariance matrix from given etensor.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 TableColRowsVec

func TableColRowsVec(vec []float64, ix *etable.IdxView, col etensor.Tensor, cidx int)

TableColRowsVec extracts row-wise vector from given cell index into vec. vec must be of size ix.Len() -- number of rows

func TensorRowsVec

func TensorRowsVec(vec []float64, tsr etensor.Tensor, cidx int)

TensorRowsVec extracts row-wise vector from given cell index into vec. vec must be of size tsr.Dim(0) -- number of rows

Types

type PCA

type PCA struct {
	Covar   *etensor.Float64 `view:"no-inline" desc:"the covariance matrix computed on original data, which is then eigen-factored"`
	Vectors *etensor.Float64 `` /* 217-byte string literal not displayed */
	Values  []float64        `view:"no-inline" desc:"the eigenvalues, ordered *lowest* to *highest*"`
}

PCA computes the eigenvalue decomposition of a square similarity matrix, typically generated using the correlation metric.

func (*PCA) Init

func (pca *PCA) Init()

func (*PCA) PCA

func (pca *PCA) PCA() error

PCA performs the eigen decomposition of the existing Covar matrix. Vectors and Values fields contain the results.

func (*PCA) ProjectCol

func (pca *PCA) ProjectCol(vals *[]float64, ix *etable.IdxView, colNm string, idx int) error

ProjectCol projects values from the given colNm of given table (via IdxView) onto the idx'th eigenvector (0 = largest eigenvalue, 1 = next, etc). Must have already called PCA() method.

func (*PCA) ProjectColToTable

func (pca *PCA) ProjectColToTable(prjns *etable.Table, ix *etable.IdxView, colNm, labNm string, idxs []int) error

ProjectColToTable projects values from the given colNm of given table (via IdxView) 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) TableCol

func (pca *PCA) TableCol(ix *etable.IdxView, colNm string, mfun metric.Func64) error

TableCol 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) TableColStd added in v1.0.16

func (pca *PCA) TableColStd(ix *etable.IdxView, colNm string, met metric.StdMetrics) error

TableColStd 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

func (pca *PCA) Tensor(tsr etensor.Tensor, mfun metric.Func64) error

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 added in v1.0.16

func (pca *PCA) TensorStd(tsr etensor.Tensor, met metric.StdMetrics) error

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 added in v1.1.7

type SVD struct {
	Kind    mat.SVDKind      `` /* 190-byte string literal not displayed */
	Cond    float64          `def:"0.01" desc:"condition value -- minimum normalized eigenvalue to return in values"`
	Rank    int              `desc:"the rank (count) of singular values greater than Cond"`
	Covar   *etensor.Float64 `view:"no-inline" desc:"the covariance matrix computed on original data, which is then eigen-factored"`
	Vectors *etensor.Float64 `` /* 217-byte string literal not displayed */
	Values  []float64        `view:"no-inline" desc:"the eigenvalues, ordered *lowest* to *highest*"`
}

SVD computes the eigenvalue decomposition of a square similarity matrix, typically generated using the correlation metric.

func (*SVD) Init added in v1.1.7

func (svd *SVD) Init()

func (*SVD) ProjectCol added in v1.1.7

func (svd *SVD) ProjectCol(vals *[]float64, ix *etable.IdxView, colNm string, idx int) error

ProjectCol projects values from the given colNm of given table (via IdxView) onto the idx'th eigenvector (0 = largest eigenvalue, 1 = next, etc). Must have already called SVD() method.

func (*SVD) ProjectColToTable added in v1.1.7

func (svd *SVD) ProjectColToTable(prjns *etable.Table, ix *etable.IdxView, colNm, labNm string, idxs []int) error

ProjectColToTable projects values from the given colNm of given table (via IdxView) 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 added in v1.1.7

func (svd *SVD) SVD() error

SVD performs the eigen decomposition of the existing Covar matrix. Vectors and Values fields contain the results.

func (*SVD) TableCol added in v1.1.7

func (svd *SVD) TableCol(ix *etable.IdxView, colNm string, mfun metric.Func64) error

TableCol 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) TableColStd added in v1.1.7

func (svd *SVD) TableColStd(ix *etable.IdxView, colNm string, met metric.StdMetrics) error

TableColStd 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 added in v1.1.7

func (svd *SVD) Tensor(tsr etensor.Tensor, mfun metric.Func64) error

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 added in v1.1.7

func (svd *SVD) TensorStd(tsr etensor.Tensor, met metric.StdMetrics) error

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL