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

Manages a clustered set of Gaussian Processes for localized regression. More...

#include <model_cluster.h>

Public Member Functions

 ModelCluster ()=default
 
void set (std::shared_ptr< covariance::Covariance > kernel, std::shared_ptr< mean::Mean > mean, Eigen::VectorXd parameters, double nugget, double gamma, unsigned int seed)
 Configures parameters, kernel, and random seed for the clustered local GP model.
 
void condition (const Eigen::Ref< const Eigen::MatrixXd > &xObs, const Eigen::Ref< const Eigen::VectorXd > &yObs, const Eigen::Ref< const Eigen::VectorXs > &labels)
 Conditions the model on observations and initial cluster labels.
 
std::pair< double, doublepredict (const Eigen::VectorXd &xStar, cmp::classifier::Classifier *classifier) const
 
size_t nClusters () const
 
void fit (Eigen::Ref< const Eigen::VectorXd > lowerBound, Eigen::Ref< const Eigen::VectorXd > upperBound, cmp::gp::method fitType, nlopt::algorithm algorithm=nlopt::LN_SBPLX, double tol=1e-3, std::shared_ptr< cmp::prior::Prior > prior=nullptr, std::vector< bool > logScale={})
 
size_t nPoints () const
 
size_t dim () const
 
size_t getMembership (size_t i) const
 
const Eigen::VectorXsgetLabels () const
 
size_t getClusterSize (size_t i) const
 
cmp::gp::GaussianProcessoperator[] (size_t i)
 
const Eigen::VectorXd & centroid (size_t i) const
 
Eigen::VectorXs getIndices (size_t clusterIndex) const
 
void updateModel (const std::vector< bool > &affectedClusters)
 
bool performSwitches (const std::vector< std::pair< size_t, size_t > > &newOwners, size_t minSize)
 
double computeScore (size_t globalIndex) const
 
double computeScore (size_t clusterIndex, size_t globalIndex) const
 
std::vector< std::pair< size_t, size_t > > switchStep (cmp::classifier::Classifier *classifier, size_t maxAllowedSwitches=10, double minProb=0.1, double T=1.0)
 
std::vector< std::pair< size_t, size_t > > deterministicSwitchStep (cmp::classifier::Classifier *cls, const size_t &maxAllowedSwitches, const double &minProb)
 
void purge (const size_t &clusterIndex)
 
std::vector< std::vector< double > > computeProbabilities (const double &T, cmp::classifier::Classifier *classifier, const double &minProb=0.1) const
 
Eigen::MatrixXd confusionMatrix (std::vector< std::vector< double > > switchingProbability) const
 
void merge (const size_t &clusterIndex1, const size_t &clusterIndex2)
 

Private Attributes

std::default_random_engine rng_
 Pseudo-random number generator.
 
Eigen::MatrixXd xObs_
 Training input matrix of observations.
 
Eigen::VectorXd yObs_
 Training target response vector.
 
size_t nClusters_
 Number of active clusters.
 
size_t nObs_
 Number of training observations.
 
size_t dimX_
 Dimension of input features.
 
Eigen::VectorXs labels_
 Cluster assignments label vector.
 
Eigen::VectorXs localIndexTable_
 Local coordinate lookup index mapping.
 
std::vector< boolfit_
 Cluster fit/convergence status flag vector.
 
std::vector< Eigen::VectorXd > centroids_
 Coordinates for each cluster's centroid.
 
std::vector< cmp::gp::GaussianProcessgps_
 Gaussian process models for each cluster.
 
std::vector< size_tclusterSize_
 Number of points assigned to each cluster.
 
double gamma_ {1.0}
 Regularization blending parameter gamma.
 
std::shared_ptr< covariance::Covariancekernel_
 Covariance kernel function shared across clusters.
 
std::shared_ptr< mean::Meanmean_
 Mean function shared across clusters.
 
Eigen::VectorXd parameters_
 Kernel hyperparameter values.
 
double nugget_ {1e-8}
 Standard noise variance nugget.
 

Detailed Description

Manages a clustered set of Gaussian Processes for localized regression.

$.

For a query point $x^*$, a classifier predicts the probability of cluster membership $P(C = k \mid x^*)$. The blended prediction is given by:

\[ \mu(x^*) = \sum_{k=1}^K P(C = k \mid x^*) \mu_k(x^*) \]

