CMP++: Uncertainty Quantification & Bayesian Calibration
Loading...
Searching...
No Matches

Namespaces

namespace  classifier
 
namespace  cluster
 
namespace  covariance
 
namespace  density
 
namespace  distribution
 
namespace  gp
 
namespace  grid
 
namespace  kernel
 
namespace  mcmc
 
namespace  mean
 
namespace  prior
 
namespace  scaler
 
namespace  sobol
 
namespace  statistics
 

Classes

struct  ChebyshevBasis
 Chebyshev orthogonal polynomial basis. More...
 
struct  HermiteBasis
 Hermite orthogonal polynomial basis. More...
 
struct  LaguerreBasis
 Laguerre orthogonal polynomial basis. More...
 
struct  LegendreBasis
 Legendre orthogonal polynomial basis. More...
 
class  ModelCluster
 Manages a clustered set of Gaussian Processes for localized regression. More...
 
class  ModelClusterPoly
 Manages a clustered set of Polynomial Chaos Expansion (PCE) models for localized regression. More...
 
class  MultiIndex
 
class  ObjectiveFunctor
 Functor wrapper for NLopt with automatic, transparent parameter space mapping (e.g., log-scaling). More...
 
class  PolynomialExpansion
 Implements multi-dimensional Polynomial Chaos Expansion (PCE) for spectral surrogate modeling. More...
 
class  Quadrature1D
 One-dimensional quadrature rule generator and integrator. More...
 
class  TensorIntegrator
 Multi-dimensional tensor product quadrature integrator. More...
 

Concepts

concept  VectorLike
 Concept for compile-time validation of vector-like containers.
 

Typedefs

using score_t = std::function< double(const Eigen::VectorXd &)>
 The score_t type A function that takes a const reference to an Eigen::VectorXd and returns a double And also its gradient counterpart, gradient_t, which takes a const reference to an Eigen::Ref<const Eigen::VectorXd> and returns an Eigen::VectorXd.
 
using gradient_t = std::function< Eigen::VectorXd(const Eigen::Ref< const Eigen::VectorXd > &)>
 

Enumerations

enum  accuracy { SECOND , FOURTH , SIXTH , EIGHTH }
 Accuracy order of the FD stencil. More...
 

Functions

const Eigen::MatrixXd DummyMatrix (0, 0)
 
const Eigen::VectorXd DummyVector (0)
 
Eigen::LDLT< Eigen::MatrixXd > ldltDecomposition (const Eigen::Ref< const Eigen::MatrixXd > &cov)
 Computes the LDLT decomposition of a symmetric matrix.
 
template<VectorLike V>
auto asEigen (const V &v) -> Eigen::Map< const Eigen::Matrix< typename V::value_type, Eigen::Dynamic, 1 > >
 Creates a non-owning, read-only Eigen view (Eigen::Map) of a vector-like container.
 
template<VectorLike V>
auto asEigen (V &v) -> Eigen::Map< Eigen::Matrix< typename V::value_type, Eigen::Dynamic, 1 > >
 Creates a non-owning, read-write Eigen view (Eigen::Map) of a vector-like container.
 
template<VectorLike V>
auto toEigen (const V &v) -> Eigen::VectorXd
 Copies the elements of a vector-like container to a new Eigen::VectorXd.
 
template<VectorLike V>
auto toStdVector (const V &v) -> std::vector< typename V::value_type >
 Copies the elements of a vector-like container to a new std::vector.
 
template<typename Derived >
Derived::PlainObject slice (const Eigen::MatrixBase< Derived > &mat, const Eigen::VectorXs &indices)
 Slices a matrix along its rows based on a set of indices.
 
template<typename DerivedX , typename DerivedY >
auto trainTestSplit (const Eigen::MatrixBase< DerivedX > &xObs, const Eigen::MatrixBase< DerivedY > &yObs, const std::pair< Eigen::VectorXs, Eigen::VectorXs > &train_test_pair)
 Function to split training data into training and test sets.
 
double fd_gradient (const Eigen::VectorXd &x_0, const std::function< double(const Eigen::VectorXd &)> fun, const int &i, const accuracy order=SECOND, const double h=1E-5)
 Computes the i-th component of the gradient of the function fun evaluated at x_0 using a central difference scheme.
 
double fd_hessian (const Eigen::VectorXd &x_0, const std::function< double(const Eigen::VectorXd &)> fun, const int &i, const int &j, const accuracy order=SECOND, const double h=1E-5)
 Computes the i-th and j-th component of the Hessian of the function fun evaluated at x_0 using a central difference scheme.
 
