Deep Learning Algorithm Implementations 1.0.0
C++ implementations of fundamental deep learning algorithms
Loading...
Searching...
No Matches
ml::PCA< T > Class Template Reference

#include <pca.hpp>

Public Member Functions

 PCA ()=default
 Default constructor.
 
void fit (const Matrix< T > &data, bool center=true, bool scale=false)
 Fit the PCA model to the data.
 
Matrix< T > transform (const Matrix< T > &data, size_t n_components=0) const
 Transform data to the principal component space.
 
Matrix< T > fit_transform (const Matrix< T > &data, size_t n_components=0, bool center=true, bool scale=false)
 Fit the model and transform the data in one step.
 
std::vector< T > explained_variance_ratio () const
 Get the explained variance ratio for each component.
 
Matrix< T > components () const
 Get the principal components (eigenvectors)
 
std::vector< T > singular_values () const
 Get the singular values (square roots of eigenvalues)
 

Detailed Description

template<typename T>
class ml::PCA< T >

Definition at line 41 of file pca.hpp.

Constructor & Destructor Documentation

◆ PCA()

template<typename T >
ml::PCA< T >::PCA ( )
default

Member Function Documentation

◆ components()

template<typename T >
Matrix< T > ml::PCA< T >::components ( ) const

Get the principal components (eigenvectors)

Returns
Matrix where each column is a principal component
Examples
/home/runner/work/deep-learning-algo-impls/deep-learning-algo-impls/include/ml/pca.hpp.

Definition at line 171 of file pca.cpp.

◆ explained_variance_ratio()

template<typename T >
std::vector< T > ml::PCA< T >::explained_variance_ratio ( ) const

Get the explained variance ratio for each component.

Returns
Vector of explained variance ratios
Examples
/home/runner/work/deep-learning-algo-impls/deep-learning-algo-impls/include/ml/pca.hpp.

Definition at line 163 of file pca.cpp.

◆ fit()

template<typename T >
void ml::PCA< T >::fit ( const Matrix< T > &  data,
bool  center = true,
bool  scale = false 
)

Fit the PCA model to the data.

Parameters
dataInput data matrix where rows are samples and columns are features
centerWhether to center the data before computing PCA
scaleWhether to scale the data to unit variance before computing PCA
Examples
/home/runner/work/deep-learning-algo-impls/deep-learning-algo-impls/include/ml/pca.hpp.

Definition at line 10 of file pca.cpp.

◆ fit_transform()

template<typename T >
Matrix< T > ml::PCA< T >::fit_transform ( const Matrix< T > &  data,
size_t  n_components = 0,
bool  center = true,
bool  scale = false 
)

Fit the model and transform the data in one step.

Parameters
dataInput data matrix where rows are samples and columns are features
n_componentsNumber of components to keep (if 0, keep all components)
centerWhether to center the data before computing PCA
scaleWhether to scale the data to unit variance before computing PCA
Returns
Transformed data matrix
Examples
/home/runner/work/deep-learning-algo-impls/deep-learning-algo-impls/include/ml/pca.hpp.

Definition at line 157 of file pca.cpp.

◆ singular_values()

template<typename T >
std::vector< T > ml::PCA< T >::singular_values ( ) const

Get the singular values (square roots of eigenvalues)

Returns
Vector of singular values
Examples
/home/runner/work/deep-learning-algo-impls/deep-learning-algo-impls/include/ml/pca.hpp.

Definition at line 179 of file pca.cpp.

◆ transform()

template<typename T >
Matrix< T > ml::PCA< T >::transform ( const Matrix< T > &  data,
size_t  n_components = 0 
) const

Transform data to the principal component space.

Parameters
dataInput data matrix where rows are samples and columns are features
n_componentsNumber of components to keep (if 0, keep all components)
Returns
Transformed data matrix
Examples
/home/runner/work/deep-learning-algo-impls/deep-learning-algo-impls/include/ml/pca.hpp.

Definition at line 117 of file pca.cpp.


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