Skip to content

Commit 137af09

Browse files
committed
Merge branch 'main' of github.com:SciCompMod/memilio-tutorials
2 parents 85bd3c4 + 7e48a3b commit 137af09

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

tutorial09.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def _(mo):
3737
3838
In this notebook we tackle a real-world modelling task: inferring epidemic parameters from observed case data in order to characterise the ongoing outbreak and support decision-making. Concretely, we want to estimate when and how strongly contact-reducing interventions took effect in each of five German regions, using only the reported ICU and death counts.
3939
40-
This is the third in a series of three notebooks introducing Approximate Bayesian Computation with MEmilio. In the first two notebooks we calibrated simple single-region compartmental models. Here we extend the approach to a **metapopulation model** that resolves spatial heterogeneity across Germany.
40+
This is the third in a series of three notebooks introducing fitting methods with MEmilio. In the first two notebooks we calibrated simple single-region compartmental models. Here we extend the approach to a **metapopulation model** that resolves spatial heterogeneity across Germany.
4141
4242
We use [BayesFlow](https://bayesflow.org/main/index.html), a Python library for simulation-based inference with deep learning, as our inference method. This notebook is not a general tutorial on Neural Parameter Estimation with BayesFlow — for that we refer to the [BayesFlow documentation](https://bayesflow.org/main/user_guide/introduction.html) and the primary literature. Our focus is on showing how MEmilio and BayesFlow work together.
4343
""")
@@ -592,12 +592,28 @@ def _(workflow):
592592
return
593593

594594

595+
@app.cell
596+
def _(mo):
597+
mo.md(r"""
598+
After training, run `workflow.plot_default_diagnostics()` and check that the calibration looks reasonable before proceeding to inference. For a full explanation of each diagnostic and its interpretation, see the [BayesFlow documentation](https://bayesflow.org/api/bayesflow.diagnostics.html).
599+
""")
600+
return
601+
602+
603+
@app.cell
604+
def _(mo, workflow):
605+
plots = workflow.plot_default_diagnostics(test_data=100, calibration_ecdf_kwargs={
606+
'difference': True, 'stacked': True})
607+
mo.vstack([plot for plot in plots.values()])
608+
return
609+
610+
595611
@app.cell
596612
def _(mo):
597613
mo.md(r"""
598614
# Inference on the Outbreak Data
599615
600-
With a trained and validated approximator in hand, we can now turn to the actual outbreak data. We load the observed ICU and death counts and pass them to the workflow. Posterior samples are drawn in a single forward pass — this is the payoff of amortized inference: no matter how long training took, each new inference is essentially free.
616+
With a trained and validated approximator in hand, we can now turn to the actual outbreak data. We load the observed ICU and death counts and pass them to the workflow. With the CouplingFlow network, posterior samples are drawn in a single forward pass — this is the payoff of amortized inference: no matter how long training took, each new inference is essentially free.
601617
602618
The posterior samples are then fed back into the simulator to produce a **posterior predictive distribution**: an ensemble of epidemic trajectories consistent with both the model and the observed data. This allows us to assess model fit and quantify forecast uncertainty.
603619
""")

0 commit comments

Comments
 (0)