CMP++: Uncertainty Quantification & Bayesian Calibration
Loading...
Searching...
No Matches
cmp::scaler::StandardScaler Class Reference

Standardizes features by removing the mean and scaling to unit variance using Cholesky decomposition. More...

#include <scaler.h>

Inheritance diagram for cmp::scaler::StandardScaler:
Collaboration diagram for cmp::scaler::StandardScaler:

Public Member Functions

 StandardScaler ()=default
 Default constructor.
 
 StandardScaler (const Eigen::Ref< const Eigen::VectorXd > &mean, const Eigen::Ref< const Eigen::MatrixXd > &scale)
 Constructs a StandardScaler with a pre-computed mean and covariance scale.
 
 StandardScaler (const StandardScaler &other)=default
 
 StandardScaler (StandardScaler &&other)=default
 
 ~StandardScaler ()=default
 
StandardScaleroperator= (const StandardScaler &other)=default
 
StandardScaleroperator= (StandardScaler &&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.
 

Private Attributes

Eigen::VectorXd mean_
 The empirical mean vector \( \mu \) of the training dataset.
 
Eigen::LLT< Eigen::MatrixXd > lltDecomposition_
 The LLT (Cholesky) decomposition of the covariance matrix \( \Sigma \).
 

Detailed Description

Standardizes features by removing the mean and scaling to unit variance using Cholesky decomposition.

Mathematical Formulation

Given data matrix \( X \in \mathbb{R}^{n \times d} \), let \( \mu \in \mathbb{R}^d \) be the column-wise mean and \( \Sigma \in \mathbb{R}^{d \times d} \) be the covariance matrix. We decompose the covariance matrix via the lower Cholesky factor \( L \) such that:

\[ \Sigma = L L^T \]

The transformation maps:

\[ y = L^{-1}(x - \mu) \]

The inverse transformation maps:

\[ x = L y + \mu \]

  • ### Implementation Algorithm
  1. Fit: Calculate mean vector \( \mu \) and covariance matrix \( \Sigma \) of \( X \), then perform Cholesky LLT decomposition to obtain \( L \).
  2. Transform: Solve the lower triangular system \( L y = x - \mu \) to compute standardized data.
  3. Inverse Transform: Compute \( L y + \mu \) via matrix multiplication and vector addition.

Constructor & Destructor Documentation

◆ StandardScaler() [1/4]

cmp::scaler::StandardScaler::StandardScaler ( )
default

Default constructor.

◆ StandardScaler() [2/4]

cmp::scaler::StandardScaler::StandardScaler ( const Eigen::Ref< const Eigen::VectorXd > &  mean,
const Eigen::Ref< const Eigen::MatrixXd > &  scale 
)
inline

Constructs a StandardScaler with a pre-computed mean and covariance scale.

Parameters
meanPre-computed mean vector \( \mu \).
scalePre-computed covariance matrix \( \Sigma \) (will be decomposed internally).

◆ StandardScaler() [3/4]

cmp::scaler::StandardScaler::StandardScaler ( const StandardScaler other)
default

◆ StandardScaler() [4/4]

cmp::scaler::StandardScaler::StandardScaler ( StandardScaler &&  other)
default

◆ ~StandardScaler()

cmp::scaler::StandardScaler::~StandardScaler ( )
default

Member Function Documentation

◆ fit()

void cmp::scaler::StandardScaler::fit ( const Eigen::Ref< const Eigen::MatrixXd > &  data)
overridevirtual

Learns the scaling parameters (e.g., mean, variance) from the training data.

Parameters
dataA matrix \( X \in \mathbb{R}^{n \times d} \) of training samples.

Implements cmp::scaler::Scaler.

◆ fit_transform()

Eigen::MatrixXd cmp::scaler::StandardScaler::fit_transform ( const Eigen::Ref< const Eigen::MatrixXd > &  data)
overridevirtual

Fits the scaling parameters to the data and subsequently transforms the data.

Parameters
dataA matrix \( X \in \mathbb{R}^{n \times d} \) of training samples.
Returns
The transformed dataset matrix \( Y \).

Implements cmp::scaler::Scaler.

◆ getIntercept()

Eigen::VectorXd cmp::scaler::StandardScaler::getIntercept ( ) const
inlineoverridevirtual

Retrieves the intercept vector \( \mu \) used in the transformation.

Returns
The intercept vector.

Implements cmp::scaler::Scaler.

◆ getScale()

Eigen::MatrixXd cmp::scaler::StandardScaler::getScale ( ) const
inlineoverridevirtual

Retrieves the scaling matrix \( S \) used in the transformation.

Returns
The scaling matrix.

Implements cmp::scaler::Scaler.

◆ inverseTransform()

Eigen::VectorXd cmp::scaler::StandardScaler::inverseTransform ( const Eigen::Ref< const Eigen::VectorXd > &  data) const
overridevirtual

Reconstructs the data from the scaled latent space back to physical space.

Parameters
dataA column vector \( y \) in the scaled space.
Returns
The unscaled physical data vector \( x \).

Implements cmp::scaler::Scaler.

◆ operator=() [1/2]

StandardScaler & cmp::scaler::StandardScaler::operator= ( const StandardScaler other)
default

◆ operator=() [2/2]

StandardScaler & cmp::scaler::StandardScaler::operator= ( StandardScaler &&  other)
default

◆ transform()

Eigen::VectorXd cmp::scaler::StandardScaler::transform ( const Eigen::Ref< const Eigen::VectorXd > &  data) const
overridevirtual

Transforms the input data from physical space to the scaled latent space.

Parameters
dataA column vector \( x \) representing a single data point in physical space.
Returns
The scaled data vector \( y \).

Implements cmp::scaler::Scaler.

Member Data Documentation

◆ lltDecomposition_

Eigen::LLT<Eigen::MatrixXd> cmp::scaler::StandardScaler::lltDecomposition_
private

The LLT (Cholesky) decomposition of the covariance matrix \( \Sigma \).

◆ mean_

Eigen::VectorXd cmp::scaler::StandardScaler::mean_
private

The empirical mean vector \( \mu \) of the training dataset.


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