Repository navigation
Conversation
n_pareto() used ceiling() for the tail length, while the PSIS paper (Appendix H) and posterior::ps_tail_length() use floor(). As discussed in stan-dev#408 it only has to be an integer, so loo now uses floor() too for consistency. The roxygen note also said 3*sqrt(S)/r_eff, which is fixed to match the code (3*sqrt(S/r_eff)). The tail can be one draw shorter, so results change slightly. The affected snapshots are updated, and the pinned mcse_elpd_loo value in the moment matching test goes from 0.1904162 to 0.1941738. Part of stan-dev#408 Signed-off-by: Soujas K <kudchadkarsoujas@gmail.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #437 +/- ##
=======================================
Coverage 92.81% 92.81%
=======================================
Files 31 31
Lines 3074 3074
=======================================
Hits 2853 2853
Misses 221 221 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
This is how benchmark results would change (along with a 95% confidence interval in relative change) if 7498582 is merged into master:
Further explanation regarding interpretation and methodology can be found in the documentation. |
| posterior >= 1.8.0 by @soujasK in #433 | ||
| * Round the PSIS tail length down instead of up in the internal | ||
| `n_pareto()`, as in the PSIS paper and `posterior::ps_tail_length()`, by | ||
| @soujasK in #437 |
There was a problem hiding this comment.
We should probably mention in the NEWS.md also the output change that this fix causes. Something like "Results of psis(), loo(), E_loo() and other functions that use psis() can change slightly."
| #' \item{`tail_len`}{ | ||
| #' Vector of tail lengths used for fitting the generalized Pareto distribution. |
There was a problem hiding this comment.
Here we should probably add the information about the output change.
#' \item{`tail_len`}{
#' Vector of tail lengths used for fitting the generalized Pareto distribution.
#' The tail length is `floor(min(0.2 * S, 3 * sqrt(S / r_eff)))`. Earlier versions of loo
#' rounded up, so results can differ slightly.
#' }
@jgabry do you think that's enough here and in the NEWS.md or should we communicate this additionally somewhere else?
There was a problem hiding this comment.
Probably, add a test that fails on the old code.
test_that("psis() rounds the tail length down", {
psis_out <- psis(-example_loglik_matrix())
expect_equal(unique(attr(psis_out, "tail_len")), 94)
})
florence-bockting
left a comment
There was a problem hiding this comment.
Thank you very much, this looks already very good.
Just some minor comments.
|
Yeah @florence-bockting i would review the small changes and apply where applicable |
Mention in NEWS.md and the psis() docs that results can change slightly, and add a test that fails with the old ceiling rounding. Signed-off-by: Soujas K <kudchadkarsoujas@gmail.com>
…08-n-pareto-floor
|
Thanks @florence-bockting!I added all three:the NEWS.md note about the output change,the formula in the |
Part of #408
As discussed in #408,
n_pareto()now usesfloor()for the PSIS tail length instead ofceiling(), same as the PSIS paper (Appendix H) andposterior::ps_tail_length().Changes:
R/psis.R:ceiling()->floor(). I also fixed the roxygen note, which said3*sqrt(S)/r_effwhile the code computes3*sqrt(S/r_eff).tests/testthat/_snaps: updated the snapshots that changed. The tail can be one draw shorter, so the values move a little (e.g.elpd_loo-83.58926 -> -83.58963 indeprecated_extractors). Every changed snapshot block has a real value change.tests/testthat/test_loo_moment_matching.R: the pinnedmcse_elpd_loofrom 23005f4 goes from 0.1904162 to 0.1941738. I checked that the same test setup gives exactly 0.1904162 withceiling()and 0.1941738 withfloor(), so the change comes only from the tail length. @avehtari could you check this one is ok?NEWS.md: add a bulletTests:
devtools::test()passes locally (1366 passed, 0 failed, 0 skipped) with R 4.4.3. The serialized snapshots were written with R 4.4.3, so their header bytes differ from the old ones written with 4.5.0.expect_snapshot_value()compares the deserialized values, so this doesn't affect the tests.@florence-bockting
AI disclosure: I used Claude to help prepare this change. I reviewed and understood all of it and can explain and defend it in review.