Monte Carlo Integration Library 1.0
High-performance Monte Carlo methods for numerical integration and optimization
metropolisHastingsSampler.hpp
Go to the documentation of this file.
1
33#ifndef MONTECARLO_DGL_METROPOLISHASTINGSSAMPLER_HPP
34#define MONTECARLO_DGL_METROPOLISHASTINGSSAMPLER_HPP
35
36#include "../domains/integration_domain.hpp"
37#include "../geometry.hpp"
38
39#include <array>
40#include <random>
41#include <utility>
42#include <functional>
43
44namespace mc{
45namespace mcmc{
46
47
77template <size_t dim>
79{
80public:
96 const std::function<double(const mc::geom::Point<dim>&)>& p,
98 double deviation);
99
121 mc::geom::Point<dim> next(std::mt19937& rng);
122
134
151 double acceptance_rate() const;
152
153private:
155
156 std::function<double(const mc::geom::Point<dim>&)> target;
157
158 mc::geom::Point<dim> current;
159
160 std::size_t n_steps = 0;
161 std::size_t n_accept = 0;
162
163 std::normal_distribution<double> rw_normal;
164 std::uniform_real_distribution<double> uni;
165};
166
167} //namespace mcmc
168} //namespace mc
169
171
172#endif //MONTECARLO_DGL_METROPOLISHASTINGSSAMPLER_HPP
Abstract base class for N-dimensional integration domains.
N-dimensional point representation.
Definition geometry.hpp:32
Metropolis-Hastings MCMC sampler for arbitrary target distributions.
double target_pdf(const mc::geom::Point< dim > &x)
Evaluate target probability density at a point.
mc::geom::Point< dim > next(std::mt19937 &rng)
Generate the next sample from the Markov chain.
double acceptance_rate() const
Get the current acceptance rate of the Markov chain.
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.