MUQ  0.4.3
MultilevelMonteCarlo.cpp
Go to the documentation of this file.
4 
7 
14 
16 
17 #include <boost/property_tree/ptree.hpp>
18 
19 namespace pt = boost::property_tree;
20 using namespace muq::Modeling;
21 using namespace muq::SamplingAlgorithms;
22 using namespace muq::Utilities;
23 
24 #include "Problem.h"
25 
26 int main(){
27 
28  pt::ptree pt;
29 
30  pt.put("NumSamples", 1e6); // number of samples for single level
31  pt.put("verbosity", 1); // show some output
32  pt.put("NumSamples_0", 1e5);
33  pt.put("NumSamples_1", 1e4);
34  pt.put("NumSamples_2", 1e3);
35  pt.put("NumSamples_3", 1e2);
36 
37  auto componentFactory = std::make_shared<MyMIComponentFactory>(pt);
38 
39 
40  std::cout << std::endl << "*************** multilevel" << std::endl << std::endl;
41 
42  MIMCMC mimcmc(pt, componentFactory);
43  //GreedyMLMCMC greedymlmcmc (pt, componentFactory);
44  mimcmc.Run();
45  std::cout << "mean QOI: " << mimcmc.GetQOIs()->Mean().transpose() << std::endl;
46 
47  //mimcmc.GetBox(std::make_shared<MultiIndex>(1,0));
48  //std::cout << "coarsest: " << mimcmc.GetBox(std::make_shared<MultiIndex>(1,0))->FinestChain()->GetQOIs()->Mean().transpose() << std::endl;
49  auto index_zero = std::make_shared<MultiIndex>(1);
50  index_zero->SetValue(0, 0);
51  std::cout << "coarsest: " << mimcmc.GetBox(index_zero)->FinestChain()->GetQOIs()->Mean().transpose() << std::endl;
52 
53 
54  std::cout << std::endl << "*************** single level" << std::endl << std::endl;
55 
56 {
57  auto index = componentFactory->FinestIndex();
58 
59  auto problem = componentFactory->SamplingProblem(index);
60  auto proposal = componentFactory->Proposal(index, problem);
61 
62  std::vector<std::shared_ptr<TransitionKernel>> kernels(1);
63  kernels[0] = std::make_shared<DummyKernel>(pt,problem,proposal);
64 
65  Eigen::VectorXd startingPoint = componentFactory->StartingPoint(index);
66 
67  auto mcmc = std::make_shared<SingleChainMCMC>(pt,kernels);
68  mcmc->Run(startingPoint);
69  std::cout << "mean QOI: " << mcmc->GetQOIs()->Mean().transpose() << std::endl;
70 }
71 
72  //SLMCMC slmcmc (pt, componentFactory);
73  //slmcmc.Run();
74  //std::cout << "mean QOI: " << slmcmc.MeanQOI().transpose() << std::endl;
75 
76  return 0;
77 }
int main()
Multiindex MCMC method.
Definition: MIMCMC.h:21
std::shared_ptr< MIMCMCBox > GetBox(std::shared_ptr< MultiIndex > index)
Access an MIMCMCBox.
Definition: MIMCMC.cpp:37
virtual std::shared_ptr< MultiIndexEstimator > GetQOIs() const
Definition: MIMCMC.cpp:48
virtual std::shared_ptr< MultiIndexEstimator > Run()
Definition: MIMCMC.cpp:52