|
Monte Carlo Integration Library 1.0
High-performance Monte Carlo methods for numerical integration and optimization
|
Metropolis-Hastings MCMC sampler for arbitrary target distributions. More...
#include <metropolisHastingsSampler.hpp>
Public Member Functions | |
| MetropolisHastingsSampler (const mc::domains::IntegrationDomain< dim > &d, const std::function< double(const mc::geom::Point< dim > &)> &p, mc::geom::Point< dim > x0, double deviation) | |
| Construct Metropolis-Hastings sampler with target distribution. | |
| mc::geom::Point< dim > | next (std::mt19937 &rng) |
| Generate the next sample from the Markov chain. | |
| double | target_pdf (const mc::geom::Point< dim > &x) |
| Evaluate target probability density at a point. | |
| double | acceptance_rate () const |
| Get the current acceptance rate of the Markov chain. | |
Metropolis-Hastings MCMC sampler for arbitrary target distributions.
| dim | Dimensionality of the sample space. |
Generates a Markov chain of samples asymptotically distributed according to target_pdf(x) using the Metropolis-Hastings algorithm.
Sampling process:
Usage:
Performance tuning:
Definition at line 78 of file metropolisHastingsSampler.hpp.
|
explicit |
Construct Metropolis-Hastings sampler with target distribution.
| d | Integration domain (defines valid region and constraints). |
| p | Target probability density function π(x). Should return 0 outside the domain and positive values inside. Must be finite and > 0 at x0. |
| x0 | Initial point for the Markov chain. Must satisfy domain.isInside(x0). |
| deviation | Standard deviation σ of random walk proposal N(0, σ²). Tune this parameter to achieve ~23.4% acceptance rate. |
| std::invalid_argument | If x0 is outside the domain. |
Initializes sampler state and validates initial conditions. The random walk proposal will use a normal distribution with standard deviation deviation for each dimension.
| double mc::mcmc::MetropolisHastingsSampler< dim >::acceptance_rate | ( | ) | const |
Get the current acceptance rate of the Markov chain.
The acceptance rate indicates chain quality:
Use this metric to tune the deviation parameter for efficiency. Generally aim for 20-40% in practice depending on dimensionality.
| mc::geom::Point< dim > mc::mcmc::MetropolisHastingsSampler< dim >::next | ( | std::mt19937 & | rng | ) |
Generate the next sample from the Markov chain.
| rng | Random number generator (must be seeded externally). |
Implements one iteration of the Metropolis-Hastings algorithm:
Important: The target density p(x) is expected to handle domain constraints by returning 0 outside valid regions (not throwing exceptions).
| std::runtime_error | If π(current) becomes ≤ 0 or non-finite. This indicates the algorithm entered an invalid state. |
| double mc::mcmc::MetropolisHastingsSampler< dim >::target_pdf | ( | const mc::geom::Point< dim > & | x | ) |
Evaluate target probability density at a point.
| x | Query point in the domain. |
Evaluates the target probability density function provided at construction. This is a simple accessor for the internal target.