5 class MySamplingProblem :
public AbstractSamplingProblem {
7 MySamplingProblem(std::shared_ptr<muq::Modeling::ModPiece> targetIn)
8 : AbstractSamplingProblem(Eigen::VectorXi::Constant(1,2), Eigen::VectorXi::Constant(1,2)),
11 virtual ~MySamplingProblem() =
default;
14 virtual double LogDensity(std::shared_ptr<SamplingState>
const& state)
override {
16 return target->Evaluate(state->state).at(0)(0);
19 virtual std::shared_ptr<SamplingState>
QOI()
override {
20 assert (lastState !=
nullptr);
21 return std::make_shared<SamplingState>(lastState->state[0] * 2, 1.0);
25 std::shared_ptr<SamplingState> lastState =
nullptr;
27 std::shared_ptr<muq::Modeling::ModPiece> target;
34 std::shared_ptr<SamplingState>
Interpolate (std::shared_ptr<SamplingState>
const& coarseProposal, std::shared_ptr<SamplingState>
const& fineProposal) {
35 return std::make_shared<SamplingState>(fineProposal->state);
49 virtual std::shared_ptr<MCMCProposal>
Proposal (std::shared_ptr<MultiIndex>
const& index, std::shared_ptr<AbstractSamplingProblem>
const& samplingProblem)
override {
50 Eigen::VectorXd mu(2);
53 Eigen::MatrixXd cov(2,2);
57 if (index->GetValue(0) == 0) {
60 }
else if (index->GetValue(0) == 1) {
63 }
else if (index->GetValue(0) == 2) {
66 }
else if (index->GetValue(0) == 3) {
70 std::cerr <<
"Sampling problem not defined!" << std::endl;
76 auto proposalDensity = std::make_shared<Gaussian>(mu, cov);
78 return std::make_shared<MCSampleProposal>(
pt, samplingProblem, proposalDensity);
82 auto index = std::make_shared<MultiIndex>(1);
83 index->SetValue(0, 3);
87 virtual std::shared_ptr<MCMCProposal>
CoarseProposal (std::shared_ptr<MultiIndex>
const& fineIndex,
88 std::shared_ptr<MultiIndex>
const& coarseIndex,
89 std::shared_ptr<AbstractSamplingProblem>
const& coarseProblem,
90 std::shared_ptr<SingleChainMCMC>
const& coarseChain)
override {
91 Eigen::VectorXd mu(2);
94 Eigen::MatrixXd cov_prop(2,2);
97 auto proposalDensity = std::make_shared<Gaussian>(mu, cov_prop);
99 return std::make_shared<MCSampleProposal>(
pt, coarseProblem, proposalDensity);
102 virtual std::shared_ptr<AbstractSamplingProblem>
SamplingProblem (std::shared_ptr<MultiIndex>
const& index)
override {
103 Eigen::VectorXd mu(2);
105 Eigen::MatrixXd cov(2,2);
109 if (index->GetValue(0) == 0) {
112 }
else if (index->GetValue(0) == 1) {
115 }
else if (index->GetValue(0) == 2) {
118 }
else if (index->GetValue(0) == 3) {
122 std::cerr <<
"Sampling problem not defined!" << std::endl;
126 auto coarseTargetDensity = std::make_shared<Gaussian>(mu, cov)->AsDensity();
127 return std::make_shared<MySamplingProblem>(coarseTargetDensity);
130 virtual std::shared_ptr<MIInterpolation>
Interpolation (std::shared_ptr<MultiIndex>
const& index)
override {
131 return std::make_shared<MyInterpolation>();
134 virtual Eigen::VectorXd
StartingPoint (std::shared_ptr<MultiIndex>
const& index)
override {
135 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
virtual std::shared_ptr< AbstractSamplingProblem > SamplingProblem(std::shared_ptr< MultiIndex > const &index) override
virtual std::shared_ptr< MultiIndex > FinestIndex() override
virtual bool IsInverseProblem() 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