You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: tutorial9.py
+19-10Lines changed: 19 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -21,9 +21,11 @@ def _(mo):
21
21
22
22
Today, the German federal health authority RKI announced that the recently observed sharp increase in ICU case numbers following acute respiratory infections is caused by a new lineage of the influenza virus. It was first sequenced at the University Hospital of Cologne and has consequently been named *Influenza B/Colognia/314/2026*. Following its detection, laboratories across Germany rushed to test stored samples from recent patients, giving us a reasonably complete picture of ICU admissions and deaths to date.
23
23
24
-
The oldest sample identified came from an 80-year-old man from Cologne who died on 2026-02-29. His family reported that he first felt ill shortly after excessively celebrating Carnival on Rose Monday, which fell on 2026-02-16 this year.
24
+
The oldest sample identified came from an 50-year-old man from Cologne who died on 2026-03-02. His family reported that he first felt ill shortly after excessively celebrating Carnival on Rose Monday, which fell on 2026-02-16 this year.
25
25
26
26
The RKI has today published all available data and called on modellers worldwide to estimate disease parameters and forecast the further course of the outbreak.
27
+
28
+
At the same time, political discussions started on whether and which non-pharmaceutical interventions should be implemented. First forecasts suggested that they are absolutely necessary to reduce the expected number of cases to not overwhelm the healthcare system. However, data shows that the German population has already started to reduce contacts and more people wear masks, which has not been taken into account by the first predictions. Some people argue that it is thus unnecessary to implement further measures, while others argue that measures are not necessary in their states, but in other states. To validate this claim, we need to identify the effects and starting days of such preventative contact reductions for each german region.
27
29
""")
28
30
return
29
31
@@ -37,7 +39,7 @@ def _(mo):
37
39
38
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.
39
41
40
-
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 and the primary literature. Our focus is on showing how MEmilio and BayesFlow work together.
42
+
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.
41
43
""")
42
44
return
43
45
@@ -303,7 +305,7 @@ def _(mo):
303
305
mo.md(r"""
304
306
### The simulator
305
307
306
-
The function below is the **core forward model** that BayesFlow will call repeatedly during training. Given a set of intervention parameters it assembles the full metapopulation model, runs the ODE solver, and returns the simulated observables.
308
+
The function below is the **core forward model** that BayesFlow will call repeatedly during training. Given a set of intervention parameters it assembles the full metapopulation model, runs the ODE solver, and returns the simulated observables. Other than in the last notebooks, here we round the output data before giving it to our inference process. This is helpful here as it already reduces a main difference between the simulated data and the real data, improving the inference process.
307
309
308
310
The outputs are the **Critical (ICU)** and **Dead** compartment counts for each of the six age groups, extracted at daily resolution for all five regions. This gives, per region, an array of shape `(31, 12)` — 31 time points (days 0–30) and 12 compartment-age combinations (6 age groups × 2 outcomes).
309
311
""")
@@ -399,16 +401,13 @@ def _(mo):
399
401
400
402
401
403
@app.cell
402
-
def_(mio):
404
+
def_():
403
405
importos
404
406
# Must be set before importing BayesFlow/Keras
405
407
os.environ["KERAS_BACKEND"] ="tensorflow"
406
408
407
409
importbayesflowasbf
408
410
409
-
# Suppress verbose MEmilio logs
410
-
mio.set_log_level(mio.LogLevel.Error)
411
-
412
411
print("All imports successful!")
413
412
print(f"BayesFlow version: {bf.__version__}")
414
413
returnbf, os
@@ -514,7 +513,7 @@ def _(mo):
514
513
515
514
The **inference network** (`CouplingFlow`) is a normalising flow that learns the mapping from the summary embedding to samples from the approximate posterior $q(\theta \mid s(y))$. It consists of alternating affine coupling layers and can represent complex, multi-modal distributions.
516
515
517
-
For more details we refer to the BayesFlow documentation.
516
+
For more details we refer to the [BayesFlow documentation](https://bayesflow.org/main/user_guide/index.html).
518
517
""")
519
518
return
520
519
@@ -578,8 +577,8 @@ def _(mo):
578
577
579
578
580
579
@app.cell
581
-
def_(mo, workflow):
582
-
mo.md("Running training... (this may take a few minutes)")
580
+
def_(workflow):
581
+
print("Running training... (this may take a few minutes)")
Overall, the fitting seems to work and the aggregated plots look reasonable. However, the plots per region show some difficulties of the inference process for the regions without ICU cases and deaths. This is likely caused by the different scales of case numbers in the different regions and age groups. The 90% CIs especially for the damping start values are very high, indicating much uncertainty in the inferred parameters. Our results indicate that there is not enough data currently to perform inference on all regions and thus, that our research question here is not answerable.
909
+
910
+
Let's hope that somebody else volunteers to communicate this in a talk show...
0 commit comments