7 namespace pt = boost::property_tree;
15 MixtureProposal::MixtureProposal(boost::property_tree::ptree pt,
16 std::shared_ptr<AbstractSamplingProblem>
const& prob) :
MixtureProposal(pt,
18 GetProposals(pt,prob),
23 MixtureProposal::MixtureProposal(boost::property_tree::ptree pt,
24 std::shared_ptr<AbstractSamplingProblem>
const& prob,
25 std::vector<std::shared_ptr<MCMCProposal>>
const& proposalsIn,
26 std::vector<double>
const& weightsIn) :
MCMCProposal(pt,prob),
27 proposals(proposalsIn),
37 for(
int i=0; i<
weights.size(); ++i){
41 for(
int i=0; i<
weights.size();++i)
47 std::shared_ptr<AbstractSamplingProblem>
const& prob)
50 assert(propStrings.size()>0);
52 std::vector<std::shared_ptr<MCMCProposal>> props(propStrings.size());
54 for(
int i=0; i<props.size(); ++i){
55 boost::property_tree::ptree subTree = pt.get_child(propStrings.at(i));
56 subTree.put(
"BlockIndex", pt.get(
"BlockIndex",0));
68 if(wtStrings.size()==0){
69 return std::vector<double>();
73 std::vector<double>
weights(wtStrings.size());
76 for(
int i=0; i<
weights.size(); ++i)
77 weights.at(i) = std::stof(wtStrings.at(i));
88 int randInd = RandomGenerator::GetDiscrete(
weights);
91 return proposals.at(randInd)->Sample(currentState);
95 std::shared_ptr<SamplingState>
const& propState)
99 density +=
weights.at(i) * std::exp(
proposals.at(i)->LogDensity(currState, propState));
101 return std::log(density);
REGISTER_MCMC_PROPOSAL(MixtureProposal) MixtureProposal
std::shared_ptr< AbstractSamplingProblem > prob
static std::shared_ptr< MCMCProposal > Construct(boost::property_tree::ptree const &pt, std::shared_ptr< AbstractSamplingProblem > const &probIn)
Static constructor for the transition kernel.
This class implements a weighted mixture of other proposals.
virtual double LogDensity(std::shared_ptr< SamplingState > const &currState, std::shared_ptr< SamplingState > const &propState) override
static std::vector< std::shared_ptr< MCMCProposal > > GetProposals(boost::property_tree::ptree const &pt, std::shared_ptr< AbstractSamplingProblem > const &prob)
std::vector< double > weights
static std::vector< double > GetWeights(boost::property_tree::ptree const &pt)
std::vector< std::shared_ptr< MCMCProposal > > proposals
The proposal distribution.
virtual std::shared_ptr< SamplingState > Sample(std::shared_ptr< SamplingState > const ¤tState) override
std::vector< std::string > Split(std::string str, char delim=',')
Split a string into parts based on a particular character delimiter. Also Strips whitespace from part...