11 #include <boost/property_tree/ptree.hpp>
13 namespace pt = boost::property_tree;
26 virtual ~MySamplingProblem() =
default;
29 virtual double LogDensity(std::shared_ptr<SamplingState>
const& state)
override {
34 virtual std::shared_ptr<SamplingState>
QOI()
override {
35 assert (lastState !=
nullptr);
36 return std::make_shared<SamplingState>(lastState->state[0] * 2, 1.0);
40 std::shared_ptr<SamplingState> lastState =
nullptr;
60 Eigen::VectorXd mu(2);
63 Eigen::MatrixXd cov(2,2);
67 auto targetDensity = std::make_shared<Gaussian>(mu, cov)->AsDensity();
74 auto problem = std::make_shared<MySamplingProblem>();
106 pt.put(
"NumSamples", 1e4);
107 pt.put(
"BurnIn", 1e3);
108 pt.put(
"PrintLevel",3);
121 Eigen::VectorXd startPt = mu;
123 Eigen::VectorXd mu_prop(2);
126 Eigen::MatrixXd cov_prop(2,2);
127 cov_prop << 1.0, 0.8,
129 auto proposalDensity = std::make_shared<Gaussian>(mu_prop, cov_prop);
131 auto proposal = std::make_shared<MCSampleProposal>(pt, problem, proposalDensity);
133 std::vector<std::shared_ptr<TransitionKernel> > kernels = {std::make_shared<DummyKernel>(pt, problem, proposal)};
135 auto mcmc = std::make_shared<SingleChainMCMC>(pt, kernels);
145 std::shared_ptr<SampleCollection> samps = mcmc->GetQOIs();
162 Eigen::VectorXd sampMean = samps->Mean();
163 std::cout <<
"\nSample Mean = \n" << sampMean.transpose() << std::endl;
165 Eigen::VectorXd sampVar = samps->Variance();
166 std::cout <<
"\nSample Variance = \n" << sampVar.transpose() << std::endl;
168 Eigen::MatrixXd sampCov = samps->Covariance();
169 std::cout <<
"\nSample Covariance = \n" << sampCov << std::endl;
171 Eigen::VectorXd sampMom3 = samps->CentralMoment(3);
172 std::cout <<
"\nSample Third Moment = \n" << sampMom3 << std::endl << std::endl;
Abstract base class for MCMC and Importance Sampling problems.