MUQ  0.4.3
SubsamplingMIProposal.cpp
Go to the documentation of this file.
2 namespace muq {
3  namespace SamplingAlgorithms {
4 
5  SubsamplingMIProposal::SubsamplingMIProposal (pt::ptree const& pt, std::shared_ptr<AbstractSamplingProblem> prob, std::shared_ptr<muq::Utilities::MultiIndex> coarseIndex, std::shared_ptr<SingleChainMCMC> coarseChain)
6  : MCMCProposal(pt,prob),
7  coarseChain(coarseChain),
8  subsampling(pt.get<int>("MLMCMC.Subsampling" + multiindexToConfigString(coarseIndex)))
9  {}
10 
11  std::shared_ptr<SamplingState> SubsamplingMIProposal::Sample(std::shared_ptr<SamplingState> const& currentState) {
12 
13  sampleID += subsampling+1;
14  while (coarseChain->GetSamples()->size() <= sampleID) {
15  coarseChain->AddNumSamps(1);
16  coarseChain->Run();
17  }
18 
19  return coarseChain->GetSamples()->at(sampleID);
20  }
21 
22  double SubsamplingMIProposal::LogDensity(std::shared_ptr<SamplingState> const& currState,
23  std::shared_ptr<SamplingState> const& propState) {
24  return 0;
25  }
26 
27  std::string SubsamplingMIProposal::multiindexToConfigString (std::shared_ptr<muq::Utilities::MultiIndex> index) {
28  std::stringstream strs;
29  for (int i = 0; i < index->GetLength(); i++) {
30  strs << "_" << index->GetValue(i);
31  }
32  return strs.str();
33  }
34 
35  }
36 }
std::shared_ptr< SingleChainMCMC > coarseChain
virtual std::shared_ptr< SamplingState > Sample(std::shared_ptr< SamplingState > const &currentState) override
virtual double LogDensity(std::shared_ptr< SamplingState > const &currState, std::shared_ptr< SamplingState > const &propState) override
SubsamplingMIProposal(pt::ptree const &pt, std::shared_ptr< AbstractSamplingProblem > prob, std::shared_ptr< muq::Utilities::MultiIndex > coarseIndex, std::shared_ptr< SingleChainMCMC > coarseChain)
std::string multiindexToConfigString(std::shared_ptr< muq::Utilities::MultiIndex > index)
auto get(const nlohmann::detail::iteration_proxy_value< IteratorType > &i) -> decltype(i.key())
Definition: json.h:3956