7 namespace pt = boost::property_tree;
15 SMMALAProposal::SMMALAProposal(pt::ptree pt,
16 std::shared_ptr<AbstractSamplingProblem>
const& probIn,
17 std::shared_ptr<muq::Modeling::ModPiece>
const& forwardModIn,
18 std::shared_ptr<muq::Modeling::Gaussian>
const& priorIn,
19 std::shared_ptr<muq::Modeling::Gaussian>
const& likelihoodIn) :
21 prior(priorIn), likelihood(likelihoodIn), model(forwardModIn), meanScaling(pt.
get(
"MeanScaling",0.5))
30 assert(currentState->state.size()>
blockInd);
33 std::vector<Eigen::VectorXd> props = currentState->state;
35 Eigen::VectorXd
const& xc = currentState->state.at(
blockInd);
40 std::stringstream blockId;
45 if(!currentState->HasMeta(
"SMMALA_Hess" + blockId.str())){
47 Eigen::MatrixXd jac =
model->Jacobian(0,
blockInd, currentState->state);
48 hess =
prior->GetPrecision() + jac.transpose() *
likelihood->ApplyPrecision(jac);
50 currentState->meta[
"SMMALA_Hess" + blockId.str()] = hess;
52 hess =
AnyCast( currentState->meta[
"SMMALA_Hess" + blockId.str()] );
55 if(!currentState->HasMeta(
"SMMALA_Grad" + blockId.str())){
57 currentState->meta[
"SMMALA_Grad" + blockId.str()] = grad;
59 grad =
AnyCast( currentState->meta[
"SMMALA_Grad" + blockId.str()] );
63 Gaussian prop(Eigen::VectorXd::Zero(xc.size()).eval(), hess, Gaussian::Mode::Precision);
69 return std::make_shared<SamplingState>(props, 1.0);
73 std::shared_ptr<SamplingState>
const& propState) {
75 std::stringstream blockId;
80 if(!currState->HasMeta(
"SMMALA_Hess" + blockId.str())){
82 Eigen::MatrixXd jac =
model->Jacobian(0,
blockInd, currState->state);
83 hess =
prior->GetPrecision() + jac.transpose() *
likelihood->ApplyPrecision(jac);
85 currState->meta[
"SMMALA_Hess" + blockId.str()] = hess;
87 hess =
AnyCast( currState->meta[
"SMMALA_Hess" + blockId.str()] );
90 if(!currState->HasMeta(
"SMMALA_Grad" + blockId.str())){
92 currState->meta[
"SMMALA_Grad" + blockId.str()] = grad;
94 grad =
AnyCast( currState->meta[
"SMMALA_Grad" + blockId.str()] );
98 Gaussian prop(Eigen::VectorXd::Zero( propState->state.at(
blockInd).size()).eval(), hess, Gaussian::Mode::Precision);
virtual double LogDensity(ref_vector< Eigen::VectorXd > const &inputs)
Evaluate the log-density.
Eigen::VectorXd Sample(ref_vector< Eigen::VectorXd > const &inputs)
Sample the distribution.
virtual Eigen::MatrixXd ApplyCovariance(Eigen::Ref< const Eigen::MatrixXd > const &x) const override
std::shared_ptr< AbstractSamplingProblem > prob
virtual std::shared_ptr< SamplingState > Sample(std::shared_ptr< SamplingState > const ¤tState) override
std::shared_ptr< muq::Modeling::Gaussian > likelihood
std::shared_ptr< muq::Modeling::Gaussian > prior
The proposal distribution.
std::shared_ptr< muq::Modeling::ModPiece > model
virtual double LogDensity(std::shared_ptr< SamplingState > const &currState, std::shared_ptr< SamplingState > const &propState) override
Class for easily casting boost::any's in assignment operations.
auto get(const nlohmann::detail::iteration_proxy_value< IteratorType > &i) -> decltype(i.key())