Skip to content

Commit

Permalink
Test model and gradients evaluate at initial condition (Issue #3034)
Browse files Browse the repository at this point in the history
  • Loading branch information
bbbales2 committed Mar 31, 2021
1 parent 55f6e57 commit 819272e
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/stan/services/util/initialize.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,28 +121,26 @@ std::vector<double> initialize(Model& model, const stan::io::var_context& init,

msg.str("");
double log_prob(0);
std::vector<double> 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<false, Jacobian>(unconstrained,
disc_vector, &msg);
log_prob = stan::model::log_prob_grad<true, Jacobian>(
model, unconstrained, disc_vector, gradient, &msg);
if (msg.str().length() > 0)
logger.info(msg);
} catch (std::domain_error& e) {
if (msg.str().length() > 0)
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;
} catch (std::exception& e) {
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;
Expand All @@ -158,7 +156,6 @@ std::vector<double> initialize(Model& model, const stan::io::var_context& init,
continue;
}
std::stringstream log_prob_msg;
std::vector<double> gradient;
auto start = std::chrono::steady_clock::now();
try {
// we evaluate this with propto=true since we're
Expand All @@ -168,6 +165,7 @@ std::vector<double> 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;
}
Expand Down

0 comments on commit 819272e

Please sign in to comment.