Represents a single Markov Chain utilizing Delayed Rejection Adaptive Metropolis (DRAM) for sampling.
More...
|
| | MarkovChain (const ProposalType &proposal, std::default_random_engine &rng, const double &targetAcceptanceRatio=0.234) |
| | Construct a new mcmc chain object.
|
| |
| | MarkovChain ()=default |
| |
| | ~MarkovChain ()=default |
| |
| void | increaseSteps () |
| | Increase the number of steps.
|
| |
| bool | accept (const Eigen::Ref< const Eigen::VectorXd > &par, double score) |
| | Accept or reject a candidate.
|
| |
| void | step (const score_t &getScore, const bool &delayedRejection=false, const double &gamma=0.1) |
| | Perform a single MCMC step.
|
| |
| void | update () |
| | Updates the value of the mean and covariance matrix.
|
| |
| Eigen::MatrixXd | getAdaptedCovariance () const |
| | Get a covariance matrix adapted to the samples.
|
| |
| void | reset () |
| |
| Eigen::VectorXd | getCurrent () const |
| | Gets the current parameters of the chain.
|
| |
| double | getScore () const |
| | Gets the current log probability score of the chain.
|
| |
| size_t | getDim () const |
| | Gets the dimensionality of the parameter space.
|
| |
| size_t | getSteps () const |
| | Gets the total number of steps run in this chain.
|
| |
| double | getAcceptanceRatio () const |
| | Gets the current acceptance ratio of proposals.
|
| |
| Eigen::VectorXd | getMean () const |
| | Gets the running mean of the parameter samples.
|
| |
| Eigen::MatrixXd | getCovariance () const |
| | Gets the running covariance of the parameter samples.
|
| |
| void | info () const |
| |
|
| double | score_ {0.0} |
| | Current log probability score value.
|
| |
| size_t | dim_ |
| | Dimension of parameter space.
|
| |
| size_t | nSteps_ {0} |
| | Number of steps taken.
|
| |
| size_t | nAccepts_ {0} |
| | Number of accepted proposals.
|
| |
| Eigen::VectorXd | mean_ |
| | Parameter sample running mean vector.
|
| |
| Eigen::MatrixXd | cov_ |
| | Parameter sample running covariance matrix.
|
| |
| ProposalType | proposal_ |
| | Proposal distribution model (copied by value).
|
| |
| std::uniform_real_distribution< double > | distU_ {0.0, 1.0} |
| | Uniform distribution helper.
|
| |
| std::default_random_engine | rng_ |
| | Random engine.
|
| |
| double | scale_ |
| | Proposal covariance scale parameter.
|
| |
| double | targetAcceptanceRatio_ |
| | Target acceptance ratio for adaptive tuning.
|
| |
template<typename ProposalType>
class cmp::mcmc::MarkovChain< ProposalType >
Represents a single Markov Chain utilizing Delayed Rejection Adaptive Metropolis (DRAM) for sampling.
- Template Parameters
-
| ProposalType | The class type of the proposal distribution used to generate candidate states. |
Mathematical Foundations & DRAM Algorithm
This class implements Delayed Rejection Adaptive Metropolis (DRAM), combining adaptive covariance tuning with multi-stage candidate proposals:
- Stage 1 (Adaptive Metropolis): A candidate state \(\boldsymbol{\theta}^*\) is proposed from a Gaussian distribution centered at the current state \(\boldsymbol{\theta}^{(t)}\) with scaling covariance \(\boldsymbol{\Sigma}_t\):
\[ \boldsymbol{\theta}^* \sim \mathcal{N}\left(\boldsymbol{\theta}^{(t)}, \gamma_1 \boldsymbol{\Sigma}_t\right) \]
The Stage 1 acceptance probability is:
\[ \alpha_1(\boldsymbol{\theta}^{(t)}, \boldsymbol{\theta}^*) = \min\left(1, \frac{\pi(\boldsymbol{\theta}^*)}{\pi(\boldsymbol{\theta}^{(t)})}\right) \]
where \(\pi(\boldsymbol{\theta})\) is the target density.
- Stage 2 (Delayed Rejection): If the Stage 1 proposal is rejected, a Stage 2 candidate \(\boldsymbol{\theta}^{**}\) is drawn from a narrower proposal distribution:
\[ \boldsymbol{\theta}^{**} \sim \mathcal{N}\left(\boldsymbol{\theta}^{(t)}, \gamma_2 \boldsymbol{\Sigma}_t\right) \]
with \(\gamma_2 < \gamma_1\). To preserve detailed balance, the Stage 2 acceptance probability must account for the first-stage rejection:
\[ \alpha_2(\boldsymbol{\theta}^{(t)}, \boldsymbol{\theta}^*, \boldsymbol{\theta}^{**}) = \min\left(1, \frac{\pi(\boldsymbol{\theta}^{**}) q_1(\boldsymbol{\theta}^* | \boldsymbol{\theta}^{**}) [1 - \alpha_1(\boldsymbol{\theta}^{**}, \boldsymbol{\theta}^*)]}{\pi(\boldsymbol{\theta}^{(t)}) q_1(\boldsymbol{\theta}^* | \boldsymbol{\theta}^{(t)}) [1 - \alpha_1(\boldsymbol{\theta}^{(t)}, \boldsymbol{\theta}^*)]}\right) \]
where \(q_1(\mathbf{x} | \mathbf{y})\) is the probability density of proposing \(\mathbf{x}\) given current state \(\mathbf{y}\) under the Stage-1 covariance.
- Adaptive Covariance Scaling: The proposal covariance \(\boldsymbol{\Sigma}_t\) is updated recursively using the sample covariance of the history of the chain:
\[ \boldsymbol{\Sigma}_t = s_d \mathrm{Cov}\left(\boldsymbol{\theta}^{(1)}, \dots, \boldsymbol{\theta}^{(t)}\right) + s_d \epsilon \mathbf{I}_d \]
where \(s_d = \frac{2.4^2}{d}\) is the optimal scaling factor for \(d\)-dimensional Gaussian targets, and \(\epsilon > 0\) is a regularization term.
Implementation Algorithms
Constraints & Invariants
- Detailed Balance: The multi-stage rejection ratio calculation must use log-space subtraction to prevent numerical underflow.
- Positive Definiteness: Regularization nugget \(\epsilon\) must be added to the diagonal of the covariance matrix to guarantee invertibility.