eos 1.4.0
|
PCA and functionality to build statistical models. More...
Enumerations | |
enum class | Covariance { AtA , AAt } |
Functions | |
std::pair< Eigen::MatrixXf, Eigen::VectorXf > | pca (const Eigen::Ref< const Eigen::MatrixXf > data, Covariance covariance_type=Covariance::AtA) |
Compute PCA on a mean-centred data matrix, and return the eigenvectors and respective eigenvalues. | |
std::pair< Eigen::MatrixXf, Eigen::VectorXf > | pca (const Eigen::Ref< const Eigen::MatrixXf > data, int num_eigenvectors_to_keep, Covariance covariance_type=Covariance::AtA) |
Performs PCA and returns num_eigenvectors_to_keep eigenvectors and eigenvalues. | |
std::pair< Eigen::MatrixXf, Eigen::VectorXf > | pca (const Eigen::Ref< const Eigen::MatrixXf > data, float variance_to_keep, Covariance covariance_type=Covariance::AtA) |
Performs PCA and returns the number of eigenvectors and eigenvalues to retain variance_to_keep variance of the original data. | |
morphablemodel::PcaModel | pca (const Eigen::Ref< const Eigen::MatrixXf > data, std::vector< std::array< int, 3 > > triangle_list, Covariance covariance_type=Covariance::AtA) |
Performs PCA on the given data (including subtracting the mean) and returns the built PcaModel. | |
PCA and functionality to build statistical models.
|
strong |
|
inline |
Compute PCA on a mean-centred data matrix, and return the eigenvectors and respective eigenvalues.
Computes PCA (principal component analysis) on the given mean-centred data matrix. Note that you should subtract the mean from the data beforehand, this function will not do so. The function computes PCA based on an eigendecomposition of the covariance matrix. If the dimensionality of the data is high, the PCA can be computed on the inner-product matrix A*A^t instead of the covariance matrix A^t*A by setting the flag Covariance::AAt
.
The function returns n-1 eigenvectors and eigenvalues, where n is the number of data samples given. The eigenvectors and eigenvalues are returned in descending order, with the largest (most significant) first.
Note: Changing the covariance_type
may return eigenvectors with different signs, but otherwise equivalent. This is completely fine as the sign of eigenvectors is arbitrary anyway.
Developer notes: If you want to avoid a copy: myarray = np.array(source, order='F') (this will change the numpy array to colmajor, so Eigen can directly accept it. There is other ways how to avoid copies: See: https://eigen.tuxfamily.org/dox/TopicFunctionTakingEigenTypes.html. http://pybind11.readthedocs.io/en/master/advanced/cast/eigen.html Also it would be nice if the function could accept any Eigen matrix types (e.g. a MatrixXf or MatrixXd).
[in] | data | Mean-free data matrix, with each row being a training sample. |
[in] | covariance_type | Specifies whether PCA is computed on the covariance matrix AtA (default) or the inner-product matrix AAt. |
|
inline |
Performs PCA and returns the number of eigenvectors and eigenvalues to retain variance_to_keep
variance of the original data.
See std::pair<Eigen::MatrixXf, Eigen::VectorXf> pca(const Eigen::Ref<const Eigen::MatrixXf>, Covariance).
variance_to_keep
needs to be between 0.0 and 1.0.
[in] | data | Mean-free data matrix, with each row being a training sample. |
[in] | variance_to_keep | Specifies how much of the variance to retain, in percent (between 0 and 1). |
[in] | covariance_type | Specifies whether PCA is computed on the covariance matrix AtA (default) or the inner-product matrix AAt. |
|
inline |
Performs PCA and returns num_eigenvectors_to_keep
eigenvectors and eigenvalues.
See std::pair<Eigen::MatrixXf, Eigen::VectorXf> pca(const Eigen::Ref<const Eigen::MatrixXf>, Covariance).
num_eigenvectors_to_keep
needs to be smaller or equal to n-1, where n is number of rows of data (i.e. number of data samples).
[in] | data | Mean-free data matrix, with each row being a training sample. |
[in] | num_eigenvectors_to_keep | Specifies how many eigenvectors and eigenvalues to keep. |
[in] | covariance_type | Specifies whether PCA is computed on the covariance matrix AtA (default) or the inner-product matrix AAt. |
|
inline |
Performs PCA on the given data (including subtracting the mean) and returns the built PcaModel.
See std::pair<Eigen::MatrixXf, Eigen::VectorXf> pca(const Eigen::Ref<const Eigen::MatrixXf>, Covariance) for the details on the PCA.
data
should be a (num_training_samples x num_data_dimensions) matrix, i.e. each row one data instance (e.g. one 3D scan).
[in] | data | Data matrix (orignal, without the mean subtracted), with each row being a training sample. |
[in] | triangle_list | Triangle list to build the topology of the PcaModel mesh. |
[in] | covariance_type | Specifies whether PCA is computed on the covariance matrix AtA (default) or the inner-product matrix AAt. |