Monte Carlo Integration Library 1.0
High-performance Monte Carlo methods for numerical integration and optimization
mixtureProposal.hpp
Go to the documentation of this file.
1
21#ifndef MONTECARLO_1_MIXTURE_PROPOSAL_HPP
22#define MONTECARLO_1_MIXTURE_PROPOSAL_HPP
23
24#include "proposal.hpp"
25
26#include <vector>
27#include <random>
28#include <stdexcept>
29#include <numeric> // std::accumulate
30#include <cmath> // std::isfinite
31
32namespace mc {
33namespace proposals {
34
35template <size_t dim>
36class MixtureProposal : public Proposal<dim>
37{
38public:
52 MixtureProposal(std::vector<const Proposal<dim>*> components,
53 std::vector<double> weights);
54
56 mc::geom::Point<dim> sample(std::mt19937& rng) const override;
57
59 double pdf(const mc::geom::Point<dim>& x) const override;
60
61 std::size_t numComponents() const noexcept { return comps.size(); }
62 const std::vector<double>& getWeights() const noexcept { return w; }
63
64private:
65 std::vector<const Proposal<dim>*> comps; // non-owning pointers
66 std::vector<double> w; // normalized weights
67
68 mutable std::discrete_distribution<std::size_t> cat;
69
70 static void validateInputs(const std::vector<const Proposal<dim>*>& components,
71 const std::vector<double>& weights);
72 static std::vector<double> normalizeWeights(const std::vector<double>& weights);
73};
74
75} // namespace proposals
76} // namespace mc
77
78#include "mixtureProposal.tpp"
79
80#endif // MONTECARLO_1_MIXTURE_PROPOSAL_HPP
N-dimensional point representation.
Definition geometry.hpp:32
std::size_t numComponents() const noexcept
MixtureProposal(std::vector< const Proposal< dim > * > components, std::vector< double > weights)
Construct a mixture proposal from non-owning component pointers and weights.
mc::geom::Point< dim > sample(std::mt19937 &rng) const override
Sample from the mixture.
double pdf(const mc::geom::Point< dim > &x) const override
Evaluate mixture PDF q(x) = sum_k w_k * q_k(x).
const std::vector< double > & getWeights() const noexcept
Abstract proposal distribution interface.
Definition proposal.hpp:29
Abstract base for probability distributions used in importance sampling.