void write_vector (const std::vector< Eigen::VectorXd > &data, std::ofstream &o_file)
 Serializes a list of vector coordinates to a file stream.
 
void write_data (const std::vector< Eigen::VectorXd > &x, const Eigen::MatrixXd &y, std::ofstream &o_file)
 Write data points and evaluations to a file.
 
std::vector< Eigen::VectorXd > read_vector (std::ifstream &i_file, std::string delimiter=",", size_t header=0)
 Read the contents of a delimited text file into vector collections.
 
double nlopt_max (cmp::ObjectiveFunctor &f, Eigen::Ref< Eigen::VectorXd > x0, const Eigen::Ref< const Eigen::VectorXd > &lb, const Eigen::Ref< const Eigen::VectorXd > &ub, nlopt::algorithm alg=nlopt::LN_SBPLX, double ftol_rel=1e-6)
 Global helper function to execute NLopt maximization, managing the log-scaling wrapper. Users pass physical, real-world bounds and initial guesses. The function manages the log translations.
 
double wasserstein1D (Eigen::VectorXd &s1, Eigen::VectorXd &s2, double p)
 Computes the 1D Wasserstein distance between two empirical distributions.
 
double slicedWassersteinDistance (const Eigen::MatrixXd &samples_1, const Eigen::MatrixXd &samples_2, double p, int slices, size_t seed=42)
 Computes the sliced-Wasserstein distance of order p between two n-dimensional datasets.
 

Variables

constexpr double TOL = 1e-12
 
const Eigen::VectorXd ScalarZero = Eigen::VectorXd::Zero(1)
 
const Eigen::VectorXd ScalarOne = Eigen::VectorXd::Ones(1)
 

Typedef Documentation

◆ gradient_t

using cmp::gradient_t = typedef std::function<Eigen::VectorXd(const Eigen::Ref<const Eigen::VectorXd>&)>

◆ score_t

using cmp::score_t = typedef std::function<double(const Eigen::VectorXd &)>

The score_t type A function that takes a const reference to an Eigen::VectorXd and returns a double And also its gradient counterpart, gradient_t, which takes a const reference to an Eigen::Ref<const Eigen::VectorXd> and returns an Eigen::VectorXd.

Enumeration Type Documentation

◆ accuracy

Accuracy order of the FD stencil.

Note, the higher the accuracy the higher the number of function evaluations required

Enumerator
SECOND 
FOURTH 
SIXTH 
EIGHTH 

Function Documentation

◆ asEigen() [1/2]

template<VectorLike V>
auto cmp::asEigen ( const V &  v) -> Eigen::Map<const Eigen::Matrix<typename V::value_type, Eigen::Dynamic, 1>>

Creates a non-owning, read-only Eigen view (Eigen::Map) of a vector-like container.

Mathematical Formulation Maps a vector \(\mathbf{v} \in \mathbb{R}^N\) represented by a contiguous-memory container to an Eigen Vector expression without copying:

\[ \mathbf{v}_{\text{Eigen}} = \text{Map}(\mathbf{v}) \]

Template Parameters
VThe type of the vector-like container, must satisfy the VectorLike concept.
Parameters
vThe vector-like container.
Returns
A non-owning Eigen::Map view pointing to the underlying data.

◆ asEigen() [2/2]

template<VectorLike V>
auto cmp::asEigen ( V &  v) -> Eigen::Map<Eigen::Matrix<typename V::value_type, Eigen::Dynamic, 1>>

Creates a non-owning, read-write Eigen view (Eigen::Map) of a vector-like container.

Template Parameters
VThe type of the vector-like container, must satisfy the VectorLike concept.
Parameters
vThe vector-like container.
Returns
A mutable, non-owning Eigen::Map view pointing to the underlying data.

◆ DummyMatrix()

const Eigen::MatrixXd cmp::DummyMatrix ( ,
 
)
inline

◆ DummyVector()

const Eigen::VectorXd cmp::DummyVector ( )
inline

◆ fd_gradient()

double cmp::fd_gradient ( const Eigen::VectorXd &  x_0,
const std::function< double(const Eigen::VectorXd &)>  fun,
const int &  i,
const accuracy  order = SECOND,
const double  h = 1E-5 
)

Computes the i-th component of the gradient of the function fun evaluated at x_0 using a central difference scheme.

