Skip to content

Commit

Permalink
update laplace
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveBronder committed Dec 13, 2024
2 parents f1a8e56 + 0820199 commit 48bbb6e
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/stan/services/optimize/laplace_sample.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,10 @@ void laplace_sample(const Model& model, const Eigen::VectorXd& theta_hat,

// create log density functor for vars and vals
std::stringstream log_density_msgs;
auto log_density_fun
= [&](auto& theta) {
return model.template log_prob<true, jacobian, stan::math::var>(
theta,
&log_density_msgs);
};
auto log_density_fun = [&](auto&& theta) {
return model.template log_prob<true, jacobian, stan::math::var>(
theta, &log_density_msgs);
};

// calculate inverse negative Hessian's Cholesky factor
if (refresh > 0) {
Expand Down Expand Up @@ -121,7 +119,10 @@ void laplace_sample(const Model& model, const Eigen::VectorXd& theta_hat,

double log_p;
if (calculate_lp) {
log_p = log_density_fun(unc_draw).val();
// clean up created vars after scope exit
stan::math::nested_rev_autodiff stack;
auto theta = unc_draw.cast<stan::math::var>().eval();
log_p = log_density_fun(theta).val();
} else {
log_p = std::numeric_limits<double>::quiet_NaN();
}
Expand Down

0 comments on commit 48bbb6e

Please sign in to comment.