Skip to content

Commit

Permalink
build based on e9f5de4
Browse files Browse the repository at this point in the history
  • Loading branch information
Documenter.jl committed Nov 15, 2024
1 parent 162ecfc commit 1cd4769
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 42 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.11.1","generation_timestamp":"2024-11-15T18:02:08","documenter_version":"1.8.0"}}
{"documenter":{"julia_version":"1.11.1","generation_timestamp":"2024-11-15T18:46:10","documenter_version":"1.8.0"}}
2 changes: 1 addition & 1 deletion dev/alternatives/index.html

Large diffs are not rendered by default.

44 changes: 22 additions & 22 deletions dev/api/index.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dev/debugging/index.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dev/examples/autodiff/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,4 @@
)
catch exception # latest release of Enzyme broke this code
display(exception)
end</code></pre><pre class="documenter-example-output"><code class="nohighlight hljs ansi">((nothing, nothing, nothing, nothing),)</code></pre><p>Once again we can check the results.</p><pre><code class="language-julia hljs">∇parameters_enzyme ≈ ∇parameters_forwarddiff</code></pre><pre class="documenter-example-output"><code class="nohighlight hljs ansi">true</code></pre><pre><code class="language-julia hljs">∇obs_enzyme ≈ ∇obs_forwarddiff</code></pre><pre class="documenter-example-output"><code class="nohighlight hljs ansi">true</code></pre><pre><code class="language-julia hljs">∇control_enzyme ≈ ∇control_forwarddiff</code></pre><pre class="documenter-example-output"><code class="nohighlight hljs ansi">true</code></pre><p>For increased efficiency, we could provide temporary storage to Enzyme.jl in order to avoid allocations. This requires going one level deeper and leveraging the in-place <a href="../../api/#HiddenMarkovModels.forward!"><code>HiddenMarkovModels.forward!</code></a> function.</p><h2 id="Gradient-methods"><a class="docs-heading-anchor" href="#Gradient-methods">Gradient methods</a><a id="Gradient-methods-1"></a><a class="docs-heading-anchor-permalink" href="#Gradient-methods" title="Permalink"></a></h2><p>Once we have gradients of the loglikelihood, it is a natural idea to perform gradient descent in order to fit the parameters of a custom HMM. However, there are two caveats we must keep in mind.</p><p>First, computing a gradient essentially requires running the forward-backward algorithm, which means it is expensive. Given the output of forward-backward, if there is a way to perform a more accurate parameter update (like going straight to the maximum likelihood value), it is probably worth it. That is what we show in the other tutorials with the reimplementation of the <code>fit!</code> method.</p><p>Second, HMM parameters live in a constrained space, which calls for a projected gradient descent. Most notably, the transition matrix must be stochastic, and the orthogonal projection onto this set (the Birkhoff polytope) is not easy to obtain.</p><p>Still, first order optimization can be relevant when we lack explicit formulas for maximum likelihood.</p><hr/><p><em>This page was generated using <a href="https://github.com/fredrikekre/Literate.jl">Literate.jl</a>.</em></p></article><nav class="docs-footer"><a class="docs-footer-prevpage" href="../controlled/">« Control dependency</a><a class="docs-footer-nextpage" href="../../api/">API reference »</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="auto">Automatic (OS)</option><option value="documenter-light">documenter-light</option><option value="documenter-dark">documenter-dark</option><option value="catppuccin-latte">catppuccin-latte</option><option value="catppuccin-frappe">catppuccin-frappe</option><option value="catppuccin-macchiato">catppuccin-macchiato</option><option value="catppuccin-mocha">catppuccin-mocha</option></select></div></p><hr/><p>This document was generated with <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> version 1.8.0 on <span class="colophon-date" title="Friday 15 November 2024 18:02">Friday 15 November 2024</span>. Using Julia version 1.11.1.</p></section><footer class="modal-card-foot"></footer></div></div></div></body></html>
end</code></pre><pre class="documenter-example-output"><code class="nohighlight hljs ansi">((nothing, nothing, nothing, nothing),)</code></pre><p>Once again we can check the results.</p><pre><code class="language-julia hljs">∇parameters_enzyme ≈ ∇parameters_forwarddiff</code></pre><pre class="documenter-example-output"><code class="nohighlight hljs ansi">true</code></pre><pre><code class="language-julia hljs">∇obs_enzyme ≈ ∇obs_forwarddiff</code></pre><pre class="documenter-example-output"><code class="nohighlight hljs ansi">true</code></pre><pre><code class="language-julia hljs">∇control_enzyme ≈ ∇control_forwarddiff</code></pre><pre class="documenter-example-output"><code class="nohighlight hljs ansi">true</code></pre><p>For increased efficiency, we could provide temporary storage to Enzyme.jl in order to avoid allocations. This requires going one level deeper and leveraging the in-place <a href="../../api/#HiddenMarkovModels.forward!"><code>HiddenMarkovModels.forward!</code></a> function.</p><h2 id="Gradient-methods"><a class="docs-heading-anchor" href="#Gradient-methods">Gradient methods</a><a id="Gradient-methods-1"></a><a class="docs-heading-anchor-permalink" href="#Gradient-methods" title="Permalink"></a></h2><p>Once we have gradients of the loglikelihood, it is a natural idea to perform gradient descent in order to fit the parameters of a custom HMM. However, there are two caveats we must keep in mind.</p><p>First, computing a gradient essentially requires running the forward-backward algorithm, which means it is expensive. Given the output of forward-backward, if there is a way to perform a more accurate parameter update (like going straight to the maximum likelihood value), it is probably worth it. That is what we show in the other tutorials with the reimplementation of the <code>fit!</code> method.</p><p>Second, HMM parameters live in a constrained space, which calls for a projected gradient descent. Most notably, the transition matrix must be stochastic, and the orthogonal projection onto this set (the Birkhoff polytope) is not easy to obtain.</p><p>Still, first order optimization can be relevant when we lack explicit formulas for maximum likelihood.</p><hr/><p><em>This page was generated using <a href="https://github.com/fredrikekre/Literate.jl">Literate.jl</a>.</em></p></article><nav class="docs-footer"><a class="docs-footer-prevpage" href="../controlled/">« Control dependency</a><a class="docs-footer-nextpage" href="../../api/">API reference »</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="auto">Automatic (OS)</option><option value="documenter-light">documenter-light</option><option value="documenter-dark">documenter-dark</option><option value="catppuccin-latte">catppuccin-latte</option><option value="catppuccin-frappe">catppuccin-frappe</option><option value="catppuccin-macchiato">catppuccin-macchiato</option><option value="catppuccin-mocha">catppuccin-mocha</option></select></div></p><hr/><p>This document was generated with <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> version 1.8.0 on <span class="colophon-date" title="Friday 15 November 2024 18:46">Friday 15 November 2024</span>. Using Julia version 1.11.1.</p></section><footer class="modal-card-foot"></footer></div></div></div></body></html>
2 changes: 1 addition & 1 deletion dev/examples/basics/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@
[-0.502073, -0.800874] [-0.5, -0.8]
[0.504019, 0.801399] [0.5, 0.8]</code></pre><pre><code class="language-julia hljs">hcat(initialization(hmm_est_concat), initialization(hmm))</code></pre><pre class="documenter-example-output"><code class="nohighlight hljs ansi">2×2 Matrix{Float64}:
0.605645 0.6
0.394355 0.4</code></pre><hr/><p><em>This page was generated using <a href="https://github.com/fredrikekre/Literate.jl">Literate.jl</a>.</em></p></article><nav class="docs-footer"><a class="docs-footer-prevpage" href="../../">« Home</a><a class="docs-footer-nextpage" href="../types/">Types »</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="auto">Automatic (OS)</option><option value="documenter-light">documenter-light</option><option value="documenter-dark">documenter-dark</option><option value="catppuccin-latte">catppuccin-latte</option><option value="catppuccin-frappe">catppuccin-frappe</option><option value="catppuccin-macchiato">catppuccin-macchiato</option><option value="catppuccin-mocha">catppuccin-mocha</option></select></div></p><hr/><p>This document was generated with <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> version 1.8.0 on <span class="colophon-date" title="Friday 15 November 2024 18:02">Friday 15 November 2024</span>. Using Julia version 1.11.1.</p></section><footer class="modal-card-foot"></footer></div></div></div></body></html>
0.394355 0.4</code></pre><hr/><p><em>This page was generated using <a href="https://github.com/fredrikekre/Literate.jl">Literate.jl</a>.</em></p></article><nav class="docs-footer"><a class="docs-footer-prevpage" href="../../">« Home</a><a class="docs-footer-nextpage" href="../types/">Types »</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="auto">Automatic (OS)</option><option value="documenter-light">documenter-light</option><option value="documenter-dark">documenter-dark</option><option value="catppuccin-latte">catppuccin-latte</option><option value="catppuccin-frappe">catppuccin-frappe</option><option value="catppuccin-macchiato">catppuccin-macchiato</option><option value="catppuccin-mocha">catppuccin-mocha</option></select></div></p><hr/><p>This document was generated with <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> version 1.8.0 on <span class="colophon-date" title="Friday 15 November 2024 18:46">Friday 15 November 2024</span>. Using Julia version 1.11.1.</p></section><footer class="modal-card-foot"></footer></div></div></div></body></html>
20 changes: 10 additions & 10 deletions dev/examples/controlled/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

