|
CMP++: Uncertainty Quantification & Bayesian Calibration
|
Principal Component Analysis (PCA) feature scaler and dimension reducer. More...
#include <scaler.h>


Public Member Functions | |
| PCA (size_t nComponents) | |
| Constructs a PCA scaler targeting a specific latent dimensionality. | |
| PCA (const PCA &other)=default | |
| PCA (PCA &&other)=default | |
| ~PCA ()=default | |
| PCA & | operator= (const PCA &other)=default |
| PCA & | operator= (PCA &&other)=default |
| Eigen::VectorXd | transform (const Eigen::Ref< const Eigen::VectorXd > &data) const override |
| Transforms the input data from physical space to the scaled latent space. | |
| Eigen::VectorXd | inverseTransform (const Eigen::Ref< const Eigen::VectorXd > &data) const override |
| Reconstructs the data from the scaled latent space back to physical space. | |
| Eigen::VectorXd | getIntercept () const override |
| Retrieves the intercept vector \( \mu \) used in the transformation. | |
| Eigen::MatrixXd | getScale () const override |
| Retrieves the scaling matrix \( S \) used in the transformation. | |
| void | fit (const Eigen::Ref< const Eigen::MatrixXd > &data) override |
| Learns the scaling parameters (e.g., mean, variance) from the training data. | |
| Eigen::MatrixXd | fit_transform (const Eigen::Ref< const Eigen::MatrixXd > &data) override |
| Fits the scaling parameters to the data and subsequently transforms the data. | |
| void | resize (size_t nComponents) |
| Resizes the number of retained principal components \( M \) after fitting. | |
| Eigen::VectorXd | getEigenvalues () const |
| Returns the eigenvalues \( \mathbf{\Lambda} \) of the covariance matrix. | |
| Eigen::MatrixXd | getEigenvectors () const |
| Returns the eigenvectors \( \mathbf{V} \) of the covariance matrix. | |
Private Member Functions | |
| void | eigenDecomposition () |
| Internal helper to execute the eigendecomposition on the current covariance matrix. | |
Private Attributes | |
| Eigen::VectorXd | mean_ |
| The empirical mean vector \( \boldsymbol{\mu} \). | |
| Eigen::SelfAdjointEigenSolver< Eigen::MatrixXd > | eigenSolver_ |
| Eigen solver storing the eigenvectors \( \mathbf{V} \) and eigenvalues \( \mathbf{\Lambda} \). | |
| Eigen::MatrixXd | sqrtCov_ |
| Precomputed square root of the truncated eigenvalues matrix \( \mathbf{\Lambda}_M^{1/2} \). | |
| Eigen::MatrixXd | sqrtCovInv_ |
| Precomputed inverse square root of the truncated eigenvalues matrix \( \mathbf{\Lambda}_M^{-1/2} \). | |
| size_t | nComponents_ |
| The number of principal components \( M \) to retain. | |
Principal Component Analysis (PCA) feature scaler and dimension reducer.
Centers data matrix \(\mathbf{X} \in \mathbb{R}^{N \times D}\) around column mean \(\boldsymbol{\mu}\) and computes the eigendecomposition of the sample covariance matrix \(\boldsymbol{\Sigma}\):
\[ \boldsymbol{\Sigma} = \mathbf{V} \mathbf{\Lambda} \mathbf{V}^T \]
where \(\mathbf{V}\) contains orthogonal eigenvectors and \(\mathbf{\Lambda}\) contains eigenvalues in descending order. The transformation projects \(\mathbf{x}\) into a lower-dimensional latent space of size \(M\):
\[ \mathbf{y} = \mathbf{\Lambda}_M^{-1/2} \mathbf{V}_M^T (\mathbf{x} - \boldsymbol{\mu}) \]
The inverse transformation reconstructs the point:
\[ \mathbf{x} = \mathbf{V}_M \mathbf{\Lambda}_M^{1/2} \mathbf{y} + \boldsymbol{\mu} \]
fit() computes the mean \(\boldsymbol{\mu}\) and covariance \(\boldsymbol{\Sigma}\) of the training matrix, then runs Eigen::SelfAdjointEigenSolver.transform() centers the query vector, projects it onto the principal eigenvectors, and scales it by the inverse square root of eigenvalues.inverseTransform() rescales by square root eigenvalues, projects back to physical coordinates, and adds the mean.
|
inline |
Constructs a PCA scaler targeting a specific latent dimensionality.
| nComponents | Number of principal components \( M \) to retain. |
|
default |
|
default |
|
default |
|
private |
Internal helper to execute the eigendecomposition on the current covariance matrix.
|
overridevirtual |
Learns the scaling parameters (e.g., mean, variance) from the training data.
| data | A matrix \( X \in \mathbb{R}^{n \times d} \) of training samples. |
Implements cmp::scaler::Scaler.
|
overridevirtual |
Fits the scaling parameters to the data and subsequently transforms the data.
| data | A matrix \( X \in \mathbb{R}^{n \times d} \) of training samples. |
Implements cmp::scaler::Scaler.
|
inline |
Returns the eigenvalues \( \mathbf{\Lambda} \) of the covariance matrix.
|
inline |
Returns the eigenvectors \( \mathbf{V} \) of the covariance matrix.
|
inlineoverridevirtual |
Retrieves the intercept vector \( \mu \) used in the transformation.
Implements cmp::scaler::Scaler.
|
inlineoverridevirtual |
Retrieves the scaling matrix \( S \) used in the transformation.
Implements cmp::scaler::Scaler.
|
overridevirtual |
Reconstructs the data from the scaled latent space back to physical space.
| data | A column vector \( y \) in the scaled space. |
Implements cmp::scaler::Scaler.
| void cmp::scaler::PCA::resize | ( | size_t | nComponents | ) |
Resizes the number of retained principal components \( M \) after fitting.
| nComponents | The new number of components to retain. |
|
overridevirtual |
Transforms the input data from physical space to the scaled latent space.
| data | A column vector \( x \) representing a single data point in physical space. |
Implements cmp::scaler::Scaler.
|
private |
Eigen solver storing the eigenvectors \( \mathbf{V} \) and eigenvalues \( \mathbf{\Lambda} \).
|
private |
The empirical mean vector \( \boldsymbol{\mu} \).
|
private |
The number of principal components \( M \) to retain.
|
private |
Precomputed square root of the truncated eigenvalues matrix \( \mathbf{\Lambda}_M^{1/2} \).
|
private |
Precomputed inverse square root of the truncated eigenvalues matrix \( \mathbf{\Lambda}_M^{-1/2} \).