Skip to content

Added sorted log ratio path for loo - #452

Open
VisruthSK wants to merge 2 commits into
masterfrom
ps-tail-specialization
Open

Added sorted log ratio path for loo#452
VisruthSK wants to merge 2 commits into
masterfrom
ps-tail-specialization

Conversation

@VisruthSK

@VisruthSK VisruthSK commented Jun 17, 2026

Copy link
Copy Markdown
Member

This PR was made with assistance from Codex.

Summary

Add ps_tail_sorted_log_ratios(), a specialized helper for loo to use when the log-ratio tail has already been sorted. See stan-dev/loo#290, especially this comment for more motivation.

Removed warning in ps_tail() for too few tail draws as the aforementioned comment suggests. Also deduplicate some code in ps_tail() with a new internal helper.

Copyright and Licensing

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

@github-actions

Copy link
Copy Markdown

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

  • ✔️as_draws_array: 156ms -> 155ms [-1.7%, +0.66%]
  • ✔️as_draws_df: 82.7ms -> 82.6ms [-1.29%, +1.04%]
  • ✔️as_draws_list: 173ms -> 176ms [-0.19%, +3.7%]
  • ✔️as_draws_matrix: 25.4ms -> 25ms [-5.02%, +1.68%]
  • ✔️as_draws_rvars: 132ms -> 131ms [-1.55%, +0.71%]
  • ❗🐌summarise_draws_100_variables: 773ms -> 821ms [+5.56%, +6.66%]
  • ✔️summarise_draws_10_variables: 86.5ms -> 86.4ms [-0.4%, +0.16%]
    Further explanation regarding interpretation and methodology can be found in the documentation.

@VisruthSK
VisruthSK marked this pull request as ready for review June 18, 2026 03:04
@VisruthSK
VisruthSK requested a review from avehtari June 18, 2026 03:04
@github-actions

Copy link
Copy Markdown

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

  • ✔️as_draws_array: 148ms -> 147ms [-1.98%, +1.14%]
  • ✔️as_draws_df: 69.4ms -> 69.9ms [-0.67%, +2.09%]
  • ❗🐌as_draws_list: 156ms -> 159ms [+0.03%, +3.44%]
  • ✔️as_draws_matrix: 24.9ms -> 24.9ms [-0.81%, +0.75%]
  • ✔️as_draws_rvars: 115ms -> 116ms [-1%, +2.55%]
  • ✔️summarise_draws_100_variables: 725ms -> 726ms [-0.13%, +0.43%]
  • ✔️summarise_draws_10_variables: 81ms -> 81.2ms [-0.01%, +0.6%]
    Further explanation regarding interpretation and methodology can be found in the documentation.

@avehtari avehtari left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

exported function might need NEWS.md item

Comment thread R/pareto_smooth.R
ps_convergence_rate(k, ndraws(x))
}


Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why whiitespace change?

Comment thread R/pareto_smooth.R
Comment on lines -488 to -495
if (ndraws_tail < 5) {
warning_no_call(
"Can't fit generalized Pareto distribution ",
"because ndraws_tail is less than 5."
)
return(list(x = x, k = NA))
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

seems like this should be separate from the sorted log ratio path?

Comment thread R/pareto_smooth.R
Comment on lines +556 to +557
#' @export
ps_tail_sorted_log_ratios <- function(x, cutoff, smooth_draws = TRUE, ...) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Add test(s)

Comment thread R/pareto_smooth.R
...
)

smoothed$tail <- log(smoothed$tail)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is it intentional to return $tail while ps_tail() returns $x? If intentional, should be documented in the roxygen

Comment thread R/pareto_smooth.R
#' Function to Pareto smooth a sorted tail of log ratios. Exported
#' for usage in other packages, not by users.
#'
#' @param x Vector of tail elements already sorted in ascending order. Already shifted to account for overflow.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Too long line

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