MUQ  0.4.3
IndependenceProposal.cpp
Go to the documentation of this file.
2 
4 
6 
7 namespace pt = boost::property_tree;
8 using namespace muq::Modeling;
9 using namespace muq::SamplingAlgorithms;
10 using namespace muq::Utilities;
11 
13 
14 IndependenceProposal::IndependenceProposal(pt::ptree const& pt,
15  std::shared_ptr<AbstractSamplingProblem> const& prob) : IndependenceProposal(pt,prob, ExtractDistribution(pt, prob))
16 {}
17 
18 IndependenceProposal::IndependenceProposal(pt::ptree const& pt,
19  std::shared_ptr<AbstractSamplingProblem> const& prob,
20  std::shared_ptr<Distribution> dist) : MCMCProposal(pt,prob),
21  proposal(dist)
22 {
23 }
24 
25 std::shared_ptr<Distribution> IndependenceProposal::ExtractDistribution(pt::ptree const& opts,
26  std::shared_ptr<AbstractSamplingProblem> const& prob)
27 {
28 
29  Eigen::VectorXd mu = Eigen::VectorXd::Zero(prob->blockSizes(opts.get("BlockIndex",0)));
30  Eigen::VectorXd var = opts.get("ProposalVariance", 1.0)*Eigen::VectorXd::Ones(mu.size());
31 
32  return std::make_shared<Gaussian>(mu,var);
33 }
34 
35 std::shared_ptr<SamplingState> IndependenceProposal::Sample(std::shared_ptr<SamplingState> const& currentState) {
36  assert(currentState->state.size()>blockInd);
37 
38  // the mean of the proposal is the current point
39  std::vector<Eigen::VectorXd> props = currentState->state;
40  assert(props.size()>blockInd);
41 
42  Eigen::VectorXd prop = proposal->Sample();
43  props.at(blockInd) = prop;
44 
45  // store the new state in the output
46  return std::make_shared<SamplingState>(props, 1.0);
47 }
48 
49 double IndependenceProposal::LogDensity(std::shared_ptr<SamplingState> const& currState,
50  std::shared_ptr<SamplingState> const& propState)
51 {
52  proposal->LogDensity(propState->state.at(blockInd));
53  return proposal->LogDensity(propState->state.at(blockInd));
54 }
REGISTER_MCMC_PROPOSAL(IndependenceProposal) IndependenceProposal
Implementation of an independence proposal with arbitrary distribution.
virtual std::shared_ptr< SamplingState > Sample(std::shared_ptr< SamplingState > const &currentState) override
virtual double LogDensity(std::shared_ptr< SamplingState > const &currState, std::shared_ptr< SamplingState > const &propState) override
std::shared_ptr< muq::Modeling::Distribution > proposal
The proposal distribution.
std::shared_ptr< AbstractSamplingProblem > prob
Definition: MCMCProposal.h:81