Skip to content

Commit 289d21e

Browse files
committed
CHG: synchronize exercise with tutorial changes
1 parent 1c6abcd commit 289d21e

1 file changed

Lines changed: 16 additions & 9 deletions

File tree

exercises/exercise09.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ def _(mo):
2121
2222
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.
2323
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.
2525
2626
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.
2729
""")
2830
return
2931

@@ -37,7 +39,7 @@ def _(mo):
3739
3840
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.
3941
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.
4143
""")
4244
return
4345

@@ -285,7 +287,7 @@ def _(mo):
285287
mo.md(r"""
286288
### The simulator
287289
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.
289291
290292
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).
291293
""")
@@ -377,16 +379,13 @@ def _(mo):
377379

378380

379381
@app.cell
380-
def _(mio):
382+
def _():
381383
import os
382384
# Must be set before importing BayesFlow/Keras
383385
os.environ["KERAS_BACKEND"] = "tensorflow"
384386

385387
import bayesflow as bf
386388

387-
# Suppress verbose MEmilio logs
388-
mio.set_log_level(mio.LogLevel.Error)
389-
390389
print("All imports successful!")
391390
print(f"BayesFlow version: {bf.__version__}")
392391
return bf, os
@@ -495,7 +494,7 @@ def _(mo):
495494
496495
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.
497496
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).
499498
""")
500499
return
501500

@@ -560,7 +559,7 @@ def _(mo):
560559

561560
@app.cell
562561
def _(mo, workflow):
563-
mo.md("Running training... (this may take a few minutes)")
562+
print("Running training... (this may take a few minutes)")
564563

565564
history = workflow.fit_online(
566565
epochs=15,
@@ -838,5 +837,13 @@ def _(mo, np, posterior_samples):
838837
return
839838

840839

840+
@app.cell(hide_code=True)
841+
def _(mo):
842+
mo.md(r"""
843+
How do we interpret these results?
844+
""")
845+
return
846+
847+
841848
if __name__ == "__main__":
842849
app.run()

0 commit comments

Comments
 (0)