Skip to content

Commit

Permalink
Changes per review
Browse files Browse the repository at this point in the history
  • Loading branch information
WardBrian committed Dec 12, 2024
1 parent dc654e0 commit 0abf5d5
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 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
= [&](const Eigen::Matrix<stan::math::var, -1, 1>& theta) {
return model.template log_prob<true, jacobian, stan::math::var>(
const_cast<Eigen::Matrix<stan::math::var, -1, 1>&>(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 @@ -123,7 +121,8 @@ void laplace_sample(const Model& model, const Eigen::VectorXd& theta_hat,
if (calculate_lp) {
// clean up created vars after scope exit
stan::math::nested_rev_autodiff stack;
log_p = log_density_fun(unc_draw).val();
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 0abf5d5

Please sign in to comment.