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 virtual std::shared_ptr<MCMCProposal>
Proposal (std::shared_ptr<MultiIndex>
const& index, std::shared_ptr<AbstractSamplingProblem>
const& samplingProblem)
override {
45 pt.put(
"BlockIndex",0);
47 Eigen::VectorXd mu(2);
49 Eigen::MatrixXd cov(2,2);
54 auto prior = std::make_shared<Gaussian>(mu, cov);
56 return std::make_shared<CrankNicolsonProposal>(
pt, samplingProblem, prior);
60 auto index = std::make_shared<MultiIndex>(1);
61 index->SetValue(0, 3);
65 virtual std::shared_ptr<MCMCProposal>
CoarseProposal (std::shared_ptr<MultiIndex>
const& fineIndex,
66 std::shared_ptr<MultiIndex>
const& coarseIndex,
67 std::shared_ptr<AbstractSamplingProblem>
const& coarseProblem,
68 std::shared_ptr<SingleChainMCMC>
const& coarseChain)
override {
69 pt::ptree ptProposal =
pt;
70 ptProposal.put(
"BlockIndex",0);
71 return std::make_shared<SubsamplingMIProposal>(ptProposal, coarseProblem, coarseIndex, coarseChain);
74 virtual std::shared_ptr<AbstractSamplingProblem>
SamplingProblem (std::shared_ptr<MultiIndex>
const& index)
override {
75 Eigen::VectorXd mu(2);
77 Eigen::MatrixXd cov(2,2);
81 if (index->GetValue(0) == 0) {
84 }
else if (index->GetValue(0) == 1) {
87 }
else if (index->GetValue(0) == 2) {
90 }
else if (index->GetValue(0) == 3) {
94 std::cerr <<
"Sampling problem not defined!" << std::endl;
98 auto coarseTargetDensity = std::make_shared<Gaussian>(mu, cov)->AsDensity();
99 return std::make_shared<MySamplingProblem>(coarseTargetDensity);
102 virtual std::shared_ptr<MIInterpolation>
Interpolation (std::shared_ptr<MultiIndex>
const& index)
override {
103 return std::make_shared<MyInterpolation>();
106 virtual Eigen::VectorXd
StartingPoint (std::shared_ptr<MultiIndex>
const& index)
override {
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
virtual std::shared_ptr< AbstractSamplingProblem > SamplingProblem(std::shared_ptr< MultiIndex > const &index) override
virtual std::shared_ptr< MultiIndex > FinestIndex() override
Eigen::VectorXd startingPoint
virtual std::shared_ptr< MCMCProposal > Proposal(std::shared_ptr< MultiIndex > const &index, std::shared_ptr< AbstractSamplingProblem > const &samplingProblem) override
MyMIComponentFactory(Eigen::VectorXd const &start, pt::ptree pt)
virtual std::shared_ptr< MIInterpolation > Interpolation(std::shared_ptr< MultiIndex > const &index) override