libcrn
3.9.5
A document image processing library
|
Class to perform Principal Componant Analysis. More...
#include <CRNPCA.h>
Public Member Functions | |
PCA (const MatrixDouble &data, bool data_reduction_flag=true) | |
Constructor. More... | |
PCA (const std::vector< std::vector< double > > &data, bool data_reduction_flag=true) | |
Constructor. More... | |
PCA (const std::vector< std::vector< double > > &data, const std::vector< size_t > &cards, bool data_reduction_flag=true) | |
Constructor from weighted vectors. More... | |
PCA (const std::map< std::vector< double >, size_t > &data, bool data_reduction_flag=true) | |
Constructor from map. More... | |
template<typename ITER > | |
PCA (ITER begin, ITER end, bool data_reduction_flag=true) | |
Constructor from iterators. More... | |
PCA (const PCA &)=default | |
Constructor. More... | |
PCA (PCA &&)=default | |
virtual | ~PCA () override=default |
Destructor. More... | |
PCA & | operator= (const PCA &)=default |
PCA & | operator= (PCA &&)=default |
size_t | GetDimension () const noexcept |
Returns the dimension of feature space. More... | |
const std::vector< double > & | GetMeans () const noexcept |
Returns the mean values computed for sample data. More... | |
double | GetMean (size_t d) const |
Returns the mean value of d-th feature computed for sample data. More... | |
const std::vector< double > & | GetDeviations () const noexcept |
Returns the deviation computed for sample data. More... | |
double | GetDeviation (size_t d) const |
Returns the deviation of d-th feature computed for sample data. More... | |
const std::multimap< double, MatrixDouble > & | GetEigensystem () const noexcept |
Returns the eigensystem computed on covariance matrix of last sample data. More... | |
MatrixDouble | Transform (const MatrixDouble &patterns, size_t nb_features=1u) const |
Apply transform to given patterns. More... | |
std::vector< std::vector < double > > | Transform (const std::vector< std::vector< double > > &data, const size_t nb_features=0u) const |
Apply transform to given patterns. More... | |
std::vector< std::vector < double > > | ReverseTransform (const std::vector< std::vector< double > > &data) const |
Apply reverse transform to get given patterns' pre-images. More... | |
void | Deserialize (xml::Element &el) |
xml::Element | Serialize (xml::Element &parent) const |
PCA (xml::Element &el) | |
![]() | |
virtual | ~Object ()=default |
Class to perform Principal Componant Analysis.
Principal Componant Analysis
PCA::PCA | ( | const MatrixDouble & | data, |
bool | data_reduction_flag = true |
||
) |
Constructor.
Constructor
[in] | data | matrix of double numbers in which patterns are stored as rows |
[in] | data_reduction_flag | flag to indicate if the data have to be reduced |
Definition at line 41 of file CRNPCA.cpp.
PCA::PCA | ( | const std::vector< std::vector< double > > & | data, |
bool | data_reduction_flag = true |
||
) |
Constructor.
Constructor
[in] | data | vector of vectors of double numbers in which patterns are stored |
[in] | data_reduction_flag | flag to indicate if the data have to be reduced |
Definition at line 140 of file CRNPCA.cpp.
PCA::PCA | ( | const std::vector< std::vector< double > > & | data, |
const std::vector< size_t > & | cards, | ||
bool | data_reduction_flag = true |
||
) |
Constructor from weighted vectors.
Constructor
[in] | data | collection of vectors of double numbers |
[in] | cards | pattern cardinals |
[in] | data_reduction_flag | flag to indicate if the data have to be reduced |
Definition at line 247 of file CRNPCA.cpp.
PCA::PCA | ( | const std::map< std::vector< double >, size_t > & | data, |
bool | data_reduction_flag = true |
||
) |
Constructor from map.
Constructor
[in] | data | map of vectors of double numbers with cardinals |
[in] | data_reduction_flag | flag to indicate if the data have to be reduced |
Definition at line 359 of file CRNPCA.cpp.
crn::PCA::PCA | ( | ITER | begin, |
ITER | end, | ||
bool | data_reduction_flag = true |
||
) |
Constructor from iterators.
Constructor
Performs principal component analysis over patterns given as a value-cardinal pairs
[in] | begin | iterator pointing at the begining of the data collection |
[in] | end | ending iterator |
[in] | data_reduction_flag | flag to indicate if data should be reduced for PCA estimate |
|
default |
Constructor.
|
default |
|
overridevirtualdefault |
Destructor.
|
inline |
void PCA::Deserialize | ( | xml::Element & | el | ) |
Unsafe load from XML node
ExceptionInvalidArgument | not a UnivariateGaussianMixture |
ExceptionNotFound | cannot find attribute |
ExceptionDomain | wrong attribute |
[in] | el | the element to load |
Definition at line 713 of file CRNPCA.cpp.
double PCA::GetDeviation | ( | size_t | d | ) | const |
Returns the deviation of d-th feature computed for sample data.
Returns the deviation of d-th feature
ExceptionDimension | incompatible patter dimensions |
[in] | d | index of desired value |
Definition at line 539 of file CRNPCA.cpp.
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
double PCA::GetMean | ( | size_t | d | ) | const |
Returns the mean value of d-th feature computed for sample data.
Returns the mean value of d-th feature
ExceptionDimension | incompatible patter dimensions |
[in] | d | index of desired value |
Definition at line 524 of file CRNPCA.cpp.
|
inlinenoexcept |
std::vector< std::vector< double > > PCA::ReverseTransform | ( | const std::vector< std::vector< double > > & | data | ) | const |
Apply reverse transform to get given patterns' pre-images.
Apply reverse transform to get given patterns' pre-images. No dimension change allowed for this version.
[in] | data | vector of multivariate patterns |
Definition at line 663 of file CRNPCA.cpp.
xml::Element PCA::Serialize | ( | xml::Element & | parent | ) | const |
Unsafe save
[in] | parent | the parent element to which we will add the new element |
Definition at line 773 of file CRNPCA.cpp.
MatrixDouble PCA::Transform | ( | const MatrixDouble & | patterns, |
size_t | nb_features = 1u |
||
) | const |
Apply transform to given patterns.
Perform projection of given patterns using current PCA attributes. Patterns are translated to make centroid become the center of space, then projected on pricipal componants from most to least significant ones.
ExceptionDimension | incompatible patter dimensions |
ExceptionDomain | incompatible output dimension |
[in] | patterns | matrix of double numbers in which patterns are stored |
[in] | nb_features | the number of principal componants used for projection |
Definition at line 560 of file CRNPCA.cpp.
std::vector< std::vector< double > > PCA::Transform | ( | const std::vector< std::vector< double > > & | data, |
const size_t | nb_features = 0u |
||
) | const |
Apply transform to given patterns.
Perform projection of given patterns using current PCA attributes. Patterns are translated to make centroid become the center of space, then projected on principal componants from most to least significant ones.
[in] | data | vector of multivariate patterns |
[in] | nb_features | the number of principal componants used for projection |
Definition at line 614 of file CRNPCA.cpp.