Skip to content

Commit

Permalink
build based on e07c715
Browse files Browse the repository at this point in the history
  • Loading branch information
Documenter.jl committed Jun 23, 2023
1 parent 337ed3c commit da3f7bb
Show file tree
Hide file tree
Showing 16 changed files with 16,246 additions and 2 deletions.
2 changes: 1 addition & 1 deletion stable
1 change: 1 addition & 0 deletions v0.8
10 changes: 10 additions & 0 deletions v0.8.0/api/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"/><meta name="viewport" content="width=device-width, initial-scale=1.0"/><title>API · PSIS.jl</title><script data-outdated-warner src="../assets/warner.js"></script><link href="https://cdnjs.cloudflare.com/ajax/libs/lato-font/3.0.0/css/lato-font.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/juliamono/0.045/juliamono.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/fontawesome.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/solid.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/brands.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.13.24/katex.min.css" rel="stylesheet" type="text/css"/><script>documenterBaseURL=".."</script><script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js" data-main="../assets/documenter.js"></script><script src="../siteinfo.js"></script><script src="../../versions.js"></script><link class="docs-theme-link" rel="stylesheet" type="text/css" href="../assets/themes/documenter-dark.css" data-theme-name="documenter-dark" data-theme-primary-dark/><link class="docs-theme-link" rel="stylesheet" type="text/css" href="../assets/themes/documenter-light.css" data-theme-name="documenter-light" data-theme-primary/><script src="../assets/themeswap.js"></script></head><body><div id="documenter"><nav class="docs-sidebar"><div class="docs-package-name"><span class="docs-autofit"><a href="../">PSIS.jl</a></span></div><form class="docs-search" action="../search/"><input class="docs-search-query" id="documenter-search-query" name="q" type="text" placeholder="Search docs"/></form><ul class="docs-menu"><li><a class="tocitem" href="../">Home</a></li><li><a class="tocitem" href="../plotting/">Plotting</a></li><li class="is-active"><a class="tocitem" href>API</a><ul class="internal"><li><a class="tocitem" href="#Core-functionality"><span>Core functionality</span></a></li><li><a class="tocitem" href="#Plotting"><span>Plotting</span></a></li></ul></li><li><a class="tocitem" href="../internal/">Internal</a></li></ul><div class="docs-version-selector field has-addons"><div class="control"><span class="docs-label button is-static is-size-7">Version</span></div><div class="docs-selector control is-expanded"><div class="select is-fullwidth is-size-7"><select id="documenter-version-selector"></select></div></div></div></nav><div class="docs-main"><header class="docs-navbar"><nav class="breadcrumb"><ul class="is-hidden-mobile"><li class="is-active"><a href>API</a></li></ul><ul class="is-hidden-tablet"><li class="is-active"><a href>API</a></li></ul></nav><div class="docs-right"><a class="docs-edit-link" href="https://github.com/arviz-devs/PSIS.jl/blob/main/docs/src/api.md#" title="Edit on GitHub"><span class="docs-icon fab"></span><span class="docs-label is-hidden-touch">Edit on GitHub</span></a><a class="docs-settings-button fas fa-cog" id="documenter-settings-button" href="#" title="Settings"></a><a class="docs-sidebar-button fa fa-bars is-hidden-desktop" id="documenter-sidebar-button" href="#"></a></div></header><article class="content" id="documenter-page"><h1 id="API"><a class="docs-heading-anchor" href="#API">API</a><a id="API-1"></a><a class="docs-heading-anchor-permalink" href="#API" title="Permalink"></a></h1><h2 id="Core-functionality"><a class="docs-heading-anchor" href="#Core-functionality">Core functionality</a><a id="Core-functionality-1"></a><a class="docs-heading-anchor-permalink" href="#Core-functionality" title="Permalink"></a></h2><article class="docstring"><header><a class="docstring-binding" id="PSIS.PSISResult" href="#PSIS.PSISResult"><code>PSIS.PSISResult</code></a><span class="docstring-category">Type</span></header><section><div><pre><code class="language-julia hljs">PSISResult</code></pre><p>Result of Pareto-smoothed importance sampling (PSIS) using <a href="#PSIS.psis"><code>psis</code></a>.</p><p><strong>Properties</strong></p><ul><li><code>log_weights</code>: un-normalized Pareto-smoothed log weights</li><li><code>weights</code>: normalized Pareto-smoothed weights (allocates a copy)</li><li><code>pareto_shape</code>: Pareto <span>$k=ξ$</span> shape parameter</li><li><code>nparams</code>: number of parameters in <code>log_weights</code></li><li><code>ndraws</code>: number of draws in <code>log_weights</code></li><li><code>nchains</code>: number of chains in <code>log_weights</code></li><li><code>reff</code>: the ratio of the effective sample size of the unsmoothed importance ratios and the actual sample size.</li><li><code>ess</code>: estimated effective sample size of estimate of mean using smoothed importance samples (see <a href="#PSIS.ess_is"><code>ess_is</code></a>)</li><li><code>tail_length</code>: length of the upper tail of <code>log_weights</code> that was smoothed</li><li><code>tail_dist</code>: the generalized Pareto distribution that was fit to the tail of <code>log_weights</code>. Note that the tail weights are scaled to have a maximum of 1, so <code>tail_dist * exp(maximum(log_ratios))</code> is the corresponding fit directly to the tail of <code>log_ratios</code>.</li><li><code>normalized::Bool</code>:indicates whether <code>log_weights</code> are log-normalized along the sample dimensions.</li></ul><p><strong>Diagnostic</strong></p><p>The <code>pareto_shape</code> parameter <span>$k=ξ$</span> of the generalized Pareto distribution <code>tail_dist</code> can be used to diagnose reliability and convergence of estimates using the importance weights <sup class="footnote-reference"><a id="citeref-VehtariSimpson2021" href="#footnote-VehtariSimpson2021">[VehtariSimpson2021]</a></sup>.</p><ul><li>if <span>$k &lt; \frac{1}{3}$</span>, importance sampling is stable, and importance sampling (IS) and PSIS both are reliable.</li><li>if <span>$k ≤ \frac{1}{2}$</span>, then the importance ratio distributon has finite variance, and the central limit theorem holds. As <span>$k$</span> approaches the upper bound, IS becomes less reliable, while PSIS still works well but with a higher RMSE.</li><li>if <span>$\frac{1}{2} &lt; k ≤ 0.7$</span>, then the variance is infinite, and IS can behave quite poorly. However, PSIS works well in this regime.</li><li>if <span>$0.7 &lt; k ≤ 1$</span>, then it quickly becomes impractical to collect enough importance weights to reliably compute estimates, and importance sampling is not recommended.</li><li>if <span>$k &gt; 1$</span>, then neither the variance nor the mean of the raw importance ratios exists. The convergence rate is close to zero, and bias can be large with practical sample sizes.</li></ul><p>See <a href="#PSIS.PSISPlots.paretoshapeplot"><code>PSISPlots.paretoshapeplot</code></a> for a diagnostic plot.</p></div><a class="docs-sourcelink" target="_blank" href="https://github.com/arviz-devs/PSIS.jl/blob/e07c7150dafbad360202c2e07fc3ea0d862b8500/src/core.jl#L12-L61">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="PSIS.psis" href="#PSIS.psis"><code>PSIS.psis</code></a><span class="docstring-category">Function</span></header><section><div><pre><code class="language-julia hljs">psis(log_ratios, reff = 1.0; kwargs...) -&gt; PSISResult
psis!(log_ratios, reff = 1.0; kwargs...) -&gt; PSISResult</code></pre><p>Compute Pareto smoothed importance sampling (PSIS) log weights <sup class="footnote-reference"><a id="citeref-VehtariSimpson2021" href="#footnote-VehtariSimpson2021">[VehtariSimpson2021]</a></sup>.</p><p>While <code>psis</code> computes smoothed log weights out-of-place, <code>psis!</code> smooths them in-place.</p><p><strong>Arguments</strong></p><ul><li><code>log_ratios</code>: an array of logarithms of importance ratios, with size <code>(draws, [chains, [parameters...]])</code>, where <code>chains&gt;1</code> would be used when chains are generated using Markov chain Monte Carlo.</li><li><code>reff::Union{Real,AbstractArray}</code>: the ratio(s) of effective sample size of <code>log_ratios</code> and the actual sample size <code>reff = ess/(draws * chains)</code>, used to account for autocorrelation, e.g. due to Markov chain Monte Carlo. If an array, it must have the size <code>(parameters...,)</code> to match <code>log_ratios</code>.</li></ul><p><strong>Keywords</strong></p><ul><li><code>warn=true</code>: If <code>true</code>, warning messages are delivered</li><li><code>normalize=true</code>: If <code>true</code>, the log-weights will be log-normalized so that <code>exp.(log_weights)</code> sums to 1 along the sample dimensions.</li></ul><p><strong>Returns</strong></p><ul><li><code>result</code>: a <a href="#PSIS.PSISResult"><code>PSISResult</code></a> object containing the results of the Pareto-smoothing.</li></ul><p>A warning is raised if the Pareto shape parameter <span>$k ≥ 0.7$</span>. See <a href="#PSIS.PSISResult"><code>PSISResult</code></a> for details and <a href="#PSIS.PSISPlots.paretoshapeplot"><code>PSISPlots.paretoshapeplot</code></a> for a diagnostic plot.</p></div><a class="docs-sourcelink" target="_blank" href="https://github.com/arviz-devs/PSIS.jl/blob/e07c7150dafbad360202c2e07fc3ea0d862b8500/src/core.jl#L176-L210">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="PSIS.ess_is" href="#PSIS.ess_is"><code>PSIS.ess_is</code></a><span class="docstring-category">Function</span></header><section><div><pre><code class="language-julia hljs">ess_is(weights; reff=1)</code></pre><p>Estimate effective sample size (ESS) for importance sampling over the sample dimensions.</p><p>Given normalized weights <span>$w_{1:n}$</span>, the ESS is estimated using the L2-norm of the weights:</p><p class="math-container">\[\mathrm{ESS}(w_{1:n}) = \frac{r_{\mathrm{eff}}}{\sum_{i=1}^n w_i^2}\]</p><p>where <span>$r_{\mathrm{eff}}$</span> is the relative efficiency of the <code>log_weights</code>.</p><pre><code class="nohighlight hljs">ess_is(result::PSISResult; bad_shape_missing=true)</code></pre><p>Estimate ESS for Pareto-smoothed importance sampling.</p><div class="admonition is-info"><header class="admonition-header">Note</header><div class="admonition-body"><p>ESS estimates for Pareto shape values <span>$k &gt; 0.7$</span>, which are unreliable and misleadingly high, are set to <code>missing</code>. To avoid this, set <code>bad_shape_missing=false</code>.</p></div></div></div><a class="docs-sourcelink" target="_blank" href="https://github.com/arviz-devs/PSIS.jl/blob/e07c7150dafbad360202c2e07fc3ea0d862b8500/src/ess.jl#L1-L22">source</a></section></article><h2 id="Plotting"><a class="docs-heading-anchor" href="#Plotting">Plotting</a><a id="Plotting-1"></a><a class="docs-heading-anchor-permalink" href="#Plotting" title="Permalink"></a></h2><article class="docstring"><header><a class="docstring-binding" id="PSIS.PSISPlots" href="#PSIS.PSISPlots"><code>PSIS.PSISPlots</code></a><span class="docstring-category">Module</span></header><section><div><p>A module defining <a href="#PSIS.PSISPlots.paretoshapeplot"><code>paretoshapeplot</code></a> for plotting Pareto shape values with Plots.jl</p></div><a class="docs-sourcelink" target="_blank" href="https://github.com/arviz-devs/PSIS.jl/blob/e07c7150dafbad360202c2e07fc3ea0d862b8500/src/recipes/plots.jl#L3-L5">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="PSIS.PSISPlots.paretoshapeplot" href="#PSIS.PSISPlots.paretoshapeplot"><code>PSIS.PSISPlots.paretoshapeplot</code></a><span class="docstring-category">Function</span></header><section><div><pre><code class="language-julia hljs">paretoshapeplot(values; showlines=false, ...)
paretoshapeplot!(values; showlines=false, kwargs...)</code></pre><p>Plot shape parameters of fitted Pareto tail distributions for diagnosing convergence.</p><p><code>values</code> may be either a vector of Pareto shape parameters or a <a href="#PSIS.PSISResult"><code>PSIS.PSISResult</code></a>.</p><p>If <code>showlines==true</code>, horizontal lines indicating relevant Pareto shape thresholds are drawn. See <a href="#PSIS.PSISResult"><code>PSIS.PSISResult</code></a> for an explanation of the thresholds.</p><p>All remaining <code>kwargs</code> are forwarded to the plotting function.</p><p>See <a href="#PSIS.psis"><code>psis</code></a>, <a href="#PSIS.PSISResult"><code>PSISResult</code></a>.</p><p><strong>Examples</strong></p><pre><code class="language-julia hljs">using PSIS, Distributions, Plots
proposal = Normal()
target = TDist(7)
x = rand(proposal, 1_000, 100)
log_ratios = logpdf.(target, x) .- logpdf.(proposal, x)
result = psis(log_ratios)
paretoshapeplot(result)</code></pre><p>We can also plot the Pareto shape parameters directly:</p><pre><code class="language-julia hljs">paretoshapeplot(result.pareto_shape)</code></pre><p>We can also use <code>plot</code> directly:</p><pre><code class="language-julia hljs">plot(result.pareto_shape; showlines=true)</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/arviz-devs/PSIS.jl/blob/e07c7150dafbad360202c2e07fc3ea0d862b8500/src/recipes/plots.jl#L11-L49">source</a></section></article><section class="footnotes is-size-7"><ul><li class="footnote" id="footnote-VehtariSimpson2021"><a class="tag is-link" href="#citeref-VehtariSimpson2021">VehtariSimpson2021</a>Vehtari A, Simpson D, Gelman A, Yao Y, Gabry J. (2021). Pareto smoothed importance sampling. <a href="https://arxiv.org/abs/1507.02646v7">arXiv:1507.02646v7</a> [stat.CO]</li><li class="footnote" id="footnote-VehtariSimpson2021"><a class="tag is-link" href="#citeref-VehtariSimpson2021">VehtariSimpson2021</a>Vehtari A, Simpson D, Gelman A, Yao Y, Gabry J. (2021). Pareto smoothed importance sampling. <a href="https://arxiv.org/abs/1507.02646v7">arXiv:1507.02646v7</a> [stat.CO]</li></ul></section></article><nav class="docs-footer"><a class="docs-footer-prevpage" href="../plotting/">« Plotting</a><a class="docs-footer-nextpage" href="../internal/">Internal »</a><div class="flexbox-break"></div><p class="footer-message">Powered by <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> and the <a href="https://julialang.org/">Julia Programming Language</a>.</p></nav></div><div class="modal" id="documenter-settings"><div class="modal-background"></div><div class="modal-card"><header class="modal-card-head"><p class="modal-card-title">Settings</p><button class="delete"></button></header><section class="modal-card-body"><p><label class="label">Theme</label><div class="select"><select id="documenter-themepicker"><option value="documenter-light">documenter-light</option><option value="documenter-dark">documenter-dark</option></select></div></p><hr/><p>This document was generated with <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> version 0.27.24 on <span class="colophon-date" title="Friday 23 June 2023 23:14">Friday 23 June 2023</span>. Using Julia version 1.9.1.</p></section><footer class="modal-card-foot"></footer></div></div></div></body></html>
Loading

0 comments on commit da3f7bb

Please sign in to comment.