-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Documenter.jl
committed
Dec 20, 2023
1 parent
41464c3
commit 28ecab3
Showing
46 changed files
with
6,517 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
v2.5.2 | ||
v2.6.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
v2.5.2 | ||
v2.6.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
v2.6.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"documenter":{"julia_version":"1.9.4","generation_timestamp":"2023-12-20T19:10:50","documenter_version":"1.2.1"}} |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"><head><meta charset="UTF-8"/><meta name="viewport" content="width=device-width, initial-scale=1.0"/><title>Medium sized models and adjoint sensitivity analysis · PEtab.jl</title><meta name="title" content="Medium sized models and adjoint sensitivity analysis · PEtab.jl"/><meta property="og:title" content="Medium sized models and adjoint sensitivity analysis · PEtab.jl"/><meta property="twitter:title" content="Medium sized models and adjoint sensitivity analysis · PEtab.jl"/><meta name="description" content="Documentation for PEtab.jl."/><meta property="og:description" content="Documentation for PEtab.jl."/><meta property="twitter:description" content="Documentation for PEtab.jl."/><meta property="og:url" content="https://sebapersson.github.io/PEtab.jl/Bachmann/"/><meta property="twitter:url" content="https://sebapersson.github.io/PEtab.jl/Bachmann/"/><link rel="canonical" href="https://sebapersson.github.io/PEtab.jl/Bachmann/"/><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.050/juliamono.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/fontawesome.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/solid.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/brands.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.16.8/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="../search_index.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="../">PEtab.jl</a></span></div><button class="docs-search-query input is-rounded is-small is-clickable my-2 mx-auto py-1 px-2" id="documenter-search-query">Search docs (Ctrl + /)</button><ul class="docs-menu"><li><a class="tocitem" href="../">Home</a></li><li><a class="tocitem" href="../Boehm/">Importing problems in PEtab standard format</a></li><li><span class="tocitem">Defining a PEtab problem in Julia</span><ul><li><a class="tocitem" href="../Define_in_julia/">Defining parameter estimation problems in Julia</a></li><li><a class="tocitem" href="../Julia_steady_state/">Pre-equilibration (steady-state simulations)</a></li><li><a class="tocitem" href="../Julia_obs_noise/">Noise and observable parameters</a></li><li><a class="tocitem" href="../Julia_condition_specific/">Condition specific system/model parameters</a></li><li><a class="tocitem" href="../Julia_event/">Events (callbacks, dosages etc...)</a></li></ul></li><li><span class="tocitem">Options for specific problem types</span><ul><li><a class="tocitem" href="../Brannmark/">Models with pre-equilibration (steady-state simulation)</a></li><li class="is-active"><a class="tocitem" href>Medium sized models and adjoint sensitivity analysis</a><ul class="internal"><li><a class="tocitem" href="#Adjoint-sensitivity-analysis"><span>Adjoint sensitivity analysis</span></a></li><li><a class="tocitem" href="#Forward-sensitivity-analysis-and-Gauss-Newton-hessian-approximation"><span>Forward sensitivity analysis and Gauss-Newton hessian approximation</span></a></li></ul></li><li><a class="tocitem" href="../Beer/">Models with many conditions specific parameters</a></li></ul></li><li><span class="tocitem">Parameter estimation</span><ul><li><a class="tocitem" href="../Parameter_estimation/">Parameter estimation</a></li><li><a class="tocitem" href="../Avaible_optimisers/">Available optimisers</a></li><li><a class="tocitem" href="../Model_selection/">Model selection (PEtab select)</a></li><li><a class="tocitem" href="../optimisation_output_plotting/">Plots evaluating parameter estimation</a></li></ul></li><li><a class="tocitem" href="../Gradient_hessian_support/">Supported gradient and hessian methods</a></li><li><a class="tocitem" href="../Best_options/">Choosing the best options for a PEtab problem</a></li><li><a class="tocitem" href="../API_choosen/">API</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"><a class="docs-sidebar-button docs-navbar-link fa-solid fa-bars is-hidden-desktop" id="documenter-sidebar-button" href="#"></a><nav class="breadcrumb"><ul class="is-hidden-mobile"><li><a class="is-disabled">Options for specific problem types</a></li><li class="is-active"><a href>Medium sized models and adjoint sensitivity analysis</a></li></ul><ul class="is-hidden-tablet"><li class="is-active"><a href>Medium sized models and adjoint sensitivity analysis</a></li></ul></nav><div class="docs-right"><a class="docs-navbar-link" href="https://github.com/sebapersson/PEtab.jl/blob/main/docs/src/Bachmann.md#" title="Edit source on GitHub"><span class="docs-icon fa-solid"></span></a><a class="docs-settings-button docs-navbar-link fa-solid fa-gear" id="documenter-settings-button" href="#" title="Settings"></a><a class="docs-article-toggle-button fa-solid fa-chevron-up" id="documenter-article-toggle-button" href="javascript:;" title="Collapse all docstrings"></a></div></header><article class="content" id="documenter-page"><h1 id="Medium-sized-models-(Bachmann-model)"><a class="docs-heading-anchor" href="#Medium-sized-models-(Bachmann-model)">Medium-sized models (Bachmann model)</a><a id="Medium-sized-models-(Bachmann-model)-1"></a><a class="docs-heading-anchor-permalink" href="#Medium-sized-models-(Bachmann-model)" title="Permalink"></a></h1><p>In this tutorial we will crate a <code>PEtabODEproblem</code> for the Bachmann model, a medium-sized ODE model. We will cover three topics:</p><ol><li>Computing the gradient via forward-sensitivity equations</li><li>Computing the gradient via adjoint sensitivity analysis</li><li>Computing the Gauss-Newton Hessian approximation, which often performs better than the (L)-BFGS Hessian approximation.</li></ol><p>To run the code, you need the Bachmann PEtab files, which can be found <a href="https://github.com/sebapersson/PEtab.jl/tree/main/examples/Bachmann">here</a>. You can find a fully runnable example of this tutorial <a href="https://github.com/sebapersson/PEtab.jl/tree/main/examples/Bachmann.jl">here</a>.</p><p>First, we'll read the model and load the necessary libraries.</p><pre><code class="language-julia hljs">using PEtab | ||
using OrdinaryDiffEq | ||
using Sundials # For CVODE_BDF | ||
using Printf | ||
|
||
path_yaml = joinpath(@__DIR__, "Bachmann", "Bachmann_MSB2011.yaml") | ||
petab_model = PEtabModel(path_yaml, verbose=true)</code></pre><pre><code class="nohighlight hljs">PEtabModel for model Bachmann. ODE-system has 25 states and 39 parameters. | ||
Generated Julia files are at ...</code></pre><h2 id="Adjoint-sensitivity-analysis"><a class="docs-heading-anchor" href="#Adjoint-sensitivity-analysis">Adjoint sensitivity analysis</a><a id="Adjoint-sensitivity-analysis-1"></a><a class="docs-heading-anchor-permalink" href="#Adjoint-sensitivity-analysis" title="Permalink"></a></h2><p>When working with a subset of medium-sized models, and definitely for large-sized models, the most efficient way to compute gradients is through adjoint sensitivity analysis (<code>gradient_method=:Adjoint</code>). There are several tuneable options that can improve performance, including:</p><ol><li><code>ode_solver_gradient</code>: This determines which ODE solver and solver tolerances (<code>abstol</code> and <code>reltol</code>) to use when computing the gradient (when solving the adjoint ODE-system). Currently, the best performing stiff solver for the adjoint problem in Julia is <code>CVODE_BDF()</code>.</li><li><code>sensealg</code>: This determines which adjoint algorithm to use. Currently, <code>InterpolatingAdjoint</code> and <code>QuadratureAdjoint</code> from SciMLSensitivity are supported. You can find more information in their <a href="https://github.com/SciML/SciMLSensitivity.jl">documentation</a>. You can provide any of the options that these methods are compatible with. For example, if you want to use the <code>ReverseDiffVJP</code> algorithm, an acceptable option is <code>sensealg=InterpolatingAdjoint(autojacvec=ReversDiffVJP())</code>.</li></ol><p>Here are a few things to keep in mind:</p><div class="admonition is-info"><header class="admonition-header">Note</header><div class="admonition-body"><p>Adjoint sensitivity analysis is not as reliable in Julia as it is in <a href="https://github.com/SciML/SciMLSensitivity.jl/issues/795">AMICI</a>. However, our benchmarks show that SciMLSensitivity has the potential to be faster.</p></div></div><pre><code class="language-julia hljs">using Zygote # For adjoint | ||
using SciMLSensitivity # For adjoint | ||
petab_problem = PEtabODEProblem(petab_model, | ||
ode_solver=ODESolver(QNDF(), abstol=1e-8, reltol=1e-8), | ||
ode_solver_gradient=ODESolver(CVODE_BDF(), abstol=1e-8, reltol=1e-8), | ||
gradient_method=:Adjoint, | ||
sensealg=InterpolatingAdjoint(autojacvec=EnzymeVJP())) | ||
p = petab_problem.θ_nominalT | ||
gradient = zeros(length(p)) | ||
cost = petab_problem.compute_cost(p) | ||
petab_problem.compute_gradient!(gradient, p) | ||
@printf("Cost = %.2f\n", cost) | ||
@printf("First element in the gradient = %.2e\n", gradient[1])</code></pre><pre><code class="nohighlight hljs">Cost = -418.41 | ||
First element in the gradient = -1.70e-03</code></pre><h2 id="Forward-sensitivity-analysis-and-Gauss-Newton-hessian-approximation"><a class="docs-heading-anchor" href="#Forward-sensitivity-analysis-and-Gauss-Newton-hessian-approximation">Forward sensitivity analysis and Gauss-Newton hessian approximation</a><a id="Forward-sensitivity-analysis-and-Gauss-Newton-hessian-approximation-1"></a><a class="docs-heading-anchor-permalink" href="#Forward-sensitivity-analysis-and-Gauss-Newton-hessian-approximation" title="Permalink"></a></h2><p>For medium-sized models, computing the full Hessian via forward-mode automatic differentiation can be too expensive, so we need an approximation. The <a href="https://en.wikipedia.org/wiki/Gauss%E2%80%93Newton_algorithm">Gauss-Newton</a> (GN) approximation often performs better than the (L)-BFGS approximation. To compute it, we need the forward sensitivities. These sensitivities can also be used to compute the gradient. As some optimizers such as Fides.py compute both the Hessian and gradient at each iteration, we can save the sensitivities between the gradient and Hessian computations.</p><p>When choosing <code>gradient_method=:ForwardEquations</code> and <code>hessian_method=:GaussNewton</code>, there are several tunable options, the key ones are:</p><ol><li><code>sensealg</code> - which sensitivity algorithm to use when computing the sensitivities. We support both <code>ForwardSensitivity()</code> and <code>ForwardDiffSensitivity()</code> with tunable options as provided by SciMLSensitivity (see their <a href="https://github.com/SciML/SciMLSensitivity.jl">documentation</a> for more information). The most efficient option is <code>:ForwardDiff</code>, where forward-mode automatic differentiation is used to compute the sensitivities.</li><li><code>reuse_sensitivities::Bool</code> - whether or not to reuse the sensitivities from the gradient computations when computing the Gauss-Newton Hessian approximation. Whether this option is applicable depends on the optimizer. For example, it works with Fides.py but not with Optim.jl's <code>IPNewton()</code>.<ul><li>Note - this approach requires that <code>sensealg=:ForwardDiff</code> for the gradient.</li></ul></li></ol><pre><code class="language-julia hljs">petab_problem = PEtabODEProblem(petab_model, | ||
ode_solver=ODESolver(QNDF(), abstol=1e-8, reltol=1e-8), | ||
gradient_method=:ForwardEquations, | ||
hessian_method=:GaussNewton, | ||
sensealg=:ForwardDiff, | ||
reuse_sensitivities=true) | ||
p = petab_problem.θ_nominalT | ||
gradient = zeros(length(p)) | ||
hessian = zeros(length(p), length(p)) | ||
cost = petab_problem.compute_cost(p) | ||
petab_problem.compute_gradient!(gradient, p) | ||
petab_problem.compute_hessian!(hessian, p) | ||
@printf("Cost for Bachmann = %.2f\n", cost) | ||
@printf("First element in the gradient = %.2e\n", gradient[1]) | ||
@printf("First element in the Gauss-Newton Hessian = %.2f\n", hessian[1, 1])</code></pre><pre><code class="nohighlight hljs">Cost for Bachmann = -418.41 | ||
First element in the gradient = -1.85e-03 | ||
First element in the Gauss-Newton Hessian = 584.10</code></pre></article><nav class="docs-footer"><a class="docs-footer-prevpage" href="../Brannmark/">« Models with pre-equilibration (steady-state simulation)</a><a class="docs-footer-nextpage" href="../Beer/">Models with many conditions specific parameters »</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.2.1 on <span class="colophon-date" title="Wednesday 20 December 2023 19:10">Wednesday 20 December 2023</span>. Using Julia version 1.9.4.</p></section><footer class="modal-card-foot"></footer></div></div></div></body></html> |
Oops, something went wrong.