Skip to content

Commit

Permalink
build based on 0223de5
Browse files Browse the repository at this point in the history
  • Loading branch information
Documenter.jl committed Feb 3, 2025
1 parent 311869a commit f64c9e6
Show file tree
Hide file tree
Showing 73 changed files with 14,853 additions and 14,847 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.3","generation_timestamp":"2025-02-03T17:43:22","documenter_version":"1.8.0"}}
{"documenter":{"julia_version":"1.11.3","generation_timestamp":"2025-02-03T21:47:26","documenter_version":"1.8.0"}}
60 changes: 0 additions & 60 deletions dev/automatic_differentiation/0f07d459.svg

This file was deleted.

43 changes: 43 additions & 0 deletions dev/automatic_differentiation/635890df.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 0 additions & 43 deletions dev/automatic_differentiation/c3710182.svg

This file was deleted.

60 changes: 60 additions & 0 deletions dev/automatic_differentiation/c6065c9e.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
89 changes: 0 additions & 89 deletions dev/automatic_differentiation/e557258c.svg

This file was deleted.

89 changes: 89 additions & 0 deletions dev/automatic_differentiation/f765a552.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
82 changes: 41 additions & 41 deletions dev/automatic_differentiation/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,53 +12,53 @@
θ = [2.7, 0.27, 0.05, 3.0, 0.7, 0.25, 0.06 * SymBoltz.eV/SymBoltz.c^2, 2e-9, 0.95]
ks = 10 .^ range(-3, 0, length=100) / u"Mpc"
Ps = P(ks, θ)</code></pre><pre class="documenter-example-output"><code class="nohighlight hljs ansi">100-element Vector{Unitful.Quantity{Float64, 𝐋^3, Unitful.FreeUnits{(Mpc^3,), 𝐋^3, nothing}}}:
15162.137586395036 Mpc^3
16134.99180982436 Mpc^3
17162.999207019468 Mpc^3
18248.471187018036 Mpc^3
19392.898110437396 Mpc^3
20597.012346830328 Mpc^3
21865.38854848125 Mpc^3
23193.91023026567 Mpc^3
24589.047571269075 Mpc^3
26045.056925307545 Mpc^3
15158.89423165112 Mpc^3
16133.990934291065 Mpc^3
17162.018008985026 Mpc^3
18247.385905142164 Mpc^3
19390.17439782168 Mpc^3
20595.51044061744 Mpc^3
21862.503297769654 Mpc^3
23192.05702724878 Mpc^3
24587.37160215938 Mpc^3
26045.150779242704 Mpc^3
307.51732440732025 Mpc^3
262.8788688870413 Mpc^3
224.4792692965347 Mpc^3
191.43515606958212 Mpc^3
163.11483066913794 Mpc^3
138.81915708865478 Mpc^3
118.05203504182272 Mpc^3
100.28517603270468 Mpc^3
85.10501405337699 Mpc^3</code></pre><p>This can be plotted with</p><pre><code class="language-julia hljs">using Plots
plot(log10.(ks/u&quot;1/Mpc&quot;), log10.(Ps/u&quot;Mpc^3&quot;); xlabel = &quot;lg(k/Mpc⁻¹)&quot;, ylabel = &quot;lg(P/Mpc³)&quot;, label = nothing)</code></pre><img src="c3710182.svg" alt="Example block output"/><h2 id="2.-Calculate-the-derivatives"><a class="docs-heading-anchor" href="#2.-Calculate-the-derivatives">2. Calculate the derivatives</a><a id="2.-Calculate-the-derivatives-1"></a><a class="docs-heading-anchor-permalink" href="#2.-Calculate-the-derivatives" title="Permalink"></a></h2><p>To get <span>$\partial \lg P / \partial \lg \theta$</span>, we can simply pass the wrapper function <code>P(k, θ)</code> through <a href="https://juliadiff.org/ForwardDiff.jl/stable/user/api/#ForwardDiff.jacobian"><code>ForwardDiff.jacobian</code></a>:</p><pre><code class="language-julia hljs">using ForwardDiff
307.9655396983048 Mpc^3
263.32042044870326 Mpc^3
224.86677824648865 Mpc^3
191.7972991076235 Mpc^3
163.53972638179297 Mpc^3
139.14297913991282 Mpc^3
118.3293250470429 Mpc^3
100.53425202929114 Mpc^3
85.32704386935688 Mpc^3</code></pre><p>This can be plotted with</p><pre><code class="language-julia hljs">using Plots
plot(log10.(ks/u&quot;1/Mpc&quot;), log10.(Ps/u&quot;Mpc^3&quot;); xlabel = &quot;lg(k/Mpc⁻¹)&quot;, ylabel = &quot;lg(P/Mpc³)&quot;, label = nothing)</code></pre><img src="635890df.svg" alt="Example block output"/><h2 id="2.-Calculate-the-derivatives"><a class="docs-heading-anchor" href="#2.-Calculate-the-derivatives">2. Calculate the derivatives</a><a id="2.-Calculate-the-derivatives-1"></a><a class="docs-heading-anchor-permalink" href="#2.-Calculate-the-derivatives" title="Permalink"></a></h2><p>To get <span>$\partial \lg P / \partial \lg \theta$</span>, we can simply pass the wrapper function <code>P(k, θ)</code> through <a href="https://juliadiff.org/ForwardDiff.jl/stable/user/api/#ForwardDiff.jacobian"><code>ForwardDiff.jacobian</code></a>:</p><pre><code class="language-julia hljs">using ForwardDiff
lgP(lgθ) = log10.(P(ks, 10 .^ lgθ) / u&quot;Mpc^3&quot;) # in log-space
dlgP_dlgθs = ForwardDiff.jacobian(lgP, log10.(θ))</code></pre><pre class="documenter-example-output"><code class="nohighlight hljs ansi">100×9 Matrix{Float64}:
-0.122219 -1.24864 -0.230638 -0.0105005 … -0.00508994 1.0 -3.71642
-0.134237 -1.24578 -0.230109 -0.011655 -0.00499815 1.0 -3.65014
-0.14694 -1.23903 -0.22886 -0.012883 -0.00488705 1.0 -3.58385
-0.160982 -1.2332 -0.227782 -0.0142333 -0.00478024 1.0 -3.51756
-0.176278 -1.22669 -0.226573 -0.015708 -0.00467268 1.0 -3.45128
-0.192977 -1.21984 -0.225306 -0.0173148 … -0.00456875 1.0 -3.38499
-0.211068 -1.21225 -0.223896 -0.0190574 -0.00447107 1.0 -3.3187
-0.230719 -1.20366 -0.222317 -0.0209459 -0.00438232 1.0 -3.25242
-0.252091 -1.19533 -0.220783 -0.0230063 -0.00431301 1.0 -3.18613
-0.27496 -1.18517 -0.218906 -0.0252122 -0.00425969 1.0 -3.11984
-0.122984 -1.2517 -0.231232 -0.0105532 … -0.00510308 1.0 -3.71642
-0.134376 -1.24393 -0.229794 -0.0116581 -0.00498988 1.0 -3.65014
-0.147123 -1.23905 -0.228875 -0.0128933 -0.00488714 1.0 -3.58385
-0.161282 -1.23344 -0.227834 -0.0142563 -0.0047812 1.0 -3.51756
-0.176537 -1.22685 -0.226621 -0.0157221 -0.00467328 1.0 -3.45128
-0.193149 -1.22043 -0.225419 -0.0173279 … -0.00457128 1.0 -3.38499
-0.211247 -1.21204 -0.223876 -0.0190661 -0.00447009 1.0 -3.3187
-0.231005 -1.20497 -0.222569 -0.0209666 -0.00438787 1.0 -3.25242
-0.252326 -1.1953 -0.220788 -0.0230183 -0.00431307 1.0 -3.18613
-0.275537 -1.18711 -0.219289 -0.0252501 -0.00426818 1.0 -3.11984
⋮ ⋱
-5.96375 1.90586 -0.396415 -0.467775 -0.0298509 1.0 2.31565
-5.99475 1.92316 -0.39715 -0.468714 -0.0298629 1.0 2.38194
-6.02517 1.9392 -0.398055 -0.469897 -0.0298739 1.0 2.44823
-6.05709 1.95456 -0.39812 -0.471019 -0.0298845 1.0 2.51451
-6.08686 1.97052 -0.398356 -0.471977 … -0.0298898 1.0 2.5808
-6.11672 1.98519 -0.398297 -0.472992 -0.0298966 1.0 2.64709
-6.14488 1.99962 -0.398602 -0.473816 -0.0299034 1.0 2.71337
-6.17217 2.0135 -0.398721 -0.47465 -0.0299085 1.0 2.77966
-6.1982 2.02687 -0.399162 -0.475427 -0.0299135 1.0 2.84595</code></pre><p>The matrix element <code>dlgP_dlgθs[i, j]</code> now contains <span>$\partial \lg P(k_i) / \partial \lg \theta_j$</span>. We can plot them all at once:</p><pre><code class="language-julia hljs">plot(
-5.96387 1.90595 -0.396278 -0.46785 -0.0298509 1.0 2.31565
-5.99425 1.92334 -0.397478 -0.468922 -0.0298623 1.0 2.38194
-6.02818 1.93856 -0.397474 -0.470402 -0.029874 1.0 2.44823
-6.05838 1.95508 -0.398049 -0.471324 -0.029882 1.0 2.51451
-6.0884 1.97025 -0.398015 -0.472262 … -0.0298906 1.0 2.5808
-6.1172 1.98441 -0.398588 -0.473238 -0.0299002 1.0 2.64709
-6.14564 1.99962 -0.398671 -0.474144 -0.0299033 1.0 2.71337
-6.17344 2.01338 -0.398892 -0.475132 -0.0299086 1.0 2.77966
-6.19947 2.02695 -0.399119 -0.475828 -0.0299133 1.0 2.84595</code></pre><p>The matrix element <code>dlgP_dlgθs[i, j]</code> now contains <span>$\partial \lg P(k_i) / \partial \lg \theta_j$</span>. We can plot them all at once:</p><pre><code class="language-julia hljs">plot(
log10.(ks/u&quot;1/Mpc&quot;), dlgP_dlgθs;
xlabel = &quot;lg(k/Mpc⁻¹)&quot;, ylabel = &quot;∂ lg(P) / ∂ lg(θᵢ)&quot;,
labels = &quot;θᵢ=&quot; .* [&quot;Tγ0&quot; &quot;Ωc0&quot; &quot;Ωb0&quot; &quot;Neff&quot; &quot;h&quot; &quot;Yp&quot; &quot;mh&quot; &quot;As&quot; &quot;ns&quot; &quot;ΩΛ0&quot;]
)</code></pre><img src="0f07d459.svg" alt="Example block output"/><h2 id="Get-values-and-derivatives-together"><a class="docs-heading-anchor" href="#Get-values-and-derivatives-together">Get values and derivatives together</a><a id="Get-values-and-derivatives-together-1"></a><a class="docs-heading-anchor-permalink" href="#Get-values-and-derivatives-together" title="Permalink"></a></h2><p>The above example showed how to calculate the power spectrum <em>values</em> and their <em>derivatives</em> through <em>two separate calls</em>. If you need both, it is faster to calculate them simultaneously with the package <a href="https://juliadiff.org/DiffResults.jl/stable/"><code>DiffResults.jl</code></a>:</p><pre><code class="language-julia hljs">using DiffResults
)</code></pre><img src="c6065c9e.svg" alt="Example block output"/><h2 id="Get-values-and-derivatives-together"><a class="docs-heading-anchor" href="#Get-values-and-derivatives-together">Get values and derivatives together</a><a id="Get-values-and-derivatives-together-1"></a><a class="docs-heading-anchor-permalink" href="#Get-values-and-derivatives-together" title="Permalink"></a></h2><p>The above example showed how to calculate the power spectrum <em>values</em> and their <em>derivatives</em> through <em>two separate calls</em>. If you need both, it is faster to calculate them simultaneously with the package <a href="https://juliadiff.org/DiffResults.jl/stable/"><code>DiffResults.jl</code></a>:</p><pre><code class="language-julia hljs">using DiffResults

