PSIS

PSIS.jl implements the Pareto smoothed importance sampling (PSIS) algorithm from [VehtariSimpson2021].

Given a set of importance weights used in some estimator, PSIS both improves the reliability of the estimates by smoothing the importance weights and acts as a diagnostic of the reliability of the estimates.

See psis for details.

Example

In this example, we use PSIS to smooth log importance ratios for importance sampling 30 isotropic Student $t$-distributed parameters using standard normal distributions as proposals.

using PSIS, Distributions
proposal = Normal()
target = TDist(7)
x = rand(proposal, 30, 1_000)
log_ratios = logpdf.(target, x) .- logpdf.(proposal, x)
result = psis(log_ratios)
┌ Warning: Pareto shape=0.81 ≥ 0.7. Resulting importance sampling estimates are likely to be unstable.
└ @ PSIS ~/.julia/packages/PSIS/15xLk/src/core.jl:195
┌ Warning: Pareto shape=0.82 ≥ 0.7. Resulting importance sampling estimates are likely to be unstable.
└ @ PSIS ~/.julia/packages/PSIS/15xLk/src/core.jl:195
┌ Warning: Pareto shape=0.72 ≥ 0.7. Resulting importance sampling estimates are likely to be unstable.
└ @ PSIS ~/.julia/packages/PSIS/15xLk/src/core.jl:195
┌ Warning: Pareto shape=0.71 ≥ 0.7. Resulting importance sampling estimates are likely to be unstable.
└ @ PSIS ~/.julia/packages/PSIS/15xLk/src/core.jl:195
┌ Warning: Pareto shape=0.84 ≥ 0.7. Resulting importance sampling estimates are likely to be unstable.
└ @ PSIS ~/.julia/packages/PSIS/15xLk/src/core.jl:195
┌ Warning: Pareto shape=0.88 ≥ 0.7. Resulting importance sampling estimates are likely to be unstable.
└ @ PSIS ~/.julia/packages/PSIS/15xLk/src/core.jl:195
┌ Warning: Pareto shape=0.81 ≥ 0.7. Resulting importance sampling estimates are likely to be unstable.
└ @ PSIS ~/.julia/packages/PSIS/15xLk/src/core.jl:195
┌ Warning: Pareto shape=0.99 ≥ 0.7. Resulting importance sampling estimates are likely to be unstable.
└ @ PSIS ~/.julia/packages/PSIS/15xLk/src/core.jl:195
┌ Warning: Pareto shape=0.72 ≥ 0.7. Resulting importance sampling estimates are likely to be unstable.
└ @ PSIS ~/.julia/packages/PSIS/15xLk/src/core.jl:195
PSISResult{Float64, Matrix{Float64}, Vector{Float64}, Vector{Int64}, Vector{GeneralizedPareto{Float64}}}:
    pareto_shape: [0.4574379142675616, 0.8101099220031522, 0.5315470814227512, 0.8225685777063371, 0.6773969963672641, 0.7229093550848019, 0.43679456680718026, 0.6643051943710179, 0.5571233606756554, 0.5335600346132449  …  0.49322517638511537, 0.5816300065815206, 0.5945840473522489, 0.8817999782322504, 0.8073272022807836, 0.568012440275629, 0.5528957257977059, 0.993157592116447, 0.7211470703414071, 0.6268057249625905]

As indicated by the warnings, this is a poor choice of a proposal distribution, and estimates are unlikely to converge.

When running PSIS with many parameters, it is useful to plot the Pareto shape values to diagnose convergence. We can do this using Plots.jl.

using Plots
plot(result; showlines=true, marker=:+, legend=false)

See PSISResult for an explanation of the shape thresholds.