MUQ  0.4.3
DefaultComponentFactory.cpp
Go to the documentation of this file.
4 
6 
7 #include <boost/property_tree/ptree.hpp>
8 
9 using namespace muq::SamplingAlgorithms;
10 using namespace muq::Utilities;
11 
12 DefaultComponentFactory::DefaultComponentFactory(boost::property_tree::ptree pt,
13  Eigen::VectorXd startingPoint,
14  std::vector<std::shared_ptr<AbstractSamplingProblem>> const& problemsIn)
15  : DefaultComponentFactory(pt, startingPoint, MultiIndexFactory::CreateFullTensor(1,problemsIn.size() - 1), problemsIn)
16 {
17 
18 }
19 
20 DefaultComponentFactory::DefaultComponentFactory(boost::property_tree::ptree optionsIn,
21  Eigen::VectorXd startingPointIn,
22  std::shared_ptr<MultiIndexSet> const& problemIndicesIn,
23  std::vector<std::shared_ptr<AbstractSamplingProblem>> const& problemsIn)
24  : options(optionsIn),
25  startingPoint(startingPointIn),
26  problemIndices(problemIndicesIn),
27  problems(problemsIn)
28  {
29  }
30 
31 
32 std::shared_ptr<MCMCProposal> DefaultComponentFactory::Proposal(std::shared_ptr<MultiIndex> const& index,
33  std::shared_ptr<AbstractSamplingProblem> const& problem)
34 {
35 
36  boost::property_tree::ptree subTree = options.get_child("Proposal");
37  subTree.put("BlockIndex",0);
38 
39  // Construct the proposal
40  std::shared_ptr<MCMCProposal> proposal = MCMCProposal::Construct(subTree, problem);
41  assert(proposal);
42  return proposal;
43 }
44 
45 std::shared_ptr<MultiIndex> DefaultComponentFactory::FinestIndex()
46 {
47  return std::make_shared<MultiIndex>(problemIndices->GetMaxOrders());
48 }
49 
50 std::shared_ptr<MCMCProposal> DefaultComponentFactory::CoarseProposal (std::shared_ptr<MultiIndex> const& fineIndex,
51  std::shared_ptr<MultiIndex> const& coarseIndex,
52  std::shared_ptr<AbstractSamplingProblem> const& coarseProblem,
53  std::shared_ptr<SingleChainMCMC> const& coarseChain)
54 {
55  boost::property_tree::ptree ptProposal = options;
56  ptProposal.put("BlockIndex",0);
57  return std::make_shared<SubsamplingMIProposal>(ptProposal, coarseProblem, coarseIndex, coarseChain);
58 }
59 
60 std::shared_ptr<AbstractSamplingProblem> DefaultComponentFactory::SamplingProblem (std::shared_ptr<MultiIndex> const& index)
61 {
62  for(int i = 0; i < problemIndices->Size(); i++) {
63  if (*(problemIndices->at(i)) == *index)
64  return problems.at(i);
65  }
66 
67  std::cout << "Undefined problem! " << *index << std::endl;
68  assert(false);
69  return nullptr;
70 }
71 
72 std::shared_ptr<MIInterpolation> DefaultComponentFactory::Interpolation (std::shared_ptr<MultiIndex> const& index)
73 {
74  return std::make_shared<ConcatenatingInterpolation>(index);
75 }
76 
77 Eigen::VectorXd DefaultComponentFactory::StartingPoint (std::shared_ptr<MultiIndex> const& index)
78 {
79  return startingPoint;
80 }
Provides a high level interface for the sampling problems on each MIMCMC level.
virtual Eigen::VectorXd StartingPoint(std::shared_ptr< MultiIndex > const &index) override
std::vector< std::shared_ptr< AbstractSamplingProblem > > problems
virtual std::shared_ptr< AbstractSamplingProblem > SamplingProblem(std::shared_ptr< MultiIndex > const &index) override
virtual std::shared_ptr< MCMCProposal > CoarseProposal(std::shared_ptr< MultiIndex > const &fineIndex, std::shared_ptr< MultiIndex > const &coarseIndex, std::shared_ptr< AbstractSamplingProblem > const &coarseProblem, std::shared_ptr< SingleChainMCMC > const &coarseChain) override
DefaultComponentFactory(boost::property_tree::ptree options, Eigen::VectorXd startingPoint, std::vector< std::shared_ptr< AbstractSamplingProblem >> const &problems)
virtual std::shared_ptr< MIInterpolation > Interpolation(std::shared_ptr< MultiIndex > const &index) override
virtual std::shared_ptr< MultiIndex > FinestIndex() override
virtual std::shared_ptr< MCMCProposal > Proposal(std::shared_ptr< MultiIndex > const &index, std::shared_ptr< AbstractSamplingProblem > const &samplingProblem) override
static std::shared_ptr< MCMCProposal > Construct(boost::property_tree::ptree const &pt, std::shared_ptr< AbstractSamplingProblem > const &probIn)
Static constructor for the transition kernel.
A factory class with static methods for generating MultiIndexSets.