Skip to content

Commit

Permalink
Don't error for very low log-weights (#28)
Browse files Browse the repository at this point in the history
* Don't rescale distribution

* Add basic test

* Increment version number
  • Loading branch information
sethaxen authored Feb 8, 2022
1 parent 1af98ee commit 9f39f24
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
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.6"
version = "0.3.0"

[deps]
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
Expand Down
8 changes: 4 additions & 4 deletions src/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ Result of Pareto-smoothed importance sampling (PSIS) using [`psis`](@ref).
- `log_weights_norm`: the logarithm of the normalization constant of `log_weights`
- `tail_length`: length of the upper tail of `log_weights` that was smoothed
- `tail_dist`: the generalized Pareto distribution that was fit to the tail of
`log_weights`
`log_weights`. Note that the tail weights are scaled to have a maximum of 1, so
`tail_dist * exp(maximum(log_ratios))` is the corresponding fit directly to the tail of
`log_ratios`.
# Diagnostic
Expand Down Expand Up @@ -303,7 +305,5 @@ function psis_tail!(logw, logμ, M=length(logw), improved=false)
logw[i] = min(log(_quantile(tail_dist_adjusted, p[i])), 0) + logw_max
end
end
# undo scaling for the tail distribution
tail_dist = scale(tail_dist_adjusted, exp(logw_max))
return logw, tail_dist
return logw, tail_dist_adjusted
end
4 changes: 0 additions & 4 deletions src/generalized_pareto.jl
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,3 @@ function prior_adjust_shape(d::Distributions.GeneralizedPareto, n, ξ_prior=1//2
ξ = (n * d.ξ + nobs * ξ_prior) / (n + nobs)
return Distributions.GeneralizedPareto(d.μ, d.σ, ξ)
end

function scale(d::Distributions.GeneralizedPareto, s)
return Distributions.GeneralizedPareto(d.μ * s, d.σ * s, d.ξ)
end
5 changes: 5 additions & 0 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,11 @@ end
end
end

# https://github.com/arviz-devs/PSIS.jl/issues/27
@testset "no failure for very low log-weights" begin
psis(rand(1000) .- 1500)
end

@testset "compatibility with arrays with named axes/dims" begin
param_names = [Symbol("x[$i]") for i in 1:10]
iter_names = 101:200
Expand Down

2 comments on commit 9f39f24

@sethaxen
Copy link
Member Author

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/54142

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.3.0 -m "<description of version>" 9f39f249034895d74df5098cde01e0bbbe9e5469
git push origin v0.3.0

Please sign in to comment.