mlpack  master
Public Member Functions | Private Member Functions | Private Attributes | List of all members
mlpack::pca::PCAType< DecompositionPolicy > Class Template Reference

This class implements principal components analysis (PCA). More...

Public Member Functions

 PCAType (const bool scaleData=false, const DecompositionPolicy &decomposition=DecompositionPolicy())
 Create the PCA object, specifying if the data should be scaled in each dimension by standard deviation when PCA is performed. More...
 
void Apply (const arma::mat &data, arma::mat &transformedData, arma::vec &eigVal, arma::mat &eigvec)
 Apply Principal Component Analysis to the provided data set. More...
 
void Apply (const arma::mat &data, arma::mat &transformedData, arma::vec &eigVal)
 Apply Principal Component Analysis to the provided data set. More...
 
double Apply (arma::mat &data, const size_t newDimension)
 Use PCA for dimensionality reduction on the given dataset. More...
 
double Apply (arma::mat &data, const int newDimension)
 This overload is here to make sure int gets casted right to size_t. More...
 
double Apply (arma::mat &data, const double varRetained)
 Use PCA for dimensionality reduction on the given dataset. More...
 
bool ScaleData () const
 Get whether or not this PCA object will scale (by standard deviation) the data when PCA is performed. More...
 
bool & ScaleData ()
 Modify whether or not this PCA object will scale (by standard deviation) the data when PCA is performed. More...
 

Private Member Functions

void ScaleData (arma::mat &centeredData)
 Scaling the data is when we reduce the variance of each dimension to 1. More...
 

Private Attributes

DecompositionPolicy decomposition
 Decomposition method used to perform principal components analysis. More...
 
bool scaleData
 Whether or not the data will be scaled by standard deviation when PCA is performed. More...
 

Detailed Description

template<typename DecompositionPolicy = ExactSVDPolicy>
class mlpack::pca::PCAType< DecompositionPolicy >

This class implements principal components analysis (PCA).

This is a common, widely-used technique that is often used for either dimensionality reduction or transforming data into a better basis. Further information on PCA can be found in almost any statistics or machine learning textbook, and all over the internet. Note this class will be changed to have the name PCA in mlpack 3.0.0

Definition at line 34 of file pca.hpp.

Constructor & Destructor Documentation

template<typename DecompositionPolicy = ExactSVDPolicy>
mlpack::pca::PCAType< DecompositionPolicy >::PCAType ( const bool  scaleData = false,
const DecompositionPolicy &  decomposition = DecompositionPolicy() 
)

Create the PCA object, specifying if the data should be scaled in each dimension by standard deviation when PCA is performed.

Parameters
scaleDataWhether or not to scale the data.

Member Function Documentation

template<typename DecompositionPolicy = ExactSVDPolicy>
void mlpack::pca::PCAType< DecompositionPolicy >::Apply ( const arma::mat &  data,
arma::mat &  transformedData,
arma::vec &  eigVal,
arma::mat &  eigvec 
)

Apply Principal Component Analysis to the provided data set.

It is safe to pass the same matrix reference for both data and transformedData.

Parameters
dataData matrix.
transformedDataMatrix to put results of PCA into.
eigvalVector to put eigenvalues into.
eigvecMatrix to put eigenvectors (loadings) into.

Referenced by mlpack::pca::PCAType< DecompositionPolicy >::Apply().

template<typename DecompositionPolicy = ExactSVDPolicy>
void mlpack::pca::PCAType< DecompositionPolicy >::Apply ( const arma::mat &  data,
arma::mat &  transformedData,
arma::vec &  eigVal 
)

Apply Principal Component Analysis to the provided data set.

It is safe to pass the same matrix reference for both data and transformedData.

Parameters
dataData matrix.
transformedDataMatrix to store results of PCA in.
eigValVector to put eigenvalues into.
template<typename DecompositionPolicy = ExactSVDPolicy>
double mlpack::pca::PCAType< DecompositionPolicy >::Apply ( arma::mat &  data,
const size_t  newDimension 
)

Use PCA for dimensionality reduction on the given dataset.

This will save the newDimension largest principal components of the data and remove the rest. The parameter returned is the amount of variance of the data that is retained; this is a value between 0 and 1. For instance, a value of 0.9 indicates that 90% of the variance present in the data was retained.

Parameters
dataData matrix.
newDimensionNew dimension of the data.
Returns
Amount of the variance of the data retained (between 0 and 1).
template<typename DecompositionPolicy = ExactSVDPolicy>
double mlpack::pca::PCAType< DecompositionPolicy >::Apply ( arma::mat &  data,
const int  newDimension 
)
inline

This overload is here to make sure int gets casted right to size_t.

Definition at line 86 of file pca.hpp.

References mlpack::pca::PCAType< DecompositionPolicy >::Apply().

template<typename DecompositionPolicy = ExactSVDPolicy>
double mlpack::pca::PCAType< DecompositionPolicy >::Apply ( arma::mat &  data,
const double  varRetained 
)

Use PCA for dimensionality reduction on the given dataset.

This will save as many dimensions as necessary to retain at least the given amount of variance (specified by parameter varRetained). The amount should be between 0 and 1; if the amount is 0, then only 1 dimension will be retained. If the amount is 1, then all dimensions will be retained.

The method returns the actual amount of variance retained, which will always be greater than or equal to the varRetained parameter.

Parameters
dataData matrix.
varRetainedLower bound on amount of variance to retain; should be between 0 and 1.
Returns
Actual amount of variance retained (between 0 and 1).
template<typename DecompositionPolicy = ExactSVDPolicy>
bool mlpack::pca::PCAType< DecompositionPolicy >::ScaleData ( ) const
inline

Get whether or not this PCA object will scale (by standard deviation) the data when PCA is performed.

Definition at line 110 of file pca.hpp.

References mlpack::pca::PCAType< DecompositionPolicy >::scaleData.

template<typename DecompositionPolicy = ExactSVDPolicy>
bool& mlpack::pca::PCAType< DecompositionPolicy >::ScaleData ( )
inline

Modify whether or not this PCA object will scale (by standard deviation) the data when PCA is performed.

Definition at line 113 of file pca.hpp.

References mlpack::pca::PCAType< DecompositionPolicy >::scaleData.

template<typename DecompositionPolicy = ExactSVDPolicy>
void mlpack::pca::PCAType< DecompositionPolicy >::ScaleData ( arma::mat &  centeredData)
inlineprivate

Scaling the data is when we reduce the variance of each dimension to 1.

Definition at line 117 of file pca.hpp.

References mlpack::pca::PCAType< DecompositionPolicy >::scaleData.

Member Data Documentation

template<typename DecompositionPolicy = ExactSVDPolicy>
DecompositionPolicy mlpack::pca::PCAType< DecompositionPolicy >::decomposition
private

Decomposition method used to perform principal components analysis.

Definition at line 141 of file pca.hpp.

template<typename DecompositionPolicy = ExactSVDPolicy>
bool mlpack::pca::PCAType< DecompositionPolicy >::scaleData
private

Whether or not the data will be scaled by standard deviation when PCA is performed.

Definition at line 138 of file pca.hpp.

Referenced by mlpack::pca::PCAType< DecompositionPolicy >::ScaleData().


The documentation for this class was generated from the following file: