Skip to content

Commit

Permalink
build based on 3749df0
Browse files Browse the repository at this point in the history
  • Loading branch information
Documenter.jl committed Oct 28, 2023
1 parent f6100a8 commit 7172a06
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion dev/.documenter-siteinfo.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"documenter":{"julia_version":"1.9.3","generation_timestamp":"2023-10-26T19:27:02","documenter_version":"1.1.2"}}
{"documenter":{"julia_version":"1.9.3","generation_timestamp":"2023-10-28T09:39:07","documenter_version":"1.1.2"}}
4 changes: 2 additions & 2 deletions dev/api/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
Other allowed proposals are
</code></pre><p>p1 = StaticProposal(Normal(0,1)) p2 = StaticProposal([Normal(0,1), InverseGamma(2,3)]) p3 = StaticProposal((a=Normal(0,1), b=InverseGamma(2,3))) p4 = StaticProposal((x=1.0) -&gt; Normal(x, 1))</p><pre><code class="nohighlight hljs">
The sampler is constructed using
</code></pre><p>julia spl = MetropolisHastings(proposal) ```</p><p>When using <code>MetropolisHastings</code> with the function <code>sample</code>, the following keyword arguments are allowed:</p><ul><li><code>init_params</code> defines the initial parameterization for your model. If</li></ul><p>none is given, the initial parameters will be drawn from the sampler&#39;s proposals.</p><ul><li><code>param_names</code> is a vector of strings to be assigned to parameters. This is only</li></ul><p>used if <code>chain_type=Chains</code>.</p><ul><li><code>chain_type</code> is the type of chain you would like returned to you. Supported</li></ul><p>types are <code>chain_type=Chains</code> if <code>MCMCChains</code> is imported, or <code>chain_type=StructArray</code> if <code>StructArrays</code> is imported.</p></div><a class="docs-sourcelink" target="_blank" href="https://github.com/TuringLang/AdvancedMH.jl/blob/8ddb81ecbc47af63f26242693a7fe87bbf7bc6e0/src/mh-core.jl#L1-L43">source</a></section></article><h2 id="Functions"><a class="docs-heading-anchor" href="#Functions">Functions</a><a id="Functions-1"></a><a class="docs-heading-anchor-permalink" href="#Functions" title="Permalink"></a></h2><article class="docstring"><header><a class="docstring-article-toggle-button fa-solid fa-chevron-down" href="javascript:;" title="Collapse docstring"></a><a class="docstring-binding" id="AdvancedMH.DensityModel" href="#AdvancedMH.DensityModel"><code>AdvancedMH.DensityModel</code></a><span class="docstring-category">Type</span></header><section><div><pre><code class="language-julia hljs">DensityModel{F} &lt;: AbstractModel</code></pre><p><code>DensityModel</code> wraps around a self-contained log-liklihood function <code>logdensity</code>.</p><p>Example:</p><pre><code class="language-julia hljs">l(x) = logpdf(Normal(), x)
DensityModel(l)</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/TuringLang/AdvancedMH.jl/blob/8ddb81ecbc47af63f26242693a7fe87bbf7bc6e0/src/AdvancedMH.jl#L38-L49">source</a></section></article></article><nav class="docs-footer"><a class="docs-footer-prevpage" href="../">« AdvancedMH.jl</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><option value="auto">Automatic (OS)</option></select></div></p><hr/><p>This document was generated with <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> version 1.1.2 on <span class="colophon-date" title="Thursday 26 October 2023 19:27">Thursday 26 October 2023</span>. Using Julia version 1.9.3.</p></section><footer class="modal-card-foot"></footer></div></div></div></body></html>
</code></pre><p>julia spl = MetropolisHastings(proposal) ```</p><p>When using <code>MetropolisHastings</code> with the function <code>sample</code>, the following keyword arguments are allowed:</p><ul><li><code>initial_params</code> defines the initial parameterization for your model. If</li></ul><p>none is given, the initial parameters will be drawn from the sampler&#39;s proposals.</p><ul><li><code>param_names</code> is a vector of strings to be assigned to parameters. This is only</li></ul><p>used if <code>chain_type=Chains</code>.</p><ul><li><code>chain_type</code> is the type of chain you would like returned to you. Supported</li></ul><p>types are <code>chain_type=Chains</code> if <code>MCMCChains</code> is imported, or <code>chain_type=StructArray</code> if <code>StructArrays</code> is imported.</p></div><a class="docs-sourcelink" target="_blank" href="https://github.com/TuringLang/AdvancedMH.jl/blob/3749df0075ae59fc8bc4ef576a73ce770b75eec0/src/mh-core.jl#L1-L43">source</a></section></article><h2 id="Functions"><a class="docs-heading-anchor" href="#Functions">Functions</a><a id="Functions-1"></a><a class="docs-heading-anchor-permalink" href="#Functions" title="Permalink"></a></h2><article class="docstring"><header><a class="docstring-article-toggle-button fa-solid fa-chevron-down" href="javascript:;" title="Collapse docstring"></a><a class="docstring-binding" id="AdvancedMH.DensityModel" href="#AdvancedMH.DensityModel"><code>AdvancedMH.DensityModel</code></a><span class="docstring-category">Type</span></header><section><div><pre><code class="language-julia hljs">DensityModel{F} &lt;: AbstractModel</code></pre><p><code>DensityModel</code> wraps around a self-contained log-liklihood function <code>logdensity</code>.</p><p>Example:</p><pre><code class="language-julia hljs">l(x) = logpdf(Normal(), x)
DensityModel(l)</code></pre></div><a class="docs-sourcelink" target="_blank" href="https://github.com/TuringLang/AdvancedMH.jl/blob/3749df0075ae59fc8bc4ef576a73ce770b75eec0/src/AdvancedMH.jl#L38-L49">source</a></section></article></article><nav class="docs-footer"><a class="docs-footer-prevpage" href="../">« AdvancedMH.jl</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><option value="auto">Automatic (OS)</option></select></div></p><hr/><p>This document was generated with <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> version 1.1.2 on <span class="colophon-date" title="Saturday 28 October 2023 09:39">Saturday 28 October 2023</span>. Using Julia version 1.9.3.</p></section><footer class="modal-card-foot"></footer></div></div></div></body></html>
10 changes: 5 additions & 5 deletions dev/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@
p4 = StaticProposal((x=1.0) -&gt; Normal(x, 1))
c4 = sample(m4, MetropolisHastings(p4), 100; chain_type=Vector{NamedTuple})</code></pre><h2 id="Static-vs.-Random-Walk"><a class="docs-heading-anchor" href="#Static-vs.-Random-Walk">Static vs. Random Walk</a><a id="Static-vs.-Random-Walk-1"></a><a class="docs-heading-anchor-permalink" href="#Static-vs.-Random-Walk" title="Permalink"></a></h2><p>Currently there are only two methods of inference available. Static MH simply draws from the prior, with no conditioning on the previous sample. Random walk will add the proposal to the previously observed value. If you are constructing a <code>Proposal</code> by hand, you can determine whether the proposal is a <code>StaticProposal</code> or a <code>RandomWalkProposal</code> using</p><pre><code class="language-julia hljs">static_prop = StaticProposal(Normal(0,1))
rw_prop = RandomWalkProposal(Normal(0,1))</code></pre><p>Different methods are easily composeable. One parameter can be static and another can be a random walk, each of which may be drawn from separate distributions.</p><h2 id="Multiple-chains"><a class="docs-heading-anchor" href="#Multiple-chains">Multiple chains</a><a id="Multiple-chains-1"></a><a class="docs-heading-anchor-permalink" href="#Multiple-chains" title="Permalink"></a></h2><p>AdvancedMH.jl implements the interface of <a href="https://github.com/TuringLang/AbstractMCMC.jl/">AbstractMCMC</a> which means sampling of multiple chains is supported for free:</p><pre><code class="language-julia hljs"># Sample 4 chains from the posterior serially, without thread or process parallelism.
chain = sample(model, RWMH(init_params), MCMCSerial(), 100000, 4; param_names=[&quot;μ&quot;,&quot;σ&quot;], chain_type=Chains)
chain = sample(model, spl, MCMCSerial(), 100000, 4; param_names=[&quot;μ&quot;,&quot;σ&quot;], chain_type=Chains)

