121 #include <boost/property_tree/ptree.hpp>
123 namespace pt = boost::property_tree;
144 Eigen::VectorXd mu(2);
147 Eigen::MatrixXd cov(2,2);
151 auto targetDensity = std::make_shared<Gaussian>(mu, cov)->AsDensity();
156 auto problem = std::make_shared<SamplingProblem>(targetDensity);
188 pt.put(
"NumSamples", 1e4);
189 pt.put(
"BurnIn", 1e3);
190 pt.put(
"PrintLevel",3);
191 pt.put(
"KernelList",
"Kernel1");
192 pt.put(
"Kernel1.Method",
"MHKernel");
193 pt.put(
"Kernel1.Proposal",
"MyProposal");
194 pt.put(
"Kernel1.MyProposal.Method",
"MHProposal");
195 pt.put(
"Kernel1.MyProposal.ProposalVariance", 2.5);
202 Eigen::VectorXd startPt = mu;
203 auto mcmc = MCMCFactory::CreateSingleChain(pt, problem);
212 std::shared_ptr<SampleCollection> samps = mcmc->Run(startPt);
229 Eigen::VectorXd sampMean = samps->Mean();
230 std::cout <<
"\nSample Mean = \n" << sampMean.transpose() << std::endl;
232 Eigen::VectorXd sampVar = samps->Variance();
233 std::cout <<
"\nSample Variance = \n" << sampVar.transpose() << std::endl;
235 Eigen::MatrixXd sampCov = samps->Covariance();
236 std::cout <<
"\nSample Covariance = \n" << sampCov << std::endl;
238 Eigen::VectorXd sampMom3 = samps->CentralMoment(3);
239 std::cout <<
"\nSample Third Moment = \n" << sampMom3 << std::endl << std::endl;
251 Eigen::VectorXd batchESS = samps->ESS(
"Batch");
252 Eigen::VectorXd batchMCSE = samps->StandardError(
"Batch");
254 Eigen::VectorXd spectralESS = samps->ESS(
"Wolff");
255 Eigen::VectorXd spectralMCSE = samps->StandardError(
"Wolff");
257 std::cout <<
"ESS:\n";
258 std::cout <<
" Batch: " << batchESS.transpose() << std::endl;
259 std::cout <<
" Spectral: " << spectralESS.transpose() << std::endl;
260 std::cout <<
"MCSE:\n";
261 std::cout <<
" Batch: " << batchMCSE.transpose() << std::endl;
262 std::cout <<
" Spectral: " << spectralMCSE.transpose() << std::endl;
276 pt.put(
"PrintLevel",0);
278 std::vector<std::shared_ptr<SampleCollection>> chains(numChains);
279 chains.at(0) = samps;
281 for(
int i=1; i<numChains; ++i){
282 std::cout <<
"Running chain " << i <<
"..." << std::flush;
283 Eigen::VectorXd x0 = startPt + 1.5*RandomGenerator::GetNormal(mu.size());
285 mcmc = MCMCFactory::CreateSingleChain(pt, problem);
286 chains.at(i) = mcmc->Run(x0);
288 std::cout <<
" done" << std::endl;
291 Eigen::VectorXd rhat = Diagnostics::Rhat(chains);
292 std::cout <<
"\nRhat = " << rhat.transpose() << std::endl;