# Following DiffResults documentation:
Pres = DiffResults.JacobianResult(ks/u&quot;1/Mpc&quot;, θ) # allocate buffer for values+derivatives for a function with θ-sized input and ks-sized output
Expand All @@ -75,4 +75,4 @@
xlabel = &quot;lg(k/Mpc⁻¹)&quot;, ylabel = &quot;∂ lg(P) / ∂ lg(θᵢ)&quot;,
labels = &quot;θᵢ=&quot; .* [&quot;Tγ0&quot; &quot;Ωc0&quot; &quot;Ωb0&quot; &quot;Neff&quot; &quot;h&quot; &quot;Yp&quot; &quot;mh&quot; &quot;As&quot; &quot;ns&quot; &quot;ΩΛ0&quot;]
)
plot(p1, p2, layout=(2, 1), size = (600, 600))</code></pre><img src="e557258c.svg" alt="Example block output"/><h2 id="General-approach"><a class="docs-heading-anchor" href="#General-approach">General approach</a><a id="General-approach-1"></a><a class="docs-heading-anchor-permalink" href="#General-approach" title="Permalink"></a></h2><p>The technique shown here can be used to calculate the derivative of any SymBoltz.jl output quantity:</p><ol><li>Write a wrapper function <code>output(input)</code> that calculates the desired output quantities from the desired input quantities.</li><li>Use <a href="https://juliadiff.org/ForwardDiff.jl/stable/user/api/#ForwardDiff.derivative"><code>ForwardDiff.derivative(output, input)</code></a> (scalar-to-scalar), <a href="https://juliadiff.org/ForwardDiff.jl/stable/user/api/#ForwardDiff.gradient"><code>ForwardDiff.gradient(output, input)</code></a> (vector-to-scalar) or <a href="https://juliadiff.org/ForwardDiff.jl/stable/user/api/#ForwardDiff.jacobian"><code>ForwardDiff.jacobian(output, input)</code></a> (vector-to-vector) to evaluate the derivative of <code>output</code> at the values <code>input</code>. Or use the similar functions in <a href="https://juliadiff.org/DiffResults.jl/stable/"><code>DiffResults</code></a> to calculate the value <em>and</em> derivatives simultaneously.</li></ol></article><nav class="docs-footer"><a class="docs-footer-prevpage" href="../getting_started/">« Getting started</a><a class="docs-footer-nextpage" href="../extended_models/">Creating extended models »</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="Monday 3 February 2025 17:42">Monday 3 February 2025</span>. Using Julia version 1.11.3.</p></section><footer class="modal-card-foot"></footer></div></div></div></body></html>
plot(p1, p2, layout=(2, 1), size = (600, 600))</code></pre><img src="f765a552.svg" alt="Example block output"/><h2 id="General-approach"><a class="docs-heading-anchor" href="#General-approach">General approach</a><a id="General-approach-1"></a><a class="docs-heading-anchor-permalink" href="#General-approach" title="Permalink"></a></h2><p>The technique shown here can be used to calculate the derivative of any SymBoltz.jl output quantity:</p><ol><li>Write a wrapper function <code>output(input)</code> that calculates the desired output quantities from the desired input quantities.</li><li>Use <a href="https://juliadiff.org/ForwardDiff.jl/stable/user/api/#ForwardDiff.derivative"><code>ForwardDiff.derivative(output, input)</code></a> (scalar-to-scalar), <a href="https://juliadiff.org/ForwardDiff.jl/stable/user/api/#ForwardDiff.gradient"><code>ForwardDiff.gradient(output, input)</code></a> (vector-to-scalar) or <a href="https://juliadiff.org/ForwardDiff.jl/stable/user/api/#ForwardDiff.jacobian"><code>ForwardDiff.jacobian(output, input)</code></a> (vector-to-vector) to evaluate the derivative of <code>output</code> at the values <code>input</code>. Or use the similar functions in <a href="https://juliadiff.org/DiffResults.jl/stable/"><code>DiffResults</code></a> to calculate the value <em>and</em> derivatives simultaneously.</li></ol></article><nav class="docs-footer"><a class="docs-footer-prevpage" href="../getting_started/">« Getting started</a><a class="docs-footer-nextpage" href="../extended_models/">Creating extended models »</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="Monday 3 February 2025 21:46">Monday 3 February 2025</span>. Using Julia version 1.11.3.</p></section><footer class="modal-card-foot"></footer></div></div></div></body></html>
Loading

0 comments on commit f64c9e6

Please sign in to comment.