# Sample 4 chains from the posterior using multiple threads.
chain = sample(model, RWMH(init_params), MCMCThreads(), 100000, 4; param_names=[&quot;μ&quot;,&quot;σ&quot;], chain_type=Chains)
chain = sample(model, spl, MCMCThreads(), 100000, 4; param_names=[&quot;μ&quot;,&quot;σ&quot;], chain_type=Chains)

# Sample 4 chains from the posterior using multiple processes.
chain = sample(model, RWMH(init_params), MCMCDistributed(), 100000, 4; param_names=[&quot;μ&quot;,&quot;σ&quot;], chain_type=Chains)</code></pre><h2 id="Metropolis-adjusted-Langevin-algorithm-(MALA)"><a class="docs-heading-anchor" href="#Metropolis-adjusted-Langevin-algorithm-(MALA)">Metropolis-adjusted Langevin algorithm (MALA)</a><a id="Metropolis-adjusted-Langevin-algorithm-(MALA)-1"></a><a class="docs-heading-anchor-permalink" href="#Metropolis-adjusted-Langevin-algorithm-(MALA)" title="Permalink"></a></h2><p>AdvancedMH.jl also offers an implementation of <a href="https://en.wikipedia.org/wiki/Metropolis-adjusted_Langevin_algorithm">MALA</a> if the <code>ForwardDiff</code> and <code>DiffResults</code> packages are available. </p><p>A <code>MALA</code> sampler can be constructed by <code>MALA(proposal)</code> where <code>proposal</code> is a function that takes the gradient computed at the current sample. It is required to specify an initial sample <code>init_params</code> when calling <code>sample</code>.</p><pre><code class="language-julia hljs"># Import the package.
chain = sample(model, spl, MCMCDistributed(), 100000, 4; param_names=[&quot;μ&quot;,&quot;σ&quot;], chain_type=Chains)</code></pre><h2 id="Metropolis-adjusted-Langevin-algorithm-(MALA)"><a class="docs-heading-anchor" href="#Metropolis-adjusted-Langevin-algorithm-(MALA)">Metropolis-adjusted Langevin algorithm (MALA)</a><a id="Metropolis-adjusted-Langevin-algorithm-(MALA)-1"></a><a class="docs-heading-anchor-permalink" href="#Metropolis-adjusted-Langevin-algorithm-(MALA)" title="Permalink"></a></h2><p>AdvancedMH.jl also offers an implementation of <a href="https://en.wikipedia.org/wiki/Metropolis-adjusted_Langevin_algorithm">MALA</a> if the <code>ForwardDiff</code> and <code>DiffResults</code> packages are available. </p><p>A <code>MALA</code> sampler can be constructed by <code>MALA(proposal)</code> where <code>proposal</code> is a function that takes the gradient computed at the current sample. It is required to specify an initial sample <code>initial_params</code> when calling <code>sample</code>.</p><pre><code class="language-julia hljs"># Import the package.
using AdvancedMH
using Distributions
using MCMCChains
Expand All @@ -107,6 +107,6 @@
spl = MALA(x -&gt; MvNormal((σ² / 2) .* x, σ² * I))

