19 #include <boost/property_tree/ptree.hpp>
21 namespace pt = boost::property_tree;
29 Eigen::MatrixXd tgtCov(2,2);
33 Eigen::VectorXd tgtMu(2);
37 auto multis = MultiIndexFactory::CreateFullTensor(2,1);
40 std::vector<std::shared_ptr<ModPiece>> models(multis->Size());
41 models.at(0) = std::make_shared<Gaussian>(tgtMu, tgtCov*2.0)->AsDensity();
42 models.at(1) = std::make_shared<Gaussian>(tgtMu, tgtCov*1.3)->AsDensity();
43 models.at(2) = std::make_shared<Gaussian>(tgtMu, tgtCov*1.5)->AsDensity();
44 models.at(3) = std::make_shared<Gaussian>(tgtMu, tgtCov)->AsDensity();
49 pt.put(
"NumSamples", 1e4);
50 pt.put(
"NumSamples_0_0", 1e5);
51 pt.put(
"NumSamples_0_1", 1e5);
52 pt.put(
"NumSamples_0_2", 1e4);
53 pt.put(
"NumSamples_1_0", 1e5);
54 pt.put(
"NumSamples_1_1", 1e4);
55 pt.put(
"NumSamples_1_2", 1e3);
56 pt.put(
"NumSamples_2_0", 1e4);
57 pt.put(
"NumSamples_2_1", 1e3);
58 pt.put(
"NumSamples_2_2", 1e3);
59 pt.put(
"MLMCMC.Subsampling_0_0", 5);
60 pt.put(
"MLMCMC.Subsampling_0_1", 5);
61 pt.put(
"MLMCMC.Subsampling_0_2", 5);
62 pt.put(
"MLMCMC.Subsampling_1_0", 5);
63 pt.put(
"MLMCMC.Subsampling_1_1", 5);
64 pt.put(
"MLMCMC.Subsampling_1_2", 5);
65 pt.put(
"MLMCMC.Subsampling_2_0", 5);
66 pt.put(
"MLMCMC.Subsampling_2_1", 5);
67 pt.put(
"MLMCMC.Subsampling_2_2", 5);
69 pt.put(
"Proposal.Method",
"MHProposal");
70 pt.put(
"Proposal.ProposalVariance", 16.0);
72 unsigned int numChains = 5;
73 std::vector<std::shared_ptr<MultiIndexEstimator>> estimators(numChains);
75 for(
int chainInd=0; chainInd<numChains; ++chainInd){
76 Eigen::VectorXd x0 = RandomGenerator::GetNormal(2);
78 std::cout <<
"\n=============================\n";
79 std::cout <<
"Running MIMCMC Chain " << chainInd <<
": \n";
80 std::cout <<
"-----------------------------\n";
82 MIMCMC mimcmc (pt, x0, models, multis);
83 estimators.at(chainInd) = mimcmc.
Run();
85 std::cout <<
"mean QOI: " << estimators.at(chainInd)->Mean().transpose() << std::endl;
87 std::stringstream filename;
88 filename <<
"MultilevelGaussianSampling_Chain" << chainInd <<
".h5";
92 std::cout <<
"\n=============================\n";
93 std::cout <<
"Multilevel Summary: \n";
94 std::cout <<
"-----------------------------\n";
95 std::cout <<
" Rhat: " << Diagnostics::Rhat(estimators).transpose() << std::endl;
96 std::cout <<
" Mean (chain 0): " << estimators.at(0)->Mean().transpose() << std::endl;
97 std::cout <<
" MCSE (chain 0): " << estimators.at(0)->StandardError().transpose() << std::endl;
98 std::cout <<
" ESS (chain 0): " << estimators.at(0)->ESS().transpose() << std::endl;
99 std::cout <<
" Variance (chain 0): " << estimators.at(0)->Variance().transpose() << std::endl;
100 std::cout << std::endl;
virtual std::shared_ptr< MultiIndexEstimator > Run()
void WriteToFile(std::string filename)
Write HDF5 output for the entire MIMCMC method.