obs_seq = reduce(vcat, obs_seqs)
control_seq = reduce(vcat, control_seqs)
seq_ends = cumsum(length.(obs_seqs));</code></pre><h2 id="Inference"><a class="docs-heading-anchor" href="#Inference">Inference</a><a id="Inference-1"></a><a class="docs-heading-anchor-permalink" href="#Inference" title="Permalink"></a></h2><p>Not much changes from the case with simple time dependency.</p><pre><code class="language-julia hljs">best_state_seq, _ = viterbi(hmm, obs_seq, control_seq; seq_ends)</code></pre><pre class="documenter-example-output"><code class="nohighlight hljs ansi">([1, 2, 2, 1, 2, 2, 2, 2, 2, 1 … 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [-344.7790148198882, -223.82732004718883, -331.36599696657885, -197.51665639052405, -294.0827379336244, -278.7947390546642, -250.68289605296098, -281.57658598104064, -305.70621553729995, -238.39304432204213 … -281.97904160944717, -313.2338726086644, -350.63062019739084, -323.28422763269594, -327.50923807468325, -273.53391195525643, -272.8967204043988, -314.1175220210592, -297.3956575816454, -306.6511540999502])</code></pre><h2 id="Learning"><a class="docs-heading-anchor" href="#Learning">Learning</a><a id="Learning-1"></a><a class="docs-heading-anchor-permalink" href="#Learning" title="Permalink"></a></h2><p>Once more, we override the <code>fit!</code> function. The state-related parameters are estimated in the standard way. Meanwhile, the observation coefficients are given by the formula for <a href="https://en.wikipedia.org/wiki/Weighted_least_squares">weighted least squares</a>.</p><pre><code class="language-julia hljs">function StatsAPI.fit!(
seq_ends = cumsum(length.(obs_seqs));</code></pre><h2 id="Inference"><a class="docs-heading-anchor" href="#Inference">Inference</a><a id="Inference-1"></a><a class="docs-heading-anchor-permalink" href="#Inference" title="Permalink"></a></h2><p>Not much changes from the case with simple time dependency.</p><pre><code class="language-julia hljs">best_state_seq, _ = viterbi(hmm, obs_seq, control_seq; seq_ends)</code></pre><pre class="documenter-example-output"><code class="nohighlight hljs ansi">([2, 2, 2, 2, 2, 2, 1, 1, 2, 2 … 2, 2, 2, 2, 2, 2, 2, 2, 1, 1], [-287.5946062079405, -202.816460131175, -351.8367517305944, -231.3179315705743, -210.25252350490103, -248.07072420255523, -238.77333732669916, -355.1692176926718, -351.01276734171455, -249.74425888408467 … -333.5165041058419, -351.7651745673535, -268.65676473979, -362.58078050044634, -292.4588312689585, -228.90328578153196, -188.8032138610884, -384.02629368052266, -366.6043501299414, -361.4329206249749])</code></pre><h2 id="Learning"><a class="docs-heading-anchor" href="#Learning">Learning</a><a id="Learning-1"></a><a class="docs-heading-anchor-permalink" href="#Learning" title="Permalink"></a></h2><p>Once more, we override the <code>fit!</code> function. The state-related parameters are estimated in the standard way. Meanwhile, the observation coefficients are given by the formula for <a href="https://en.wikipedia.org/wiki/Weighted_least_squares">weighted least squares</a>.</p><pre><code class="language-julia hljs">function StatsAPI.fit!(
hmm::ControlledGaussianHMM{T},
fb_storage::HMMs.ForwardBackwardStorage,
obs_seq::AbstractVector,
Expand Down Expand Up @@ -60,17 +60,17 @@
trans_guess = [0.6 0.4; 0.3 0.7]
dist_coeffs_guess = [-1.1 * ones(d), 1.1 * ones(d)]
hmm_guess = ControlledGaussianHMM(init_guess, trans_guess, dist_coeffs_guess);</code></pre><pre><code class="language-julia hljs">hmm_est, loglikelihood_evolution = baum_welch(hmm_guess, obs_seq, control_seq; seq_ends)
first(loglikelihood_evolution), last(loglikelihood_evolution)</code></pre><pre class="documenter-example-output"><code class="nohighlight hljs ansi">(-264372.44002048456, -260871.19436194317)</code></pre><p>How did we perform?</p><pre><code class="language-julia hljs">cat(hmm_est.trans, hmm.trans; dims=3)</code></pre><pre class="documenter-example-output"><code class="nohighlight hljs ansi">2×2×2 Array{Float64, 3}:
first(loglikelihood_evolution), last(loglikelihood_evolution)</code></pre><pre class="documenter-example-output"><code class="nohighlight hljs ansi">(-264966.12308636686, -261495.8836762496)</code></pre><p>How did we perform?</p><pre><code class="language-julia hljs">cat(hmm_est.trans, hmm.trans; dims=3)</code></pre><pre class="documenter-example-output"><code class="nohighlight hljs ansi">2×2×2 Array{Float64, 3}:
[:, :, 1] =
0.696353 0.303647
0.200603 0.799397
0.699326 0.300674
0.200752 0.799248

[:, :, 2] =
0.7 0.3
0.2 0.8</code></pre><pre><code class="language-julia hljs">hcat(hmm_est.dist_coeffs[1], hmm.dist_coeffs[1])</code></pre><pre class="documenter-example-output"><code class="nohighlight hljs ansi">3×2 Matrix{Float64}:
-0.997503 -1.0
-0.998396 -1.0
-1.00666 -1.0</code></pre><pre><code class="language-julia hljs">hcat(hmm_est.dist_coeffs[2], hmm.dist_coeffs[2])</code></pre><pre class="documenter-example-output"><code class="nohighlight hljs ansi">3×2 Matrix{Float64}:
1.00433 1.0
0.995292 1.0
1.00029 1.0</code></pre><hr/><p><em>This page was generated using <a href="https://github.com/fredrikekre/Literate.jl">Literate.jl</a>.</em></p></article><nav class="docs-footer"><a class="docs-footer-prevpage" href="../temporal/">« Time dependency</a><a class="docs-footer-nextpage" href="../autodiff/">Autodiff »</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="auto">Automatic (OS)</option><option value="documenter-light">documenter-light</option><option value="documenter-dark">documenter-dark</option><option value="catppuccin-latte">catppuccin-latte</option><option value="catppuccin-frappe">catppuccin-frappe</option><option value="catppuccin-macchiato">catppuccin-macchiato</option><option value="catppuccin-mocha">catppuccin-mocha</option></select></div></p><hr/><p>This document was generated with <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> version 1.8.0 on <span class="colophon-date" title="Friday 15 November 2024 18:02">Friday 15 November 2024</span>. Using Julia version 1.11.1.</p></section><footer class="modal-card-foot"></footer></div></div></div></body></html>
-0.990972 -1.0
-1.00796 -1.0
-0.997021 -1.0</code></pre><pre><code class="language-julia hljs">hcat(hmm_est.dist_coeffs[2], hmm.dist_coeffs[2])</code></pre><pre class="documenter-example-output"><code class="nohighlight hljs ansi">3×2 Matrix{Float64}:
1.00427 1.0
1.00823 1.0
1.00062 1.0</code></pre><hr/><p><em>This page was generated using <a href="https://github.com/fredrikekre/Literate.jl">Literate.jl</a>.</em></p></article><nav class="docs-footer"><a class="docs-footer-prevpage" href="../temporal/">« Time dependency</a><a class="docs-footer-nextpage" href="../autodiff/">Autodiff »</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="auto">Automatic (OS)</option><option value="documenter-light">documenter-light</option><option value="documenter-dark">documenter-dark</option><option value="catppuccin-latte">catppuccin-latte</option><option value="catppuccin-frappe">catppuccin-frappe</option><option value="catppuccin-macchiato">catppuccin-macchiato</option><option value="catppuccin-mocha">catppuccin-mocha</option></select></div></p><hr/><p>This document was generated with <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> version 1.8.0 on <span class="colophon-date" title="Friday 15 November 2024 18:46">Friday 15 November 2024</span>. Using Julia version 1.11.1.</p></section><footer class="modal-card-foot"></footer></div></div></div></body></html>
Loading

0 comments on commit 1cd4769

Please sign in to comment.