Mathematical Formulation Approximates the partial derivative of \(f: \mathbb{R}^D \to \mathbb{R}\) at \(\mathbf{x}_0\) with respect to the \(i\)-th variable using a central difference stencil:

\[ \frac{\partial f(\mathbf{x}_0)}{\partial x_i} \approx \frac{f(\mathbf{x}_0 + h \mathbf{e}_i) - f(\mathbf{x}_0 - h \mathbf{e}_i)}{2h} \]

where \(\mathbf{e}_i\) is the \(i\)-th standard basis vector, and \(h > 0\) is the step size. For higher-order accuracy (e.g., 4th, 6th, or 8th order), wider stencils are employed.

Implementation Algorithm

  1. Creates coordinate perturbations \(\mathbf{x}_0 \pm n h \mathbf{e}_i\) for stencil points \(n\).
  2. Evaluates the function fun at each perturbed point.
  3. Takes a linear combination of the function values scaled by the central difference stencil coefficients.
Parameters
x_0The point at which to evaluate the gradient
funThe function of which to evaluate the gradient
iThe component of the gradient
orderThe accuracy order (default = SECOND)
hThe step size (default = 1E-5)
Returns
The required component of the gradient

◆ fd_hessian()

double cmp::fd_hessian ( const Eigen::VectorXd &  x_0,
const std::function< double(const Eigen::VectorXd &)>  fun,
const int &  i,
const int &  j,
const accuracy  order = SECOND,
const double  h = 1E-5 
)

Computes the i-th and j-th component of the Hessian of the function fun evaluated at x_0 using a central difference scheme.

Mathematical Formulation Approximates the second-order partial derivative \(\frac{\partial^2 f(\mathbf{x}_0)}{\partial x_i \partial x_j}\) at \(\mathbf{x}_0\). For diagonal elements ( \(i = j\)):

\[ \frac{\partial^2 f(\mathbf{x}_0)}{\partial x_i^2} \approx \frac{f(\mathbf{x}_0 + h\mathbf{e}_i) - 2f(\mathbf{x}_0) + f(\mathbf{x}_0 - h\mathbf{e}_i)}{h^2} \]

For off-diagonal elements ( \(i \neq j\)):

\[ \frac{\partial^2 f(\mathbf{x}_0)}{\partial x_i \partial x_j} \approx \frac{f(\mathbf{x}_0 + h\mathbf{e}_i + h\mathbf{e}_j) - f(\mathbf{x}_0 + h\mathbf{e}_i - h\mathbf{e}_j) - f(\mathbf{x}_0 - h\mathbf{e}_i + h\mathbf{e}_j) + f(\mathbf{x}_0 - h\mathbf{e}_i - h\mathbf{e}_j)}{4h^2} \]

Implementation Algorithm

  1. Checks if \(i = j\) or \(i \neq j\).
  2. Prepares perturbations along standard directions \(\mathbf{e}_i\) and \(\mathbf{e}_j\).
  3. Evaluates the function at the perturbed points and computes the stencil difference quotient.
Parameters
x_0The point at which to evaluate the hessian
funThe function of which to evaluate the hessian
iRow of the hessian
jColumn of the hessian
orderThe accuracy order (default = SECOND)
hThe step size (default = 1E-5)
Returns
The required component of the Hessian

◆ ldltDecomposition()

Eigen::LDLT< Eigen::MatrixXd > cmp::ldltDecomposition ( const Eigen::Ref< const Eigen::MatrixXd > &  cov)
inline

Computes the LDLT decomposition of a symmetric matrix.

Mathematical Formulation For a symmetric positive semidefinite matrix \(\mathbf{A} \in \mathbb{R}^{n \times n}\), LDLT decomposes \(\mathbf{A}\) into:

\[ \mathbf{A} = \mathbf{L} \mathbf{D} \mathbf{L}^T \]

where \(\mathbf{L}\) is a lower unit triangular matrix and \(\mathbf{D}\) is a diagonal matrix. This decomposition is more numerically stable than Cholesky decomposition for semi-definite matrices as it avoids taking square roots of diagonal elements.

Implementation Algorithm Calls Eigen's .ldlt() method on the matrix block.

◆ nlopt_max()

double cmp::nlopt_max ( cmp::ObjectiveFunctor f,
Eigen::Ref< Eigen::VectorXd >  x0,
const Eigen::Ref< const Eigen::VectorXd > &  lb,
const Eigen::Ref< const Eigen::VectorXd > &  ub,
nlopt::algorithm  alg = nlopt::LN_SBPLX,
double  ftol_rel = 1e-6 
)

