Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort only upper tail weights #22

Merged
merged 4 commits into from
Dec 30, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "PSIS"
uuid = "ce719bf2-d5d0-4fb9-925d-10a81b42ad04"
authors = ["Seth Axen <[email protected]> and contributors"]
version = "0.2.5"
version = "0.2.6"

[deps]
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
Expand Down
14 changes: 6 additions & 8 deletions src/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,6 @@ While `psis` computes smoothed log weights out-of-place, `psis!` smooths them in

# Keywords

- `sorted=issorted(vec(log_ratios))`: whether `log_ratios` are already sorted. Only
accepted if `nparams==1`.
- `improved=false`: If `true`, use the adaptive empirical prior of [^Zhang2010].
If `false`, use the simpler prior of [^ZhangStephens2009], which is also used in
[^VehtariSimpson2021].
Expand Down Expand Up @@ -207,7 +205,7 @@ end
function psis!(
logw::AbstractVector,
reff=1;
sorted::Bool=issorted(logw),
sorted::Bool=false, # deprecated
improved::Bool=false,
warn::Bool=true,
)
Expand All @@ -219,11 +217,11 @@ function psis!(
@warn "$M tail draws is insufficient to fit the generalized Pareto distribution. $MISSING_SHAPE_SUMMARY"
return PSISResult(logw, LogExpFunctions.logsumexp(logw), reff_val, M, missing)
end
perm = sorted ? collect(eachindex(logw)) : sortperm(logw)
icut = S - M
tail_range = (icut + 1):S
@inbounds logw_tail = @views logw[perm[tail_range]]
@inbounds logu = logw[perm[icut]]
perm = partialsortperm(logw, (S - M):S)
cutoff_ind = perm[1]
tail_inds = @view perm[2:M + 1]
sethaxen marked this conversation as resolved.
Show resolved Hide resolved
logu = logw[cutoff_ind]
logw_tail = @views logw[tail_inds]
_, tail_dist = psis_tail!(logw_tail, logu, M, improved)
warn && check_pareto_shape(tail_dist)
return PSISResult(logw, LogExpFunctions.logsumexp(logw), reff_val, M, tail_dist)
Expand Down