\[ \sigma^2(x^*) = \sum_{k=1}^K P(C = k \mid x^*)^2 \sigma_k^2(x^*) \]

where $\mu_k(x^*)$ and $\sigma_k^2(x^*)$ are the mean and variance predictions of the $k$-th GP.

Switching steps evaluate the change in predictive log-likelihood (LOO error for current cluster, or standard predictive log-likelihood for candidate clusters). The stochastic switching probability for point $i$ to cluster $j$ is computed as:

\[ p_{ij} \propto P(C = j \mid x_i) \exp\left( \frac{\Delta_{ij}}{T} \right) \]

where $\Delta_{ij}$ represents the log-predictive score difference if point $i$ is moved to cluster $j$, and $T$ is the temperature parameter.

Implementation Algorithm

  1. **Initialization (condition)**: Groups the input observations according to their labels, instantiates the GP models, computes initial cluster centroids, and sets up index lookup tables.
  2. **Blended Prediction (predict)**: Obtains probabilities from the classifier, queries predictions from each local GP, and performs the weighted combination.
  3. **Stochastic Switching (switchStep)**: Precomputes probability distributions for all points based on likelihood shifts, filters active points, and samples switches up to maxAllowedSwitches.
  4. **Deterministic Switching (deterministicSwitchStep)**: Calculates the log-likelihood gain for all possible re-assignments, sorts them, and executes the top beneficial moves.
  5. Purging / Merging: Reassigns points from a dissolved cluster to their nearest centroids, shrinks the list of active GPs, and shifts all cluster labels to maintain contiguous indices.

    Mathematical Formulation Let the dataset be composed of $N$ observations $(x_i, y_i) \in \mathbb{R}^d \times \mathbb{R}$. The data is partitioned into $K$ clusters. Each cluster $k \in 1, \ldots, K

Constructor & Destructor Documentation

◆ ModelCluster()

cmp::ModelCluster::ModelCluster ( )
default

Member Function Documentation

◆ centroid()

const Eigen::VectorXd & cmp::ModelCluster::centroid ( size_t  i) const
inline

◆ computeProbabilities()

std::vector< std::vector< double > > cmp::ModelCluster::computeProbabilities ( const double T,
cmp::classifier::Classifier classifier,
const double minProb = 0.1 
) const
inline

◆ computeScore() [1/2]

double cmp::ModelCluster::computeScore ( size_t  clusterIndex,
size_t  globalIndex 
) const
inline

This function computes the score of cluster clusterIndex on the point globalIndex

Parameters
clusterIndexThe index of the cluster
globalIndexThe global index of the point
Returns
The error

◆ computeScore() [2/2]

double cmp::ModelCluster::computeScore ( size_t  globalIndex) const
inline

This function computes the score of the point globalIndex on its current cluster

Parameters
globalIndexThe global index of the point
Returns
The LOO log-predictive contribution of the point under its current cluster assignment.

◆ condition()

void cmp::ModelCluster::condition ( const Eigen::Ref< const Eigen::MatrixXd > &  xObs,
const Eigen::Ref< const Eigen::VectorXd > &  yObs,
const Eigen::Ref< const Eigen::VectorXs > &  labels 
)
inline

Conditions the model on observations and initial cluster labels.

Parameters
xObsObservation point matrix.
yObsResponse vector.
labelsCluster assignments vector.

◆ confusionMatrix()

Eigen::MatrixXd cmp::ModelCluster::confusionMatrix ( std::vector< std::vector< double > >  switchingProbability) const
inline

◆ deterministicSwitchStep()

std::vector< std::pair< size_t, size_t > > cmp::ModelCluster::deterministicSwitchStep ( cmp::classifier::Classifier cls,
const size_t maxAllowedSwitches,
const double minProb 
)
inline

◆ dim()

size_t cmp::ModelCluster::dim ( ) const
inline

◆ fit()

void cmp::ModelCluster::fit ( Eigen::Ref< const Eigen::VectorXd >  lowerBound,
Eigen::Ref< const Eigen::VectorXd >  upperBound,
cmp::gp::method  fitType,
nlopt::algorithm  algorithm = nlopt::LN_SBPLX,
double  tol = 1e-3,
std::shared_ptr< cmp::prior::Prior prior = nullptr,
std::vector< bool logScale = {} 
)
inline

◆ getClusterSize()

size_t cmp::ModelCluster::getClusterSize ( size_t  i) const
inline

◆ getIndices()

