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: exercises/exercise09.py
+16-9Lines changed: 16 additions & 9 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 first patients 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
@@ -285,7 +287,7 @@ def _(mo):
285
287
mo.md(r"""
286
288
### The simulator
287
289
288
-
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.
290
+
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.
289
291
290
292
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).
291
293
""")
@@ -377,16 +379,13 @@ def _(mo):
377
379
378
380
379
381
@app.cell
380
-
def_(mio):
382
+
def_():
381
383
importos
382
384
# Must be set before importing BayesFlow/Keras
383
385
os.environ["KERAS_BACKEND"] ="tensorflow"
384
386
385
387
importbayesflowasbf
386
388
387
-
# Suppress verbose MEmilio logs
388
-
mio.set_log_level(mio.LogLevel.Error)
389
-
390
389
print("All imports successful!")
391
390
print(f"BayesFlow version: {bf.__version__}")
392
391
returnbf, os
@@ -495,7 +494,7 @@ def _(mo):
495
494
496
495
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.
497
496
498
-
For more details we refer to the BayesFlow documentation.
497
+
For more details we refer to the [BayesFlow documentation](https://bayesflow.org/main/user_guide/index.html).
499
498
""")
500
499
return
501
500
@@ -560,7 +559,7 @@ def _(mo):
560
559
561
560
@app.cell
562
561
def_(mo, workflow):
563
-
mo.md("Running training... (this may take a few minutes)")
562
+
print("Running training... (this may take a few minutes)")
0 commit comments