Skip to content

alxvth/Eigen-PCA

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Principal components analysis with Eigen

Header-only C++ principal components analysis with Eigen (3.4.1 and newer).

Example code

#include "pca/eigen-pca.hpp"

// Define your data in the format
// [p0d0, p0d1, ..., p1d0, p1d1, ..., pNd0, pNd1, ..., pNdM]
// with p0 being point 0 and d0 dimension 0, up to point N and dimension M
std::vector<float> data_in;
size_t num_dims = 50;

// Compute first two principle components
std::vector<float> pca_out;
size_t num_comp = 2;

math::pca(data_in, num_dims, pca_out, num_comp);

Settings

Two normalization procedures are implemented: Other normalization steps before this centering are possible as well:

Each normalization centers the data such that each dimension/channel has zero mean.

This project implements two PCA computation algorithms:

  • Explicitly computing the eigenvectors of the covariance matrix (math::PCA_ALG::COV)
  • Singular value decomposition (math::PCA_ALG::SVD).

The default settings are:

math::pca(data_in, num_dims, pca_out, num_comp, math:PCA_ALG::SVD, math:DATA_NORM::MINMAX);

Tests

To run some test, follow the setup instructions, which include creating reference data and ensuring that Eigen is available.

About

Header-only C++ PCA

Resources

License

Stars

Watchers

Forks

Releases

No releases published