LTI-Lib latest version v1.9 - last update 24 Nov 2005
Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

lti::principalComponents< T > Class Template Reference
[Linear Algebra]

Functor for computing a principal component analysis. More...

#include <ltiPCA.h>

Inheritance diagram for lti::principalComponents< T >:

Inheritance graph
[legend]
Collaboration diagram for lti::principalComponents< T >:

Collaboration graph
[legend]
List of all members.

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)
principalComponentscopy (const principalComponents &other)
principalComponentsoperator= (const principalComponents &other)
virtual functorclone () const
const parametersgetParameters () 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

Classes

class  parameters
 the parameters for the class principalComponents More...

Detailed Description

template<class T>
class lti::principalComponents< T >

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)


Constructor & Destructor Documentation

template<class T>
lti::principalComponents< T >::principalComponents const bool  createDefaultParams = true  ) 
 

default constructor

Parameters:
createDefaultParams if true (default) a default parameters object will be created.

template<class T>
lti::principalComponents< T >::principalComponents const parameters par  ) 
 

default constructor with parameters

template<class T>
lti::principalComponents< T >::principalComponents const principalComponents< T > &  other  ) 
 

copy constructor

Parameters:
other the object to be copied

template<class T>
virtual lti::principalComponents< T >::~principalComponents  )  [virtual]
 

destructor


Member Function Documentation

template<class T>
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)

template<class T>
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().

Parameters:
srcdest matrix<T> with the source data, which will also contain the result.
Returns:
a reference to srcdest.

template<class T>
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().

Parameters:
data matrix<T> with the source data.
result matrix<T> with the result data.
Returns:
true if the PCA could be computed, false otherwise

template<class T>
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 >.

template<class 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 >.

template<class T>
virtual bool lti::principalComponents< T >::computeTransformMatrix const matrix< T > &  src  )  [virtual]
 

Compute the transformation matrix.

Similar to the apply() method, but it does not transform the given data (this saves some time).

Parameters:
src the matrix with the input data to be analysed.
Returns:
true if transformation matrix could be computed, false otherwise

template<class T>
principalComponents& lti::principalComponents< T >::copy const principalComponents< T > &  other  ) 
 

copy data of "other" functor.

Parameters:
other the functor to be copied
Returns:
a reference to this functor object

template<class T>
virtual const vector<T>& lti::principalComponents< T >::getEigenValues  )  const [virtual]
 

Returns the previously computed eigenvalues of the covariance matrix.

Returns:
a const reference to the last computed eigenvalues

template<class T>
virtual bool lti::principalComponents< T >::getEigenValues vector< T > &  result  )  const [virtual]
 

Returns the previously computed eigenvalues of the covariance matrix.

Parameters:
result the vector which will receive the eigenvalues.
Returns:
true if the values could be obtained, false otherwise.

template<class T>
virtual const matrix<T>& lti::principalComponents< T >::getEigenVectors  )  const [virtual]
 

Returns the previously computed eigenvectors of the covariance matrix.

Returns:
a const reference to the last computed eigenvectors

template<class T>
virtual bool lti::principalComponents< T >::getEigenVectors matrix< T > &  result  )  const [virtual]
 

Returns the previously computed eigenvectors of the covariance matrix.

Parameters:
result the matrix which will receive the eigenvectors. Each column of the matrix contains one eigenvector.
Returns:
true if the vectors could be obtained, false otherwise

template<class T>
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.

Parameters:
result the matrix which will receive the eigenvectors. Each row of the matrix contains one eigenvector.
Returns:
true if the vectors could be obtained, false otherwise

template<class T>
virtual const vector<T>& lti::principalComponents< T >::getOffsetVector  )  const [virtual]
 

Returns the previously computed offset vector, which corresponds to the mean of the data.

Returns:
a const reference to the last computed or used offset vector.

template<class T>
virtual bool lti::principalComponents< T >::getOffsetVector vector< T > &  result  )  const [virtual]
 

