29 #include <boost/property_tree/ptree.hpp> 
   31 namespace pt = boost::property_tree;
 
   65   Eigen::VectorXd mu(2);
 
   68   Eigen::MatrixXd cov(2,2);
 
   72   auto targetDensity = std::make_shared<Gaussian>(mu, cov)->AsDensity(); 
 
   77   auto problem = std::make_shared<SamplingProblem>(targetDensity);
 
   97   Eigen::VectorXd propMu = Eigen::VectorXd::Zero(2);
 
  100   Eigen::MatrixXd propCov = (2.4*2.4/std::sqrt(2))*cov;
 
  102   auto propDist = std::make_shared<Gaussian>(propMu, propCov);
 
  108   auto proposal = std::make_shared<MHProposal>(propOpts, problem, propDist);
 
  123   std::vector<std::shared_ptr<TransitionKernel>> kernels(1);
 
  124   kernels.at(0) = std::make_shared<MHKernel>(kernOpts, problem, proposal);
 
  130   chainOpts.put(
"NumSamples", 1e4); 
 
  131   chainOpts.put(
"BurnIn", 1e3);
 
  132   chainOpts.put(
"PrintLevel",3);
 
  134   auto mcmc = std::make_shared<SingleChainMCMC>(chainOpts,kernels);
 
  143   Eigen::VectorXd startPt = mu;
 
  144   std::shared_ptr<SampleCollection> samps = mcmc->Run(startPt);
 
  150   unsigned int numChains = 4;
 
  151   std::vector<std::shared_ptr<SampleCollection>> chains(numChains);
 
  152   chains.at(0) = samps;
 
  154   for(
unsigned int i=1; i<numChains; ++i){
 
  157     mcmc = std::make_shared<SingleChainMCMC>(chainOpts,kernels);    
 
  160     startPt = std::sqrt(1.5) * RandomGenerator::GetNormal(2);
 
  163     chains.at(i) = mcmc->Run(startPt);
 
  175   Eigen::VectorXd rhat = Diagnostics::Rhat(chains);
 
  176   std::cout << 
"\nRhat:\n" << rhat.transpose() << std::endl;
 
  187   Eigen::VectorXd sampMean = samps->Mean();
 
  188   std::cout << 
"\nSample Mean:\n" << sampMean.transpose() << std::endl;
 
  190   Eigen::VectorXd sampVar = samps->Variance();
 
  191   std::cout << 
"\nSample Variance:\n" << sampVar.transpose() << std::endl;
 
  193   Eigen::MatrixXd sampCov = samps->Covariance();
 
  194   std::cout << 
"\nSample Covariance:\n" << sampCov << std::endl;
 
  196   Eigen::VectorXd sampMom3 = samps->CentralMoment(3);
 
  197   std::cout << 
"\nSample Third Moment:\n" << sampMom3.transpose() << std::endl << std::endl;
 
  218   std::cout << 
"Available MetaData: " << std::endl;
 
  219   for(
auto& metaKey : samps->ListMeta())
 
  220     std::cout << 
"  \"" << metaKey << 
"\"" << std::endl;
 
  221   std::cout << std::endl;
 
  224   Eigen::MatrixXd logTargetDens = samps->GetMeta(
"LogTarget");
 
  228   unsigned int maxRow, maxCol;
 
  229   maxLogDens = logTargetDens.maxCoeff(&maxRow, &maxCol);
 
  231   std::cout << 
"From MetaData:" << std::endl;
 
  232   std::cout << 
"  p* = max log(p(x)) = " << maxLogDens << std::endl;
 
  233   std::cout << 
"  x* = argmax p(x) = " << samps->at(maxCol)->state.at(0).transpose() << std::endl;
 
  242   Eigen::MatrixXd sampMat = samps->AsMatrix();
 
  244   std::cout << 
"\nMean using eigen = " << sampMat.rowwise().mean().transpose() << std::endl;