Skip to content

fix pareto_smooth in case of constant tail + cleanup#442

Merged
avehtari merged 3 commits intomasterfrom
fix-pareto_smooth
Mar 26, 2026
Merged

fix pareto_smooth in case of constant tail + cleanup#442
avehtari merged 3 commits intomasterfrom
fix-pareto_smooth

Conversation

@avehtari
Copy link
Member

pareto_smooth() could fail if x is non-constant, but the tail is constant

Main fix

  • Inside pareto_smooth.default(), if ps_tail() returns k as NA, exit early with return(pareto_diags_na(x, return_k, extra_diags))

In addition

  • ps_min_ss() now returns NA if k is NA instead of erroring (with the main fix we don't reach this)
  • cleaned ps_tail()
    • exit earlier if ndraws_tail < 5
    • check constant tail earlier and return original x without a warning
    • removed duplicate sort.int() call
    • removed redundant constant tail check (which also was not using is_constant())
    • removed min_tail variable as it was not used anymore
  • added test to check that pareto_smooth() with non-constant x with constant tail does not error and returns the original x

Copyright and Licensing

By submitting this pull request, the copyright holder is agreeing to
license the submitted work under the following licenses:

@avehtari avehtari requested a review from n-kall March 22, 2026 15:55
@github-actions
Copy link

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

  • ✔️as_draws_array: 146ms -> 144ms [-2.81%, +0.33%]
  • ✔️as_draws_df: 75.9ms -> 76.4ms [-1.08%, +2.42%]
  • ✔️as_draws_list: 170ms -> 171ms [-0.46%, +2.06%]
  • ✔️as_draws_matrix: 31.2ms -> 31.5ms [-0.13%, +2.4%]
  • 🚀as_draws_rvars: 130ms -> 128ms [-2.97%, -0.23%]
  • ❗🐌summarise_draws_100_variables: 764ms -> 801ms [+4.14%, +5.76%]
  • ✔️summarise_draws_10_variables: 89.8ms -> 89.2ms [-1.66%, +0.35%]
    Further explanation regarding interpretation and methodology can be found in the documentation.

Copy link
Collaborator

@florence-bockting florence-bockting left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. I just added three additional tests for checking expected behavior of modified parts (i.e., ps_tail and ps_min_ss).

@github-actions
Copy link

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

  • ✔️as_draws_array: 144ms -> 144ms [-0.91%, +0.92%]
  • ✔️as_draws_df: 76.9ms -> 76.3ms [-2.33%, +0.55%]
  • ✔️as_draws_list: 173ms -> 174ms [-0.67%, +1.02%]
  • ✔️as_draws_matrix: 31.1ms -> 31ms [-1.4%, +0.57%]
  • ✔️as_draws_rvars: 130ms -> 129ms [-1.62%, +0.14%]
  • ❗🐌summarise_draws_100_variables: 743ms -> 781ms [+4.46%, +5.98%]
  • ✔️summarise_draws_10_variables: 89ms -> 89ms [-1.09%, +1.15%]
    Further explanation regarding interpretation and methodology can be found in the documentation.

@avehtari avehtari merged commit f0799d9 into master Mar 26, 2026
10 of 11 checks passed
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.

2 participants