Returns the previously computed offset vector, which corresponds to the mean of the data.

Parameters:
result the offset vector will be written here.
Returns:
true if the matrix could be computed, false otherwise.

template<class T>
const parameters& lti::principalComponents< T >::getParameters  )  const
 

returns used parameters

Reimplemented from lti::functor.

Reimplemented in lti::regularizedPCA< T >.

template<class T>
virtual const matrix<T>& lti::principalComponents< T >::getTransformMatrix  )  const [virtual]
 

Returns the previously computed transform matrix.

Returns:
a const reference to the last computed or used transformation matrix.

template<class T>
virtual bool lti::principalComponents< T >::getTransformMatrix matrix< T > &  result  )  const [virtual]
 

Returns the previously computed transform matrix.

Parameters:
result the matrix which will receive the transformation matrix.
Returns:
true if the matrix could be computed, false otherwise.

template<class T>
virtual const char* lti::principalComponents< T >::getTypeName  )  const [virtual]
 

returns the name of this type ("principalComponents")

Reimplemented from lti::linearAlgebraFunctor.

template<class T>
int lti::principalComponents< T >::getUsedDimension  )  const [inline]
 

Number of dimensions considered in the transformation.

Returns:
the number of dimensions used for the transformation. It is always less or equal the number of dimensions of the input vectors.

template<class T>
principalComponents& lti::principalComponents< T >::operator= const principalComponents< T > &  other  ) 
 

Alias for copy.

template<class T>
virtual bool lti::principalComponents< T >::read ioHandler handler,
const bool  complete = true
[virtual]
 

Reads this functor from the given handler.

Reimplemented from lti::functor.

template<class T>
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.

Parameters:
coeff each row contains PCA coefficients for reconstruction.
dest each row is one reconstructed data vector.
Returns:
true if reconstruction was successful

template<class T>
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.

Parameters:
coeff PCA coefficients for reconstruction.
dest reconstructed data vector.
Returns:
true if reconstruction was successful

template<class T>
void lti::principalComponents< T >::reset  )  [protected]
 

Resets all private members to size 0.

Used when an error occurs in the calculation of the transform matrix.

template<class T>
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.

template<class T>
virtual void lti::principalComponents< T >::setDimension int  k  )  [virtual]
 

Set the dimension to which the vectors should be reduced.

This is just considered when computing the transformation matrix. After this matrix is determined the (destination) dimension is fixed and just can be changed by recalculating the transformation matrix.

template<class T>
virtual bool lti::principalComponents< T >::train const matrix< T > &  src  )  [virtual]
 

Alias for computeTransformMatrix().

template<class T>
virtual bool lti::principalComponents< T >::transform matrix< T > &  srcdest  )  const [virtual]
 

Transform an entire matrix according to a previously computed transformation matrix.

Unfortunately, we must choose a name different from apply.

Parameters:
srcdest the data matrix. The result will be left here too.
Returns:
true if successful, false otherwise.

template<class T>
virtual bool lti::principalComponents< T >::transform const matrix< T > &  src,
matrix< T > &  result
const [virtual]
 

Transform an entire matrix according to a previously computed transformation matrix.

Unfortunately, we must choose a name different from apply.

Parameters:
src the data matrix
result the matrix which will receive the transformed data
Returns:
true if successful, false otherwise.

template<class T>
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.

Parameters:
src the data vector
result the vector which will receive the transformed data
Returns:
a reference to result

template<class T>
virtual bool lti::principalComponents< T >::updateParameters  )  [virtual]
 

Update functor's parameters.

This member initializes some internal data according to the values in the parameters.

Returns:
true if successful, false otherwise

Reimplemented from lti::functor.

template<class T>
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.


Member Data Documentation

template<class T>
int lti::principalComponents< T >::usedDimensionality [protected]
 

dimensionality being used.


The documentation for this class was generated from the following file:
Generated on Thu Nov 24 17:04:14 2005 for LTI-Lib by Doxygen 1.4.4