Solution (source code)

= Solution

Continue the random-number stream used for the ten trajectories, then generate 1000 further independent realizations with the same model parameters. Plot each statistic in its own <histogram>:

``
stats = sir_sim_stats(1000, 100, [99,1,0], 1, .25, rng)
fig, axes = plt.subplots(1, 2, figsize=(9, 4), layout="constrained")
axes[0].hist(stats[:,0], bins=np.arange(.5,65.6,2))
axes[1].hist(stats[:,1], bins=np.arange(0,61,2))
axes[0].set(xlabel="Peak infected population", ylabel="Number of outbreaks")
axes[1].set(xlabel="Final recorded time (days)", ylabel="Number of outbreaks")
plt.show()
``

Both <histograms> have a group of early failures separated from a group of large outbreaks. For this reproducible run the mean peak is \b[33.73 individuals], and the mean final time is \b[22.165 days]; the largest final time is 56.916 days, so all 1000 runs reached <epidemic extinction> before the 100-day horizon.

\Image[/past-exam-of-the-mathematical-and-computational-biology-course-of-the-university-of-cambridge/2024/paper-2-sir-summary.png]
{title=Peak size and extinction time for 1000 original stochastic SIR realizations, with operational failure cutoffs}