MUQ  0.4.3
MultilevelMCMC_FLowModel.cpp
Go to the documentation of this file.
1 #include <iostream>
2 
4 
5 #include "FlowModelComponents.h"
6 
7 namespace pt = boost::property_tree;
8 using namespace muq::Modeling;
9 using namespace muq::SamplingAlgorithms;
10 
11 int main() {
12  const std::size_t numLevels = 2;
13  const std::size_t baseRefinement = 25; // The number of cells in the coarsest model
14  std::vector<std::shared_ptr<ModPiece> > logDensities = ConstructDensities(numLevels, baseRefinement);
15 
16  pt::ptree options;
17 
18  options.put("NumInitialSamples", 1000); // number of initial samples for greedy MLMCMC
19  options.put("GreedyTargetVariance", 0.05); // Target estimator variance to be achieved by greedy algorithm
20  options.put("verbosity", 1); // show some output
21  options.put("MLMCMC.Subsampling_0", 8);
22  options.put("MLMCMC.Subsampling_1", 4);
23  options.put("MLMCMC.Subsampling_2", 2);
24  options.put("MLMCMC.Subsampling_3", 0);
25 
26  options.put("Proposal.Method", "MHProposal");
27  options.put("Proposal.ProposalVariance", 1.0);
28 
29  Eigen::VectorXd theta0 = Eigen::VectorXd::Zero(logDensities[0]->inputSizes(0));
30  GreedyMLMCMC sampler(options, theta0, logDensities);
31 
32  std::shared_ptr<MultiIndexEstimator> estimator = sampler.Run();
33 
34  std::cout << "Mean: " << estimator->Mean().transpose() << std::endl;
35  std::cout << "Variance: " << estimator->Variance().transpose() << std::endl;
36 
37  const std::string filename = "output.h5";
38  sampler.WriteToFile(filename);
39 
40  /*// Define the mesh
41  unsigned int numCells = 100;
42  Discretization mesh(numCells);
43 
44  // Generate synthetic "truth" data
45  unsigned int obsThin = 10;
46  double obsVar = 0.01*0.01;
47  auto data = GenerateData(mesh, obsThin, obsVar);
48 
49  auto posterior = DefinePosterior(mesh, data, obsThin, obsVar);
50 
51  // Using the "truth" as a starting point for MCMC
52  Eigen::VectorXd startPt = GetTrueLogConductivity(mesh);*/
53 }
std::vector< std::shared_ptr< ModPiece > > ConstructDensities()
Greedy Multilevel MCMC method.
Definition: GreedyMLMCMC.h:24
void WriteToFile(std::string filename)
virtual std::shared_ptr< MultiIndexEstimator > Run()