Global helper function to execute NLopt maximization, managing the log-scaling wrapper. Users pass physical, real-world bounds and initial guesses. The function manages the log translations.

◆ read_vector()

std::vector< Eigen::VectorXd > cmp::read_vector ( std::ifstream &  i_file,
std::string  delimiter = ",",
size_t  header = 0 
)

Read the contents of a delimited text file into vector collections.

Mathematical Formulation Parses text lines representing coordinate records to rebuild the set \(\{\mathbf{x}_i\}_{i=1}^M \subset \mathbb{R}^N\).

Implementation Algorithm

  1. Skips the specified number of header rows.
  2. Parses each line using std::getline, splitting coordinates based on the delimiter.
  3. Converts string tokens to double using standard converters, aggregates them into Eigen::VectorXd rows, and returns them as a standard vector.
Parameters
i_fileAn open and valid file stream.
delimiterThe delimiter string separating columns (default is ",")
headerThe number of header rows to skip (default is 0)
Returns
A std::vector containing each row of the file as a Eigen::VectorXd.

◆ slice()

template<typename Derived >
Derived::PlainObject cmp::slice ( const Eigen::MatrixBase< Derived > &  mat,
const Eigen::VectorXs indices 
)

Slices a matrix along its rows based on a set of indices.

Mathematical Formulation For a matrix \(\mathbf{X} \in \mathbb{R}^{M \times D}\) and a vector of indices \(\mathcal{I} = [i_1, i_2, \dots, i_K]^T\), computes the sliced matrix \(\mathbf{X}_{\mathcal{I}} \in \mathbb{R}^{K \times D}\):

\[ \left(\mathbf{X}_{\mathcal{I}}\right)_{k, \cdot} = \mathbf{X}_{i_k, \cdot} \]

Template Parameters
DerivedThe derived Eigen matrix expression type.
Parameters
matThe input matrix.
indicesA vector of row indices to extract.
Returns
A new plain matrix containing only the specified rows of mat.

◆ slicedWassersteinDistance()

double cmp::slicedWassersteinDistance ( const Eigen::MatrixXd &  samples_1,
const Eigen::MatrixXd &  samples_2,
double  p,
int  slices,
size_t  seed = 42 
)

Computes the sliced-Wasserstein distance of order p between two n-dimensional datasets.

Mathematical Formulation The Sliced Wasserstein distance projects multivariate distributions \(\mu, \nu\) in \(\mathbb{R}^D\) onto 1D lines along random directions \(\boldsymbol{\theta} \in \mathbb{S}^{D-1}\) (the unit sphere):

\[ SW_p^p(\mu, \nu) = \int_{\mathbb{S}^{D-1}} W_p^p(\boldsymbol{\theta}^* \mu, \boldsymbol{\theta}^* \nu) d\boldsymbol{\theta} \approx \frac{1}{L} \sum_{l=1}^L W_p^p(\boldsymbol{\theta}_l^T \mathbf{X}_1, \boldsymbol{\theta}_l^T \mathbf{X}_2) \]

where \(\boldsymbol{\theta}_l\) are random projection directions drawn uniformly from the unit sphere.

Implementation Algorithm

  1. Generates \(L\) random directions by sampling from a standard multivariate Gaussian and normalizing to unit norm.
  2. Projects the multivariate samples \(\mathbf{X}_1\) and \(\mathbf{X}_2\) onto each direction.
  3. Computes the 1D Wasserstein distance for each projection and returns the arithmetic mean.
Parameters
samples_1The first set of samples (N x D matrix).
samples_2The second set of samples (M x D matrix).
pThe order of the distance.
slicesThe number of slices to compute.
seedThe seed for the random number generator (passed to thread-local PRNGs).
Returns
SW_p^p, the p-th power of the sliced Wasserstein distance.

◆ toEigen()

template<VectorLike V>
auto cmp::toEigen ( const V &  v) -> Eigen::VectorXd

Copies the elements of a vector-like container to a new Eigen::VectorXd.

Template Parameters
VThe type of the vector-like container, must satisfy the VectorLike concept.
Parameters
vThe vector-like container to copy.
Returns
A new Eigen::VectorXd containing a copy of the elements of v.

◆ toStdVector()

template<VectorLike V>
auto cmp::toStdVector ( const V &  v) -> std::vector<typename V::value_type>

