|
CMP++: Uncertainty Quantification & Bayesian Calibration
|
Implements an infinite Gaussian Mixture Model using a Dirichlet Process Mixture Model (DPMM) and Gibbs sampling. More...
#include <cluster.h>

Classes | |
| struct | Cluster |
Public Member Functions | |
| DirichletProcessMixtureModel (double alpha, const cmp::distribution::GammaDistribution &alphaPrior, const cmp::distribution::NormalInverseWishartDistribution &hyper, unsigned int seed=12345) | |
| Constructs a new DirichletProcessMixtureModel object. | |
| void | condition (const Eigen::Ref< const Eigen::MatrixXd > &data, const Eigen::VectorXs &init_labels) |
| Conditions the DPMM model on the given dataset with initial cluster labels. | |
| void | step () |
| Performs one complete sweep of collapsed Gibbs sampling over all points. | |
| void | remapLabels () |
| Remaps cluster labels to be contiguous integers starting from 0. | |
| Eigen::VectorXs | getLabels () const |
| Gets the current cluster label assignments vector. | |
| size_t | nClusters () const |
| Gets the current number of active clusters. | |
| double | getAlpha () const |
| Gets the current concentration parameter alpha. | |
Private Member Functions | |
| void | init (const Eigen::VectorXs &init_labels) |
| Initializes cluster counts, sums, and sufficient statistics. | |
| void | removePointFromCluster (const size_t &pointIndex, const size_t &clusterID) |
| Removes a point from the sufficient statistics of a specified cluster. | |
| void | addPointToCluster (const size_t &pointIndex, const size_t &clusterID) |
| Adds a point to the sufficient statistics of a specified cluster. | |
| double | logNIWPosterior (const Eigen::VectorXd &x, const Cluster &c) const |
| Computes the log posterior probability of a point under a cluster's NIW predictive distribution. | |
| void | updateAlpha () |
| Updates the concentration parameter alpha via auxiliary variable sampling. | |
Private Attributes | |
| std::vector< double > | logp_workspace_ |
| Temporary buffer for cluster log-probabilities. | |
| std::vector< double > | probs_workspace_ |
| Temporary buffer for cluster probability weights. | |
| std::vector< size_t > | clusterIDs_workspace_ |
| Temporary buffer for cluster IDs. | |
| Eigen::MatrixXd | xObs_ |
| Observed data points matrix (N x D). | |
| Eigen::VectorXs | labels_ |
| Current cluster assignment label vector. | |
| size_t | nPoints_ {0} |
| Number of observation points. | |
| int | dim_ {0} |
| Dimensionality of the feature space. | |
| std::vector< size_t > | clusterIDs_ |
| List of active cluster IDs. | |
| cmp::distribution::NormalInverseWishartDistribution | hyper_ |
| Hyperprior distribution parameters for clusters. | |
| cmp::distribution::GammaDistribution | alphaPrior_ |
| Prior distribution parameters for concentration parameter. | |
| double | alpha_ {1.0} |
| Concentration parameter alpha for the Dirichlet Process. | |
| std::map< size_t, Cluster > | clusters_ |
| Map from cluster ID to sufficient statistics cluster structure. | |
| size_t | nextClusterId_ |
| Counter to generate unique new cluster IDs. | |
| std::default_random_engine | rng_ |
| Pseudo-random number generator engine. | |
| std::uniform_real_distribution< double > | distU_ {0.0, 1.0} |
| Uniform real generator for rejection sampler. | |
Implements an infinite Gaussian Mixture Model using a Dirichlet Process Mixture Model (DPMM) and Gibbs sampling.
The Dirichlet Process Mixture Model (DPMM) assumes an infinite number of mixture components, allowing the model to adaptively determine the number of clusters from the data. The generative process for observations \(\mathbf{x}_i \in \mathbb{R}^d\) is:
\[ \mathbf{x}_i | z_i, \{\boldsymbol{\mu}_k, \boldsymbol{\Sigma}_k\} \sim \mathcal{N}(\boldsymbol{\mu}_{z_i}, \boldsymbol{\Sigma}_{z_i}) \]
\[ z_i | \mathbf{w} \sim \mathrm{Categorical}(\mathbf{w}) \]
\[ \mathbf{w} \sim \mathrm{GEM}(\alpha) \quad \text{(Stick-breaking construction)} \]
\[ (\boldsymbol{\mu}_k, \boldsymbol{\Sigma}_k) \sim \mathrm{NIW}(\boldsymbol{\mu}_0, \kappa_0, \boldsymbol{\Lambda}_0, \nu_0) \]
where \(\mathrm{NIW}\) is the Normal-Inverse-Wishart conjugate prior, and \(\alpha > 0\) is the concentration parameter.
The NIW prior is defined as:
\[ \boldsymbol{\Sigma} \sim \mathrm{Inv-Wishart}(\boldsymbol{\Lambda}_0, \nu_0), \quad \boldsymbol{\mu} | \boldsymbol{\Sigma} \sim \mathcal{N}\left(\boldsymbol{\mu}_0, \frac{1}{\kappa_0} \boldsymbol{\Sigma}\right) \]
The algorithm integrates out the parameters \(\{\boldsymbol{\mu}_k, \boldsymbol{\Sigma}_k\}\), sampling only the cluster indicators \(z_i\):
\[ P(z_i = k | \mathbf{z}_{-i}, \mathbf{x}_i) \propto n_k^{-i} \cdot t_{\nu_n}\left(\mathbf{x}_i ; \boldsymbol{\mu}_n, \frac{\kappa_n + 1}{\kappa_n(\nu_n - d + 1)} \boldsymbol{\Lambda}_n\right) \]
where \(n_k^{-i}\) is the cluster size excluding \(\mathbf{x}_i\), and \(t_{\nu}\) is the multivariate Student-t distribution representing the posterior predictive distribution.\[ P(z_i = \text{new} | \mathbf{z}_{-i}, \mathbf{x}_i) \propto \alpha \cdot t_{\nu_0}\left(\mathbf{x}_i ; \boldsymbol{\mu}_0, \frac{\kappa_0 + 1}{\kappa_0(\nu_0 - d + 1)} \boldsymbol{\Lambda}_0\right) \]
\[ \kappa_n = \kappa_0 + n_k, \quad \nu_n = \nu_0 + n_k, \quad \boldsymbol{\mu}_n = \frac{\kappa_0 \boldsymbol{\mu}_0 + n_k \bar{\mathbf{x}}}{\kappa_n} \]
\[ \boldsymbol{\Lambda}_n = \boldsymbol{\Lambda}_0 + \mathbf{C} + \frac{\kappa_0 n_k}{\kappa_n} (\bar{\mathbf{x}} - \boldsymbol{\mu}_0)(\bar{\mathbf{x}} - \boldsymbol{\mu}_0)^T \]
where \(\bar{\mathbf{x}}\) is the sample mean, and \(\mathbf{C} = \sum_{j \in \text{cluster}} (\mathbf{x}_j - \bar{\mathbf{x}})(\mathbf{x}_j - \bar{\mathbf{x}})^T\).| cmp::cluster::DirichletProcessMixtureModel::DirichletProcessMixtureModel | ( | double | alpha, |
| const cmp::distribution::GammaDistribution & | alphaPrior, | ||
| const cmp::distribution::NormalInverseWishartDistribution & | hyper, | ||
| unsigned int | seed = 12345 |
||
| ) |
Constructs a new DirichletProcessMixtureModel object.
| alpha | Initial concentration parameter for the Dirichlet Process. |
| alphaPrior | Gamma prior distribution parameters for concentration updates. |
| hyper | Normal-Inverse-Wishart hyperprior parameters for clusters. |
| seed | Seed value for the random number generator. |
|
private |
Adds a point to the sufficient statistics of a specified cluster.
| pointIndex | Index of the data point. |
| clusterID | ID of the cluster. |
| void cmp::cluster::DirichletProcessMixtureModel::condition | ( | const Eigen::Ref< const Eigen::MatrixXd > & | data, |
| const Eigen::VectorXs & | init_labels | ||
| ) |
Conditions the DPMM model on the given dataset with initial cluster labels.
| data | N x D matrix of observed points. |
| init_labels | Initial cluster assignment vector of size N. |
|
inline |
Gets the current concentration parameter alpha.
|
inline |
Gets the current cluster label assignments vector.
|
private |
Initializes cluster counts, sums, and sufficient statistics.
| init_labels | Initial cluster labels. |
|
private |
Computes the log posterior probability of a point under a cluster's NIW predictive distribution.
| x | The point vector. |
| c | The cluster structure. |
|
inline |
Gets the current number of active clusters.
| void cmp::cluster::DirichletProcessMixtureModel::remapLabels | ( | ) |
Remaps cluster labels to be contiguous integers starting from 0.
|
private |
Removes a point from the sufficient statistics of a specified cluster.
| pointIndex | Index of the data point. |
| clusterID | ID of the cluster. |
| void cmp::cluster::DirichletProcessMixtureModel::step | ( | ) |
Performs one complete sweep of collapsed Gibbs sampling over all points.
|
inlineprivate |
Updates the concentration parameter alpha via auxiliary variable sampling.
|
private |
Concentration parameter alpha for the Dirichlet Process.
|
private |
Prior distribution parameters for concentration parameter.
|
private |
List of active cluster IDs.
|
private |
Temporary buffer for cluster IDs.
|
private |
Map from cluster ID to sufficient statistics cluster structure.
|
private |
Dimensionality of the feature space.
|
private |
Uniform real generator for rejection sampler.
|
private |
Hyperprior distribution parameters for clusters.
|
private |
Current cluster assignment label vector.
|
private |
Temporary buffer for cluster log-probabilities.
|
private |
Counter to generate unique new cluster IDs.
|
private |
Number of observation points.
|
private |
Temporary buffer for cluster probability weights.
|
private |
Pseudo-random number generator engine.
|
private |
Observed data points matrix (N x D).