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.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, samplingProblem, prior);
64 auto index = std::make_shared<MultiIndex>(1);
65 index->SetValue(0, 1);
69 virtual std::shared_ptr<MCMCProposal>
CoarseProposal (std::shared_ptr<MultiIndex>
const& fineIndex,
70 std::shared_ptr<MultiIndex>
const& coarseIndex,
71 std::shared_ptr<AbstractSamplingProblem>
const& coarseProblem,
72 std::shared_ptr<SingleChainMCMC>
const& coarseChain)
override {
73 pt::ptree ptProposal =
pt;
74 pt.put(
"BlockIndex",0);
75 return std::make_shared<SubsamplingMIProposal>(ptProposal, coarseProblem, coarseIndex, coarseChain);
78 virtual std::shared_ptr<AbstractSamplingProblem>
SamplingProblem (std::shared_ptr<MultiIndex>
const& index)
override {
79 Eigen::VectorXd mu(2);
81 Eigen::MatrixXd cov(2,2);
85 if (index->GetValue(0) == 0) {
88 }
else if (index->GetValue(0) == 1) {
91 }
else if (index->GetValue(0) == 2) {
94 }
else if (index->GetValue(0) == 3) {
98 std::cerr <<
"Sampling problem not defined!" << std::endl;
102 auto coarseTargetDensity = std::make_shared<Gaussian>(mu, cov)->AsDensity();
103 return std::make_shared<MySamplingProblem>(coarseTargetDensity);
106 virtual std::shared_ptr<MIInterpolation>
Interpolation (std::shared_ptr<MultiIndex>
const& index)
override {
107 return std::make_shared<MyInterpolation>();
110 virtual Eigen::VectorXd
StartingPoint (std::shared_ptr<MultiIndex>
const& index)
override {
111 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