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

Implements an Evolutionary Markov Chain Monte Carlo sampler. More...

#include <mcmc.h>

Public Member Functions

 EvolutionaryMarkovChain ()=default
 
 EvolutionaryMarkovChain (std::vector< Eigen::VectorXd > initialSamples, std::vector< double > initialScores, double nugget=1e-6)
 Constructs an EvolutionaryMarkovChain sampler.
 
void step (const score_t &getScore, std::default_random_engine &rng, double gamma=0.2)
 Performs one crossover and mutation step for all chains.
 
std::vector< Eigen::VectorXd > getCurrent () const
 Gets the current states of all chains.
 
std::vector< double > getScores () const
 Gets the current log probability scores of all chains.
 

Protected Attributes

size_t nChains_ {0}
 Number of active parallel chains.
 
size_t dim_ {0}
 Dimension of the parameter space.
 
std::vector< Eigen::VectorXd > chainSamples_
 Current parameter samples for each chain.
 
std::vector< double > chainScores_
 Current score (log probability) for each chain.
 
std::uniform_int_distribution< size_t > distChain_
 Discrete uniform distribution helper to pick random chain.
 
std::uniform_real_distribution< double > distU_ {0, 1}
 Uniform distribution helper.
 
std::normal_distribution< double > distN_ {0, 1}
 Normal distribution helper.
 
double nugget_ {1e-6}
 Crossover mutation noise scaling.
 

Detailed Description

Implements an Evolutionary Markov Chain Monte Carlo sampler.

Mathematical Formulation Uses differential evolution crossover proposals. For each chain \(i\), candidate states \(\boldsymbol{\theta}_i^*\) are generated using states from two other distinct, randomly selected chains \(j\) and \(k\):

\[ \boldsymbol{\theta}_i^* = \boldsymbol{\theta}_i + \gamma (\boldsymbol{\theta}_j - \boldsymbol{\theta}_k) + \mathbf{e} \]

where \(\gamma\) is the scale factor and \(\mathbf{e} \sim \mathcal{N}(\mathbf{0}, \sigma_e^2 \mathbf{I})\) represents small mutation noise. The candidate state is accepted according to the Metropolis-Hastings probability:

\[ \alpha = \min\left(1, \exp\left(\log \pi(\boldsymbol{\theta}_i^*) - \log \pi(\boldsymbol{\theta}_i)\right)\right) \]

Implementation Algorithm

  1. For each chain \(i\), randomly selects distinct partner chains \(j\) and \(k\).
  2. Evaluates mutated crossover states.
  3. Applies Metropolis-Hastings rejection step based on the likelihood evaluations.

Constructor & Destructor Documentation

◆ EvolutionaryMarkovChain() [1/2]

cmp::mcmc::EvolutionaryMarkovChain::EvolutionaryMarkovChain ( )
default

◆ EvolutionaryMarkovChain() [2/2]

cmp::mcmc::EvolutionaryMarkovChain::EvolutionaryMarkovChain ( std::vector< Eigen::VectorXd >  initialSamples,
std::vector< double >  initialScores,
double  nugget = 1e-6 
)

Constructs an EvolutionaryMarkovChain sampler.

Parameters
initialSamplesInitial parameter states for each chain.
initialScoresInitial log probability scores for each chain.
nuggetStandard deviation scaling for crossover mutation noise.

Member Function Documentation

◆ getCurrent()

std::vector< Eigen::VectorXd > cmp::mcmc::EvolutionaryMarkovChain::getCurrent ( ) const
inline

Gets the current states of all chains.

Returns
Vector of chain samples.

◆ getScores()

std::vector< double > cmp::mcmc::EvolutionaryMarkovChain::getScores ( ) const
inline

Gets the current log probability scores of all chains.

Returns
Vector of chain scores.

◆ step()

void cmp::mcmc::EvolutionaryMarkovChain::step ( const score_t getScore,
std::default_random_engine &  rng,
double  gamma = 0.2 
)

Performs one crossover and mutation step for all chains.

Parameters
getScoreThe log posterior probability evaluator.
rngRandom number engine.
gammaScale factor for difference vector in differential evolution.

Member Data Documentation

◆ chainSamples_

std::vector<Eigen::VectorXd> cmp::mcmc::EvolutionaryMarkovChain::chainSamples_
protected

Current parameter samples for each chain.

◆ chainScores_

std::vector<double> cmp::mcmc::EvolutionaryMarkovChain::chainScores_
protected

Current score (log probability) for each chain.

◆ dim_

size_t cmp::mcmc::EvolutionaryMarkovChain::dim_ {0}
protected

Dimension of the parameter space.

◆ distChain_

std::uniform_int_distribution<size_t> cmp::mcmc::EvolutionaryMarkovChain::distChain_
protected

Discrete uniform distribution helper to pick random chain.

◆ distN_

std::normal_distribution<double> cmp::mcmc::EvolutionaryMarkovChain::distN_ {0, 1}
protected

Normal distribution helper.

◆ distU_

std::uniform_real_distribution<double> cmp::mcmc::EvolutionaryMarkovChain::distU_ {0, 1}
protected

Uniform distribution helper.

◆ nChains_

size_t cmp::mcmc::EvolutionaryMarkovChain::nChains_ {0}
protected

Number of active parallel chains.

◆ nugget_

double cmp::mcmc::EvolutionaryMarkovChain::nugget_ {1e-6}
protected

Crossover mutation noise scaling.


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