7 namespace pt = boost::property_tree;
11 ImportanceSampling::ImportanceSampling(std::shared_ptr<muq::Modeling::Distribution>
const& target, boost::property_tree::ptree
const& pt) :
SamplingAlgorithm(std::make_shared<
SampleCollection>()), numSamps(pt.
get<unsigned int>(
"NumSamples")), bias(target) {}
14 numSamps(pt.
get<unsigned int>(
"NumSamples")), target(target), bias(bias) {}
25 biasingPara.insert(biasingPara.begin(), Eigen::VectorXd());
28 for(
unsigned int i=0; i<
numSamps; ++i ) {
33 double logweight = 0.0, logbias = 0.0, logtarget = 0.0;
35 logbias =
bias->LogDensity(biasingPara);
36 logtarget =
target->Evaluate(biasingPara[0])[0](0);
37 logweight = logtarget - logbias;
40 auto state = std::make_shared<SamplingState>(biasingPara[0], std::exp(logweight));
42 state->meta[
"log target"] = logtarget;
43 state->meta[
"log bias"] = logbias;
const unsigned int numSamps
The number of samples.
std::shared_ptr< muq::Modeling::Distribution > bias
The biasing distribution.
ImportanceSampling(std::shared_ptr< muq::Modeling::Distribution > const &target, boost::property_tree::ptree const &pt)
virtual std::shared_ptr< SampleCollection > RunImpl(std::vector< Eigen::VectorXd > const &x0) override
const std::vector< Eigen::VectorXd > hyperparameters
Hyperparameters for the biasing distribution.
std::shared_ptr< muq::Modeling::ModPiece > target
A class to hold and analyze a collection of SamplingState objects.
std::shared_ptr< SampleCollection > samples
auto get(const nlohmann::detail::iteration_proxy_value< IteratorType > &i) -> decltype(i.key())