latest version v1.9 - last update 10 Apr 2010 |
Functor for computing a principal component analysis. More...
#include <ltiPCA.h>
Classes | |
class | parameters |
the parameters for the class principalComponents More... | |
Public Member Functions | |
principalComponents (const bool createDefaultParams=true) | |
principalComponents (const parameters &par) | |
principalComponents (const principalComponents &other) | |
virtual | ~principalComponents () |
virtual const char * | getTypeName () 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) |
principalComponents & | copy (const principalComponents &other) |
principalComponents & | operator= (const principalComponents &other) |
virtual functor * | clone () 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 | |
int | checkDim () |
void | reset () |
Protected Attributes | |
int | usedDimensionality |
Functor for computing a principal component analysis.
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 (see also lti::eigenSystem<T>).
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 and set parameters::svd to singularValueDecomp<T> or one of its subclasses (eg. fastSVD<T> if you are using LAPACK)
lti::principalComponents< T >::principalComponents | ( | const bool | createDefaultParams = true |
) |
default constructor
createDefaultParams | if true (default) a default parameters object will be created. |
lti::principalComponents< T >::principalComponents | ( | const parameters & | par | ) |
default constructor with parameters
lti::principalComponents< T >::principalComponents | ( | const principalComponents< T > & | other | ) |
copy constructor
other | the object to be copied |
virtual lti::principalComponents< T >::~principalComponents | ( | ) | [virtual] |
destructor
virtual bool lti::principalComponents< 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)
virtual bool lti::principalComponents< T >::apply | ( | matrix< T > & | srcdest | ) | [virtual] |
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 lti::principalComponents< 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.
This method uses the eigenvector functor given in the parameters. By default, it uses ltilib's own jacobi functor. However, you can speed it up considerably by using the eigensystem functor in the lamath directory.
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 lti::principalComponents< 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
Reimplemented in lti::regularizedPCA< T >.
virtual functor* lti::principalComponents< T >::clone | ( | ) | const [virtual] |
returns a pointer to a clone of this functor.
Implements lti::functor.
Reimplemented in lti::regularizedPCA< T >.
virtual bool lti::principalComponents< T >::computeTransformMatrix | ( | const matrix< T > & | src | ) | [virtual] |
principalComponents& lti::principalComponents< T >::copy | ( | const principalComponents< T > & | other | ) |
copy data of "other" functor.
other | the functor to be copied |
Reimplemented from lti::functor.
virtual const vector<T>& lti::principalComponents< T >::getEigenValues | ( | ) | const [virtual] |
Returns the previously computed eigenvalues of the covariance matrix.
virtual bool lti::principalComponents< T >::getEigenValues | ( | vector< T > & | result | ) | const [virtual] |
virtual const matrix<T>& lti::principalComponents< T >::getEigenVectors | ( | ) | const [virtual] |
Returns the previously computed eigenvectors of the covariance matrix.
virtual bool lti::principalComponents< T >::getEigenVectors | ( | matrix< T > & | result | ) | const [virtual] |
virtual bool lti::principalComponents< 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. |
virtual const vector<T>& lti::principalComponents< T >::getOffsetVector | ( | ) | const [virtual] |
virtual bool lti::principalComponents< T >::getOffsetVector | ( | vector< T > & | result | ) | const [virtual] |
const parameters& lti::principalComponents< T >::getParameters | ( | ) | const |
virtual const matrix<T>& lti::principalComponents< T >::getTransformMatrix | ( | ) | const [virtual] |
virtual bool lti::principalComponents< T >::getTransformMatrix | ( | matrix< T > & | result | ) | const [virtual] |
virtual const char* lti::principalComponents< T >::getTypeName | ( | ) | const [virtual] |
returns the name of this type ("principalComponents")
Reimplemented from lti::linearAlgebraFunctor.
int lti::principalComponents< T >::getUsedDimension | ( | ) | const [inline] |
Number of dimensions considered in the transformation.
principalComponents& lti::principalComponents< T >::operator= | ( | const principalComponents< T > & | other | ) |
Alias for copy.
Reimplemented from lti::functor.
virtual bool lti::principalComponents< T >::read | ( | ioHandler & | handler, | |
const bool | complete = true | |||
) | [virtual] |
Reads this functor from the given handler.
Reimplemented from lti::functor.
virtual bool lti::principalComponents< 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 lti::principalComponents< 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 lti::principalComponents< T >::reset | ( | ) | [protected] |
bool lti::principalComponents< 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 lti::principalComponents< T >::setDimension | ( | int | k | ) | [virtual] |
virtual bool lti::principalComponents< T >::train | ( | const matrix< T > & | src | ) | [virtual] |
Alias for computeTransformMatrix().
virtual bool lti::principalComponents< T >::transform | ( | matrix< T > & | srcdest | ) | const [virtual] |
virtual bool lti::principalComponents< T >::transform | ( | const matrix< T > & | src, | |
matrix< T > & | result | |||
) | const [virtual] |
virtual bool lti::principalComponents< 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 lti::principalComponents< float >::apply().
virtual bool lti::principalComponents< T >::updateParameters | ( | ) | [virtual] |
Update functor's parameters.
This member initializes some internal data according to the values in the parameters.
Reimplemented from lti::functor.
virtual bool lti::principalComponents< T >::write | ( | ioHandler & | handler, | |
const bool | complete = true | |||
) | const [virtual] |
Writes this functor to the given handler.
Reimplemented from lti::functor.
int lti::principalComponents< T >::usedDimensionality [protected] |
dimensionality being used.
Referenced by lti::principalComponents< float >::getUsedDimension().