Copies the elements of a vector-like container to a new std::vector.

Template Parameters
VThe type of the vector-like container, must satisfy the VectorLike concept.
Parameters
vThe vector-like container to copy.
Returns
A new std::vector containing a copy of the elements of v.

◆ trainTestSplit()

template<typename DerivedX , typename DerivedY >
auto cmp::trainTestSplit ( const Eigen::MatrixBase< DerivedX > &  xObs,
const Eigen::MatrixBase< DerivedY > &  yObs,
const std::pair< Eigen::VectorXs, Eigen::VectorXs > &  train_test_pair 
)

Function to split training data into training and test sets.

Parameters
xObsThe observations matrix.
yObsThe labels/values vector.
train_test_pairA pair of vectors containing the training and test indices.
Returns
A tuple containing the training observations, training labels, test observations, and test labels.

◆ wasserstein1D()

double cmp::wasserstein1D ( Eigen::VectorXd &  s1,
Eigen::VectorXd &  s2,
double  p 
)

Computes the 1D Wasserstein distance between two empirical distributions.

Mathematical Formulation The 1D Wasserstein distance of order \(p \ge 1\) between two empirical measures \(\mu = \frac{1}{N}\sum \delta_{x_i}\) and \(\nu = \frac{1}{M}\sum \delta_{y_j}\) is defined as the \(L^p\) distance between their quantile functions \(F^{-1}(t)\) and \(G^{-1}(t)\):

\[ W_p^p(\mu, \nu) = \int_0^1 |F^{-1}(t) - G^{-1}(t)|^p dt \]

When \(N = M\), this reduces to:

\[ W_p^p(\mu, \nu) = \frac{1}{N} \sum_{i=1}^N |x_{(i)} - y_{(i)}|^p \]

where \(x_{(i)}\) and \(y_{(i)}\) are sorted samples. For unequal sample sizes, the integral is solved by integrating the differences of the step functions over partitions of \([0, 1]\).

Implementation Algorithm

  1. Sorts s1 and s2 in-place to form the empirical quantiles.
  2. Iterates through the joint partition of \([0, 1]\) defined by the cumulative weight steps \(i/N\) and \(j/M\).
  3. Integrates the constant difference raised to power \(p\) over each interval.
Parameters
s1The first set of 1D projected samples. (Modified in-place)
s2The second set of 1D projected samples. (Modified in-place)
pThe order of the distance.
Returns
W_p^p, the p-th power of the Wasserstein distance.

◆ write_data()

void cmp::write_data ( const std::vector< Eigen::VectorXd > &  x,
const Eigen::MatrixXd &  y,
std::ofstream &  o_file 
)

Write data points and evaluations to a file.

Mathematical Formulation Serializes input vectors \(\mathbf{x}_i \in \mathbb{R}^D\) along with corresponding multivariate observations \(\mathbf{y}_i \in \mathbb{R}^Q\):

\[ \text{Row}_i = [x_{i,1}, \dots, x_{i,D}, y_{i,1}, \dots, y_{i,Q}] \]

Implementation Algorithm Loops over the vector entries, streaming coordinates of \(\mathbf{x}_i\) followed by the corresponding row coordinates of the matrix \(\mathbf{y}_i\) into o_file.

Parameters
xThe points (as a vector)
yThe data (as a matrix)
o_fileThe output file

◆ write_vector()

void cmp::write_vector ( const std::vector< Eigen::VectorXd > &  data,
std::ofstream &  o_file 
)

Serializes a list of vector coordinates to a file stream.

Mathematical Formulation Serializes a set of vectors \(\{\mathbf{x}_i\}_{i=1}^M\) where \(\mathbf{x}_i \in \mathbb{R}^N\) into a structured grid representation in text format:

\[ \mathbf{x}_i^T = [x_{i,1}, x_{i,2}, \dots, x_{i,N}] \]

Implementation Algorithm Streams each vector to the output file stream o_file line-by-line, separating coordinates with spaces.

Parameters
dataA matrix containing the data.
o_fileAn open and valid file in which to write the contents.

Variable Documentation

◆ ScalarOne

const Eigen::VectorXd cmp::ScalarOne = Eigen::VectorXd::Ones(1)

◆ ScalarZero

const Eigen::VectorXd cmp::ScalarZero = Eigen::VectorXd::Zero(1)

◆ TOL

constexpr double cmp::TOL = 1e-12
inlineconstexpr