Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/notebooks/chap13.ipynb
Views: 531
Modeling and Simulation in Python
Chapter 13
Copyright 2017 Allen Downey
Code from previous chapters
make_system
, plot_results
, and calc_total_infected
are unchanged.
Sweeping beta
Make a range of values for beta
, with constant gamma
.
Run the simulation once for each value of beta
and print total infections.
Wrap that loop in a function and return a SweepSeries
object.
Sweep beta
and plot the results.
Sweeping gamma
Using the same array of values for beta
And now an array of values for gamma
For each value of gamma
, sweep beta
and plot the results.
Exercise: Suppose the infectious period for the Freshman Plague is known to be 2 days on average, and suppose during one particularly bad year, 40% of the class is infected at some point. Estimate the time between contacts.
SweepFrame
The following sweeps two parameters and stores the results in a SweepFrame
Here's what the SweepFrame
look like.
And here's how we can plot the results.
We can also plot one line for each value of beta
, although there are a lot of them.
It's often useful to separate the code that generates results from the code that plots the results, so we can run the simulations once, save the results, and then use them for different analysis, visualization, etc.
After running sweep_parameters
, we have a SweepFrame
with one row for each value of beta
and one column for each value of gamma
.