Eigen::VectorXs cmp::ModelCluster::getIndices ( size_t  clusterIndex) const
inline

◆ getLabels()

const Eigen::VectorXs & cmp::ModelCluster::getLabels ( ) const
inline

◆ getMembership()

size_t cmp::ModelCluster::getMembership ( size_t  i) const
inline

◆ merge()

void cmp::ModelCluster::merge ( const size_t clusterIndex1,
const size_t clusterIndex2 
)
inline

◆ nClusters()

size_t cmp::ModelCluster::nClusters ( ) const
inline

◆ nPoints()

size_t cmp::ModelCluster::nPoints ( ) const
inline

◆ operator[]()

◆ performSwitches()

bool cmp::ModelCluster::performSwitches ( const std::vector< std::pair< size_t, size_t > > &  newOwners,
size_t  minSize 
)
inline

This function performs the switch of the points

Parameters
newOwnersThe new owners of the points, the first element is the global index and the second element is the owner
minSizeThe minimum size of the clusters

◆ predict()

std::pair< double, double > cmp::ModelCluster::predict ( const Eigen::VectorXd &  xStar,
cmp::classifier::Classifier classifier 
) const
inline

◆ purge()

void cmp::ModelCluster::purge ( const size_t clusterIndex)
inline

This function purges a cluster

Parameters
clusterIndexThe index of the cluster to purge

◆ set()

void cmp::ModelCluster::set ( std::shared_ptr< covariance::Covariance kernel,
std::shared_ptr< mean::Mean mean,
Eigen::VectorXd  parameters,
double  nugget,
double  gamma,
unsigned int  seed 
)
inline

Configures parameters, kernel, and random seed for the clustered local GP model.

Parameters
kernelShared covariance function.
meanShared mean function.
parametersCovariance hyperparameter vector.
nuggetStandard observation noise.
gammaBlending scale/regularization factor.
seedRandom seed.

◆ switchStep()

std::vector< std::pair< size_t, size_t > > cmp::ModelCluster::switchStep ( cmp::classifier::Classifier classifier,
size_t  maxAllowedSwitches = 10,
double  minProb = 0.1,
double  T = 1.0 
)
inline

◆ updateModel()

void cmp::ModelCluster::updateModel ( const std::vector< bool > &  affectedClusters)
inline

Member Data Documentation

◆ centroids_

std::vector<Eigen::VectorXd> cmp::ModelCluster::centroids_
private

Coordinates for each cluster's centroid.

◆ clusterSize_

std::vector<size_t> cmp::ModelCluster::clusterSize_
private

Number of points assigned to each cluster.

◆ dimX_

size_t cmp::ModelCluster::dimX_
private

Dimension of input features.

◆ fit_

std::vector<bool> cmp::ModelCluster::fit_
private

Cluster fit/convergence status flag vector.

◆ gamma_

double cmp::ModelCluster::gamma_ {1.0}
private

Regularization blending parameter gamma.

◆ gps_

std::vector<cmp::gp::GaussianProcess> cmp::ModelCluster::gps_
private

Gaussian process models for each cluster.

◆ kernel_

std::shared_ptr<covariance::Covariance> cmp::ModelCluster::kernel_
private

Covariance kernel function shared across clusters.

◆ labels_

Eigen::VectorXs cmp::ModelCluster::labels_
private

Cluster assignments label vector.

◆ localIndexTable_

Eigen::VectorXs cmp::ModelCluster::localIndexTable_
private

Local coordinate lookup index mapping.

◆ mean_

std::shared_ptr<mean::Mean> cmp::ModelCluster::mean_
private

Mean function shared across clusters.

◆ nClusters_

size_t cmp::ModelCluster::nClusters_
private

Number of active clusters.

◆ nObs_

size_t cmp::ModelCluster::nObs_
private

Number of training observations.

◆ nugget_

double cmp::ModelCluster::nugget_ {1e-8}
private

Standard noise variance nugget.

◆ parameters_

Eigen::VectorXd cmp::ModelCluster::parameters_
private

Kernel hyperparameter values.

◆ rng_

std::default_random_engine cmp::ModelCluster::rng_
private

Pseudo-random number generator.

◆ xObs_

Eigen::MatrixXd cmp::ModelCluster::xObs_
private

Training input matrix of observations.

◆ yObs_

Eigen::VectorXd cmp::ModelCluster::yObs_
private

Training target response vector.


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