last update 20 Sep 2009 |
#include <cvrPCA.h>
Classes | |
class | parameters |
The parameters for the class pca. More... | |
Public Member Functions | |
pca () | |
pca (const parameters &par) | |
pca (const pca &other) | |
virtual | ~pca () |
virtual const std::string & | name () const |
virtual bool | apply (const matrix< T > &data, matrix< T > &result) |
virtual bool | apply (matrix< T > &srcdest) |
virtual bool | apply (const vector< T > &src, vector< T > &result) |
bool | setCovarianceAndMean (const matrix< T > &coVar, const vector< T > &meanVec) |
virtual bool | transform (const vector< T > &src, vector< T > &result) const |
virtual bool | transform (const matrix< T > &src, matrix< T > &result) const |
virtual bool | transform (matrix< T > &srcdest) const |
virtual bool | computeTransformMatrix (const matrix< T > &src) |
virtual bool | train (const matrix< T > &src) |
virtual bool | reconstruct (const vector< T > &coeff, vector< T > &dest) const |
virtual bool | reconstruct (const matrix< T > &coeff, matrix< T > &dest) const |
virtual bool | getTransformMatrix (matrix< T > &result) const |
virtual const matrix< T > & | getTransformMatrix () const |
virtual bool | getOffsetVector (vector< T > &result) const |
virtual const vector< T > & | getOffsetVector () const |
virtual bool | getEigenValues (vector< T > &result) const |
virtual const vector< T > & | getEigenValues () const |
virtual bool | getEigenVectors (matrix< T > &result) const |
virtual bool | getEigenVectorsInRows (matrix< T > &result) const |
virtual const matrix< T > & | getEigenVectors () const |
virtual void | setDimension (int k) |
pca & | copy (const pca &other) |
pca & | operator= (const pca &other) |
virtual functor * | clone () const |
virtual functor * | newInstance () const |
const parameters & | getParameters () const |
virtual bool | updateParameters () |
virtual bool | read (ioHandler &handler, const bool complete=true) |
virtual bool | write (ioHandler &handler, const bool complete=true) const |
int | getUsedDimension () const |
Protected Member Functions | |
pca (const bool createDefaultParams) | |
int | checkDim () |
void | reset () |
Protected Attributes | |
matrix< T > | orderedEigVec_ |
matrix< T > | transformMatrix_ |
vector< T > | eigValues_ |
vector< T > | offset_ |
vector< T > | transformedOffset_ |
vector< T > | scale_ |
vector< T > | whiteScale_ |
int | usedDimensionality_ |
Functor for computing the principal components of a data set.
It receives a set of input vectors in form of a matrix (each row of the matrix corresponds to an input vector), which will be transformed with PCA.
The first time you use the apply()-method, the transformation matrix will be computed. You can use this transformation matrix with other data sets using the transform() methods.
Please note that the eigenvector matrices will contain the eigenvector in the COLUMNS and not in the rows, as could be expected. This avoids the requirement of transposing matrices in the vector transformations.
For large data matrices is is advisable to use singular value decomposition instead of an eigensystem for the PCA. The operation will usually be faster and using less memory. To do so set parameters::useSVD to true.
Default constructor.
createDefaultParams | if true (default) a default parameters object will be created. |
cvr::pca< T >::pca | ( | const parameters & | par | ) |
Default constructor with parameters.
virtual bool cvr::pca< T >::apply | ( | const vector< T > & | src, | |
vector< T > & | result | |||
) | [inline, virtual] |
Transforms a single vector according to a previously computed transformation matrix.
(this is an alias for the transform() method)
References cvr::pca< T >::transform().
On-Place version of the transformation.
If you don't need to transform the input data, and just want to use the input matrix to compute the principal components you can use the method computeTransformMatrix(). If you just need to transform the data, without computing the transformation matrix, you can use the method transform().
srcdest | matrix<T> with the source data, which will also contain the result. |
srcdest
. virtual bool cvr::pca< T >::apply | ( | const matrix< T > & | data, | |
matrix< T > & | result | |||
) | [virtual] |
Computes the principal components of the data matrix and transforms it according to the new coordinate system.
The result is the transformed matrix. Data and result must not be references to the same matrix. Data points are expected to be in the rows of the data matrix.
If you don't need to transform the input data, and just want to use the input matrix to compute the principal components you can use the method computeTransformMatrix(). If you just need to transform the data, without computing the transformation matrix, you can use the method transform().
data | matrix<T> with the source data. | |
result | matrix<T> with the result data. |
int cvr::pca< T >::checkDim | ( | ) | [protected] |
Determines the intrinsic dimensionality of the data set if the user specify autoDim, otherwise return parameters::resultDim.
The member usedDimensionality will be set with the returned value
Returns the previously computed eigenvalues of the covariance matrix.
Returns the previously computed eigenvectors of the covariance matrix.
virtual bool cvr::pca< T >::getEigenVectorsInRows | ( | matrix< T > & | result | ) | const [virtual] |
Returns the previously computed eigenvectors of the covariance matrix.
This method will call the normal getEigenVectors() methods and after that will transpose the obtained matrix, i.e. it is faster to get the eigenvectors in the columns.
result | the matrix which will receive the eigenvectors. Each row of the matrix contains one eigenvector. |
const parameters& cvr::pca< T >::getParameters | ( | ) | const |
int cvr::pca< T >::getUsedDimension | ( | ) | const [inline] |
Number of dimensions considered in the transformation.
References cvr::pca< T >::usedDimensionality_.
virtual const std::string& cvr::pca< T >::name | ( | ) | const [virtual] |
virtual bool cvr::pca< T >::reconstruct | ( | const matrix< T > & | coeff, | |
matrix< T > & | dest | |||
) | const [virtual] |
Reconstructs a set of data vectors dest
from the given coefficients coeff
, using the transformMatrix found by computeTransformMatrix() or apply() and the appropriate offset.
As usual coeff
as well as dest
contain one data vector per row.
coeff | each row contains PCA coefficients for reconstruction. | |
dest | each row is one reconstructed data vector. |
virtual bool cvr::pca< T >::reconstruct | ( | const vector< T > & | coeff, | |
vector< T > & | dest | |||
) | const [virtual] |
Reconstructs a data vector dest
from the given coefficients coeff
, using the transformMatrix found by computeTransformMatrix() or apply() and the appropriate offset.
coeff | PCA coefficients for reconstruction. | |
dest | reconstructed data vector. |
void cvr::pca< T >::reset | ( | ) | [protected] |
Resets all private members to size 0.
Used when an error occurs in the calculation of the transform matrix.
bool cvr::pca< T >::setCovarianceAndMean | ( | const matrix< T > & | coVar, | |
const vector< T > & | meanVec | |||
) |
Pass the covariance matrix and the mean values directly to the functor to generate the transform matrix.
If you know the mean and covariance of your data, you can use this method to speed up the computations of the transformation matrix. Otherwise, just call one of the apply() methods with your data vectors in the rows of the matrix. The covariance and mean vectors will be computed there automatically.
virtual void cvr::pca< T >::setDimension | ( | int | k | ) | [virtual] |
Alias for computeTransformMatrix().
virtual bool cvr::pca< T >::transform | ( | const vector< T > & | src, | |
vector< T > & | result | |||
) | const [virtual] |
Transforms a single vector according to a previously computed transformation matrix.
result
Referenced by cvr::pca< T >::apply().
virtual bool cvr::pca< T >::updateParameters | ( | ) | [virtual] |
Update functor's parameters.
This member initializes some internal data according to the values in the parameters.
Reimplemented from cvr::parametersManager.
vector<T> cvr::pca< T >::eigValues_ [protected] |
Eigenvalues.
matrix<T> cvr::pca< T >::orderedEigVec_ [protected] |
Ordered eigen vectors.
vector<T> cvr::pca< T >::transformedOffset_ [protected] |
Transformed offset.
matrix<T> cvr::pca< T >::transformMatrix_ [protected] |
Transformation matrix.
int cvr::pca< T >::usedDimensionality_ [protected] |
vector<T> cvr::pca< T >::whiteScale_ [protected] |
Whitening scale.