From 819272ea7cb741751f5123adb82a8c8e96df04e8 Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 31 Mar 2021 13:27:25 -0700 Subject: [PATCH 1/2] Test model and gradients evaluate at initial condition (Issue #3034) --- src/stan/services/util/initialize.hpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/stan/services/util/initialize.hpp b/src/stan/services/util/initialize.hpp index fd180819b99..247df97a8c7 100644 --- a/src/stan/services/util/initialize.hpp +++ b/src/stan/services/util/initialize.hpp @@ -121,12 +121,10 @@ std::vector initialize(Model& model, const stan::io::var_context& init, msg.str(""); double log_prob(0); + std::vector gradient; try { - // we evaluate the log_prob function with propto=false - // because we're evaluating with `double` as the type of - // the parameters. - log_prob = model.template log_prob(unconstrained, - disc_vector, &msg); + log_prob = stan::model::log_prob_grad( + model, unconstrained, disc_vector, gradient, &msg); if (msg.str().length() > 0) logger.info(msg); } catch (std::domain_error& e) { @@ -134,7 +132,7 @@ std::vector initialize(Model& model, const stan::io::var_context& init, logger.info(msg); logger.info("Rejecting initial value:"); logger.info( - " Error evaluating the log probability" + " Error evaluating the log probability with gradients" " at the initial value."); logger.info(e.what()); continue; @@ -142,7 +140,7 @@ std::vector initialize(Model& model, const stan::io::var_context& init, if (msg.str().length() > 0) logger.info(msg); logger.info( - "Unrecoverable error evaluating the log probability" + "Unrecoverable error evaluating the log probability with gradients" " at the initial value."); logger.info(e.what()); throw; @@ -158,7 +156,6 @@ std::vector initialize(Model& model, const stan::io::var_context& init, continue; } std::stringstream log_prob_msg; - std::vector gradient; auto start = std::chrono::steady_clock::now(); try { // we evaluate this with propto=true since we're @@ -168,6 +165,7 @@ std::vector initialize(Model& model, const stan::io::var_context& init, } catch (const std::exception& e) { if (log_prob_msg.str().length() > 0) logger.info(log_prob_msg); + logger.info(" Failed to evaluate log_prob with gradients for performance test"); logger.info(e.what()); throw; } From 4784e7405b50d7e4c1a8b72dc950a07aebda69e9 Mon Sep 17 00:00:00 2001 From: Stan Jenkins Date: Wed, 31 Mar 2021 20:44:36 +0000 Subject: [PATCH 2/2] [Jenkins] auto-formatting by clang-format version 6.0.0-1ubuntu2~16.04.1 (tags/RELEASE_600/final) --- src/stan/services/util/initialize.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/stan/services/util/initialize.hpp b/src/stan/services/util/initialize.hpp index 247df97a8c7..ef30446f7f1 100644 --- a/src/stan/services/util/initialize.hpp +++ b/src/stan/services/util/initialize.hpp @@ -165,7 +165,8 @@ std::vector initialize(Model& model, const stan::io::var_context& init, } catch (const std::exception& e) { if (log_prob_msg.str().length() > 0) logger.info(log_prob_msg); - logger.info(" Failed to evaluate log_prob with gradients for performance test"); + logger.info( + " Failed to evaluate log_prob with gradients for performance test"); logger.info(e.what()); throw; }