Skip to content

Commit

Permalink
Merge pull request #3320 from stan-dev/fix/MAD-quantile-exceptions
Browse files Browse the repository at this point in the history
Also catch exceptions in MAD calculation
  • Loading branch information
WardBrian authored Nov 29, 2024
2 parents 42731ba + c4b2f2f commit f4fb7cb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/stan/mcmc/chainset.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,11 @@ class chainset {
auto center = median(index);
Eigen::MatrixXd abs_dev = (draws.array() - center).abs();
Eigen::Map<Eigen::VectorXd> map(abs_dev.data(), abs_dev.size());
return 1.4826 * stan::math::quantile(map, 0.5);
try {
return 1.4826 * stan::math::quantile(map, 0.5);
} catch (const std::logic_error& e) {
return std::numeric_limits<double>::quiet_NaN();
}
}

/**
Expand Down
3 changes: 3 additions & 0 deletions src/test/unit/mcmc/chainset_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@ TEST_F(McmcChains, quantile_tests) {
EXPECT_TRUE(std::isnan(stepsize_quantiles(i)));
}

double stepsize_MAD = datagen_chains.med_abs_deviation("stepsize__");
EXPECT_TRUE(std::isnan(stepsize_MAD));

Eigen::VectorXd bad_probs(3);
bad_probs << 5, 50, 95;
Eigen::VectorXd y_sim_quantiles
Expand Down

0 comments on commit f4fb7cb

Please sign in to comment.