3 class MySamplingProblem :
public AbstractSamplingProblem {
5 MySamplingProblem(std::shared_ptr<muq::Modeling::ModPiece> targetIn)
6 : AbstractSamplingProblem(Eigen::VectorXi::Constant(1,2), Eigen::VectorXi::Constant(1,2)),
9 virtual ~MySamplingProblem() =
default;
12 virtual double LogDensity(std::shared_ptr<SamplingState>
const& state)
override {
14 return target->Evaluate(state->state).at(0)(0);
17 virtual std::shared_ptr<SamplingState>
QOI()
override {
18 assert (lastState !=
nullptr);
19 return std::make_shared<SamplingState>(lastState->state, 1.0);
23 std::shared_ptr<SamplingState> lastState =
nullptr;
25 std::shared_ptr<muq::Modeling::ModPiece> target;
32 std::shared_ptr<SamplingState>
Interpolate (std::shared_ptr<SamplingState>
const& coarseProposal, std::shared_ptr<SamplingState>
const& fineProposal) {
33 return std::make_shared<SamplingState>(coarseProposal->state);
43 void SetComm(std::shared_ptr<parcer::Communicator>
const& comm)
override {
47 virtual std::shared_ptr<MCMCProposal>
Proposal (std::shared_ptr<MultiIndex>
const& index, std::shared_ptr<AbstractSamplingProblem>
const& samplingProblem)
override {
49 pt_prop.put(
"BlockIndex",0);
51 Eigen::VectorXd mu(2);
53 Eigen::MatrixXd cov(2,2);
58 auto prior = std::make_shared<Gaussian>(mu, cov);
60 return std::make_shared<CrankNicolsonProposal>(pt_prop, samplingProblem, prior);
64 auto index = std::make_shared<MultiIndex>(2);
65 index->SetValue(0, 2);
66 index->SetValue(1, 2);
70 virtual std::shared_ptr<MCMCProposal>
CoarseProposal (std::shared_ptr<MultiIndex>
const& fineIndex,
71 std::shared_ptr<MultiIndex>
const& coarseIndex,
72 std::shared_ptr<AbstractSamplingProblem>
const& coarseProblem,
73 std::shared_ptr<SingleChainMCMC>
const& coarseChain)
override {
74 pt::ptree ptProposal =
pt;
75 ptProposal.put(
"BlockIndex",0);
76 return std::make_shared<SubsamplingMIProposal>(ptProposal, coarseProblem, coarseIndex, coarseChain);
79 virtual std::shared_ptr<AbstractSamplingProblem>
SamplingProblem (std::shared_ptr<MultiIndex>
const& index)
override {
80 Eigen::VectorXd mu(2);
82 Eigen::MatrixXd cov(2,2);
86 if (index->GetValue(1) == 0) {
89 }
else if (index->GetValue(1) == 1) {
92 }
else if (index->GetValue(1) == 2) {
96 std::cerr <<
"Sampling problem not defined!" << std::endl;
99 if (index->GetValue(0) == 0) {
102 }
else if (index->GetValue(0) == 1) {
105 }
else if (index->GetValue(0) == 2) {
109 std::cerr <<
"Sampling problem not defined!" << std::endl;
113 auto coarseTargetDensity = std::make_shared<Gaussian>(mu, cov)->AsDensity();
114 return std::make_shared<MySamplingProblem>(coarseTargetDensity);
117 virtual std::shared_ptr<MIInterpolation>
Interpolation (std::shared_ptr<MultiIndex>
const& index)
override {
118 return std::make_shared<MyInterpolation>();
121 virtual Eigen::VectorXd
StartingPoint (std::shared_ptr<MultiIndex>
const& index)
override {
122 Eigen::VectorXd mu(2);
std::shared_ptr< SamplingState > Interpolate(std::shared_ptr< SamplingState > const &coarseProposal, std::shared_ptr< SamplingState > const &fineProposal)
virtual Eigen::VectorXd StartingPoint(std::shared_ptr< MultiIndex > const &index) override
virtual std::shared_ptr< MCMCProposal > CoarseProposal(std::shared_ptr< MultiIndex > const &fineIndex, std::shared_ptr< MultiIndex > const &coarseIndex, std::shared_ptr< AbstractSamplingProblem > const &coarseProblem, std::shared_ptr< SingleChainMCMC > const &coarseChain) override
void SetComm(std::shared_ptr< parcer::Communicator > const &comm) override
virtual std::shared_ptr< AbstractSamplingProblem > SamplingProblem(std::shared_ptr< MultiIndex > const &index) override
virtual std::shared_ptr< MultiIndex > FinestIndex() override
virtual std::shared_ptr< MCMCProposal > Proposal(std::shared_ptr< MultiIndex > const &index, std::shared_ptr< AbstractSamplingProblem > const &samplingProblem) override
MyMIComponentFactory(pt::ptree pt)
virtual std::shared_ptr< MIInterpolation > Interpolation(std::shared_ptr< MultiIndex > const &index) override