# Sample from the posterior.
chain = sample(model, spl, 100000; init_params=ones(2), chain_type=StructArray, param_names=[&quot;μ&quot;, &quot;σ&quot;])</code></pre><h3 id="Usage-with-[LogDensityProblems.jl](https://github.com/tpapp/LogDensityProblems.jl)-2"><a class="docs-heading-anchor" href="#Usage-with-[LogDensityProblems.jl](https://github.com/tpapp/LogDensityProblems.jl)-2">Usage with <a href="https://github.com/tpapp/LogDensityProblems.jl"><code>LogDensityProblems.jl</code></a></a><a class="docs-heading-anchor-permalink" href="#Usage-with-[LogDensityProblems.jl](https://github.com/tpapp/LogDensityProblems.jl)-2" title="Permalink"></a></h3><p>As above, we can define the model with the LogDensityProblems.jl interface. We can implement the gradient of the log density function manually, or use <a href="https://github.com/tpapp/LogDensityProblemsAD.jl"><code>LogDensityProblemsAD.jl</code></a> to provide us with the gradient computation used in MALA. Using our implementation of the <code>LogDensityProblems.jl</code> interface above:</p><pre><code class="language-julia hljs">using LogDensityProblemsAD
chain = sample(model, spl, 100000; initial_params=ones(2), chain_type=StructArray, param_names=[&quot;μ&quot;, &quot;σ&quot;])</code></pre><h3 id="Usage-with-[LogDensityProblems.jl](https://github.com/tpapp/LogDensityProblems.jl)-2"><a class="docs-heading-anchor" href="#Usage-with-[LogDensityProblems.jl](https://github.com/tpapp/LogDensityProblems.jl)-2">Usage with <a href="https://github.com/tpapp/LogDensityProblems.jl"><code>LogDensityProblems.jl</code></a></a><a class="docs-heading-anchor-permalink" href="#Usage-with-[LogDensityProblems.jl](https://github.com/tpapp/LogDensityProblems.jl)-2" title="Permalink"></a></h3><p>As above, we can define the model with the LogDensityProblems.jl interface. We can implement the gradient of the log density function manually, or use <a href="https://github.com/tpapp/LogDensityProblemsAD.jl"><code>LogDensityProblemsAD.jl</code></a> to provide us with the gradient computation used in MALA. Using our implementation of the <code>LogDensityProblems.jl</code> interface above:</p><pre><code class="language-julia hljs">using LogDensityProblemsAD
model_with_ad = LogDensityProblemsAD.ADgradient(Val(:ForwardDiff), LogTargetDensity())
sample(model_with_ad, spl, 100000; init_params=ones(2), chain_type=StructArray, param_names=[&quot;μ&quot;, &quot;σ&quot;])</code></pre></article><nav class="docs-footer"><a class="docs-footer-nextpage" href="api/">AdvancedMH.jl »</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><option value="auto">Automatic (OS)</option></select></div></p><hr/><p>This document was generated with <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> version 1.1.2 on <span class="colophon-date" title="Thursday 26 October 2023 19:27">Thursday 26 October 2023</span>. Using Julia version 1.9.3.</p></section><footer class="modal-card-foot"></footer></div></div></div></body></html>
sample(model_with_ad, spl, 100000; initial_params=ones(2), chain_type=StructArray, param_names=[&quot;μ&quot;, &quot;σ&quot;])</code></pre></article><nav class="docs-footer"><a class="docs-footer-nextpage" href="api/">AdvancedMH.jl »</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><option value="auto">Automatic (OS)</option></select></div></p><hr/><p>This document was generated with <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> version 1.1.2 on <span class="colophon-date" title="Saturday 28 October 2023 09:39">Saturday 28 October 2023</span>. Using Julia version 1.9.3.</p></section><footer class="modal-card-foot"></footer></div></div></div></body></html>
Loading

0 comments on commit 7172a06

Please sign in to comment.