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 void SetComm(std::shared_ptr<parcer::Communicator>
const& comm)
override {
53 virtual std::shared_ptr<MCMCProposal>
Proposal (std::shared_ptr<MultiIndex>
const& index, std::shared_ptr<AbstractSamplingProblem>
const& samplingProblem)
override {
54 Eigen::VectorXd mu(2);
57 Eigen::MatrixXd cov(2,2);
61 if (index->GetValue(0) == 0) {
64 }
else if (index->GetValue(0) == 1) {
67 }
else if (index->GetValue(0) == 2) {
70 }
else if (index->GetValue(0) == 3) {
74 std::cerr <<
"Sampling problem not defined!" << std::endl;
80 auto proposalDensity = std::make_shared<Gaussian>(mu, cov);
82 return std::make_shared<MCSampleProposal>(
pt, samplingProblem, proposalDensity);
86 auto index = std::make_shared<MultiIndex>(1);
87 index->SetValue(0, 3);
91 virtual std::shared_ptr<MCMCProposal>
CoarseProposal (std::shared_ptr<MultiIndex>
const& fineIndex,
92 std::shared_ptr<MultiIndex>
const& coarseIndex,
93 std::shared_ptr<AbstractSamplingProblem>
const& coarseProblem,
94 std::shared_ptr<SingleChainMCMC>
const& coarseChain)
override {
95 Eigen::VectorXd mu(2);
98 Eigen::MatrixXd cov_prop(2,2);
101 auto proposalDensity = std::make_shared<Gaussian>(mu, cov_prop);
103 return std::make_shared<MCSampleProposal>(
pt, coarseProblem, proposalDensity);
106 virtual std::shared_ptr<AbstractSamplingProblem>
SamplingProblem (std::shared_ptr<MultiIndex>
const& index)
override {
107 Eigen::VectorXd mu(2);
109 Eigen::MatrixXd cov(2,2);
113 if (index->GetValue(0) == 0) {
116 }
else if (index->GetValue(0) == 1) {
119 }
else if (index->GetValue(0) == 2) {
122 }
else if (index->GetValue(0) == 3) {
126 std::cerr <<
"Sampling problem not defined!" << std::endl;
130 auto coarseTargetDensity = std::make_shared<Gaussian>(mu, cov)->AsDensity();
131 return std::make_shared<MySamplingProblem>(coarseTargetDensity);
134 virtual std::shared_ptr<MIInterpolation>
Interpolation (std::shared_ptr<MultiIndex>
const& index)
override {
135 return std::make_shared<MyInterpolation>();
138 virtual Eigen::VectorXd
StartingPoint (std::shared_ptr<MultiIndex>
const& index)
override {
139 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 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