latest version v1.9 - last update 10 Apr 2010 |
Functor for computing a linear discriminant analysis (LDA). More...
#include <ltiLDA.h>
Classes | |
class | parameters |
the parameters for the class linearDiscriminantAnalysis More... | |
Public Member Functions | |
linearDiscriminantAnalysis () | |
linearDiscriminantAnalysis (const linearDiscriminantAnalysis &other) | |
virtual | ~linearDiscriminantAnalysis () |
virtual const char * | getTypeName () const |
bool | apply (matrix< T > &srcdest, const ivector &labels) |
bool | apply (const matrix< T > &src, matrix< T > &dest, const ivector &labels) |
bool | apply (const matrix< T > &src, matrix< T > &dest, const matrix< T > &Sb) |
bool | apply (const matrix< T > &src, matrix< T > &result) |
bool | apply (const vector< T > &src, vector< T > &result) |
bool | apply (matrix< T > &srcdest) |
void | setDimension (int k) |
virtual bool | setParameters (const parameters &theParam) |
bool | getEigenValues (vector< T > &result) const |
const vector< T > & | getEigenValues () const |
bool | getEigenVectors (matrix< T > &result) const |
bool | getEigenVectorsInRows (matrix< T > &result) const |
linearDiscriminantAnalysis & | copy (const linearDiscriminantAnalysis &other) |
virtual functor * | clone () const |
const parameters & | getParameters () const |
bool | computeSb (const matrix< T > &src, matrix< T > &Sb, const ivector &labels) const |
virtual bool | read (ioHandler &handler, const bool complete=true) |
virtual bool | write (ioHandler &handler, const bool complete=true) const |
Protected Member Functions | |
int | checkDim () |
Functor for computing a linear discriminant analysis (LDA).
It uses functors that require the LAPack.
lti::linearDiscriminantAnalysis< T >::linearDiscriminantAnalysis | ( | ) |
default constructor
lti::linearDiscriminantAnalysis< T >::linearDiscriminantAnalysis | ( | const linearDiscriminantAnalysis< T > & | other | ) |
copy constructor
other | the object to be copied |
virtual lti::linearDiscriminantAnalysis< T >::~linearDiscriminantAnalysis | ( | ) | [virtual] |
destructor
bool lti::linearDiscriminantAnalysis< T >::apply | ( | matrix< T > & | srcdest | ) |
On-Place version of the transformation.
srcdest | matrix<T> with the source data, which will also contain the result. |
bool lti::linearDiscriminantAnalysis< T >::apply | ( | const vector< T > & | src, | |
vector< T > & | result | |||
) |
Uses a previously computed transform in order to reduce the given data set's dimensionality according to the resultDim parameter.
src | matrix<T> with the source data. | |
result | matrix<T> with the result data. |
bool lti::linearDiscriminantAnalysis< T >::apply | ( | const matrix< T > & | src, | |
matrix< T > & | result | |||
) |
Uses a previously computed transform in order to reduce the given data set's dimensionality according to the resultDim parameter.
src | matrix<T> with the source data. | |
result | matrix<T> with the result data. |
bool lti::linearDiscriminantAnalysis< T >::apply | ( | const matrix< T > & | src, | |
matrix< T > & | dest, | |||
const matrix< T > & | Sb | |||
) |
Computes a linear discriminant analysis for the data given in src.
This matrix is assumed to contain the data points for one class. The computed transformation is stored internally and can be used just as a global transformation. The main purpose of this method is to be used for LDA classifiers, which compute class-wise LDA transforms and classify by subsequently applying the LDA's of all classes to the vector, and then choosing the class whose mean is closest to the presented vector. This method can be used to compute the required LDAs.
src | matrix<T> with the source data. | |
dest | matrix<T> where the result will be left. | |
Sb | matrix<T> which is the between-class scatter matrix of the entire population. |
bool lti::linearDiscriminantAnalysis< T >::apply | ( | const matrix< T > & | src, | |
matrix< T > & | dest, | |||
const ivector & | labels | |||
) |
Computes the linear discriminant analysis for the data given in src.
It internally stores a transformation matrix which is applied to the data. This matrix can be reused by calling one of the functions without the label vector.
src | matrix<T> with the source data. | |
dest | matrix<T> where the result will be left. | |
labels | ivector for each row of the source matrix, this vector contains the class label. |
bool lti::linearDiscriminantAnalysis< T >::apply | ( | matrix< T > & | srcdest, | |
const ivector & | labels | |||
) |
int lti::linearDiscriminantAnalysis< 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
virtual functor* lti::linearDiscriminantAnalysis< T >::clone | ( | ) | const [virtual] |
returns a pointer to a clone of this functor.
Implements lti::functor.
bool lti::linearDiscriminantAnalysis< T >::computeSb | ( | const matrix< T > & | src, | |
matrix< T > & | Sb, | |||
const ivector & | labels | |||
) | const |
Computes the between-class scatter matrix Sb.
linearDiscriminantAnalysis& lti::linearDiscriminantAnalysis< T >::copy | ( | const linearDiscriminantAnalysis< T > & | other | ) |
copy data of "other" functor.
other | the functor to be copied |
Reimplemented from lti::functor.
const vector<T>& lti::linearDiscriminantAnalysis< T >::getEigenValues | ( | ) | const |
Returns the previously computed eigenvalues of the scatter matrix.
bool lti::linearDiscriminantAnalysis< T >::getEigenValues | ( | vector< T > & | result | ) | const |
bool lti::linearDiscriminantAnalysis< T >::getEigenVectors | ( | matrix< T > & | result | ) | const |
bool lti::linearDiscriminantAnalysis< T >::getEigenVectorsInRows | ( | matrix< T > & | result | ) | const |
Returns the previously computed eigenvectors of the scatter 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& lti::linearDiscriminantAnalysis< T >::getParameters | ( | ) | const |
returns used parameters
Reimplemented from lti::functor.
virtual const char* lti::linearDiscriminantAnalysis< T >::getTypeName | ( | ) | const [virtual] |
returns the name of this type ("linearDiscriminantAnalysis")
Reimplemented from lti::linearAlgebraFunctor.
virtual bool lti::linearDiscriminantAnalysis< T >::read | ( | ioHandler & | handler, | |
const bool | complete = true | |||
) | [virtual] |
Read the functor from the given ioHandler.
The default implementation is to read just the parameters object.
Since this virtual method needs to know the exact type of the parameters to call the proper read method, it will just assume that the current functor instance has a valid parameter set. If this is not the case, you need to reimplement the read method to set first a dummy parameter object.
handler | the ioHandler to be used | |
complete | if true (the default) the enclosing begin/end will be also written, otherwise only the data block will be written. |
Reimplemented from lti::functor.
void lti::linearDiscriminantAnalysis< T >::setDimension | ( | int | k | ) |
Set the dimension to which the vectors should be reduced.
virtual bool lti::linearDiscriminantAnalysis< T >::setParameters | ( | const parameters & | theParam | ) | [virtual] |
set functor's parameters.
This member makes a copy of theParam: the functor will keep its own copy of the parameters! The difference to the standard is that this one passes the useSVD flag on to the matrix inverter.
Reimplemented from lti::functor.
virtual bool lti::linearDiscriminantAnalysis< T >::write | ( | ioHandler & | handler, | |
const bool | complete = true | |||
) | const [virtual] |
return the last message set with setStatusString().
This will never return 0. If no status-string has been set yet an empty string (pointer to a string with only the char(0)) will be returned. set a status string.
msg | the const string to be reported next time by getStatusString(). The given string will be copied. This message will be usually set within the apply methods to indicate an error cause. |
Note that the change of the status string is not considered as a change in the functor status. append a message to the current status string. Take care to reset the status string by calling setStatusString() for each call of an apply() or similar method. appendStatusString() should only be used after setStatusString() has been called.
msg | message to be appended to the current status string. |
Note that the change of the status string is not considered as a change in the functor status. append an integer value to the current status string. Take care to reset the status string by calling setStatusString() for each call of an apply() or similar method. appendStatusString() should only be used after setStatusString() has been called.
msg | integer value to be appended to the current status string. |
Note that the change of the status string is not considered as a change in the functor status. append a double value to the current status string. Take care to reset the status string by calling setStatusString() for each call of an apply() or similar method. appendStatusString() should only be used after setStatusString() has been called.
msg | double value to be appended to the current status string. |
Note that the change of the status string is not considered as a change in the functor status. Append the status string of another functor to this functors status string. To achieve better readability of the resulting message a new line is started with the other functor's name and the message.
Note that the change of the status string is not considered as a change in the functor status. write the functor in the given ioHandler. The default implementation is to write just the parameters object.
handler | the ioHandler to be used | |
complete | if true (the default) the enclosing begin/end will be also written, otherwise only the data block will be written. |
Reimplemented from lti::functor.