Skip to content

Round the PSIS tail length down in n_pareto() - #437

Open
soujasK wants to merge 2 commits into
stan-dev:masterfrom
soujasK:fix/408-n-pareto-floor
Open

soujasK wants to merge 2 commits into
stan-dev:masterfrom
soujasK:fix/408-n-pareto-floor

Conversation

@soujasK

@soujasK soujasK commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Part of #408

As discussed in #408, n_pareto() now uses floor() for the PSIS tail length instead of ceiling(), same as the PSIS paper (Appendix H) and posterior::ps_tail_length().

Changes:

  • R/psis.R: ceiling() -> floor(). I also fixed the roxygen note, which said 3*sqrt(S)/r_eff while the code computes 3*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 in deprecated_extractors). Every changed snapshot block has a real value change.
  • tests/testthat/test_loo_moment_matching.R: the pinned mcse_elpd_loo from 23005f4 goes from 0.1904162 to 0.1941738. I checked that the same test setup gives exactly 0.1904162 with ceiling() and 0.1941738 with floor(), so the change comes only from the tail length. @avehtari could you check this one is ok?
  • NEWS.md: add a bullet

Tests: 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.

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-commenter

codecov-commenter commented Dec 2, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.81%. Comparing base (aca15cc) to head (eef9b69).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

This is how benchmark results would change (along with a 95% confidence interval in relative change) if eef9b69 is merged into master:

Status Name Current Incoming Interval
🚀 loo_matrix 1.61s 1.6s [-0.89%, -0.49%]
🚀 loo_function 1.62s 1.61s [-0.76%, -0.35%]

Further explanation regarding interpretation and methodology can be found in the documentation.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants