Quickstart¶
Note
This very simple tutorial will guide you through the most basic functionalities of **pyepidemics**, ie building and manipulating a SIR model
Developer import¶
%matplotlib inline
%load_ext autoreload
%autoreload 2
# Developer import
import sys
sys.path.append("../../")
On Google Colab¶
Uncomment the following line to install the library locally
# !pip install pyepidemics
Verify the library is correctly installed¶
import pyepidemics
Building a SIR model¶
Quickstart¶
Simply imports the pre-coded SIR model from the bank of models
from pyepidemics.models import SIR
N = 1000 # Thousand persons
beta = 3/4 # One person contaminates 3/4 person per day
gamma = 1/4 # One person stay infected for 4 days
sir = SIR(N,beta,gamma)
You can then make predictions using this model
states = sir.solve()
states
is a custom object, ie a Pandas DataFrame with more features adapted to our case
type(states)
Among those features are visualization with simple but efficient functions like .show()
states.show(plotly = False)
Yet states is also a DataFrame you can use and manipulate as usual where the population in each compartment is stored
states.head()
For example you can find the date of the epidemic peak easily with :
states["I"].idxmax()
You can also visualize the epidemic curves in proportions (curves can be reordered or selected using Pandas indexing)
states[["I","R","S"]].show_evolution_norm(plotly = False)
states.show(plotly = True)
You can separate on each row (respectively column with the argument facet_column
) to make it more readable
states.show(facet_row = "compartment")
You can also group epidemic curves together using the argument group
, which is super useful to visualize together curves of the same scale.
states.show(group = {"Infections":["I"],"Population":["S","R"]})
Controlling the solve()
function¶
When you solve the differential equation it implicitly use I0=1
, ie starting with S0 = N-1
and I0 =1
, you can change that behavior by passing an init_state
to the solve equation as shown below
This will be interpreted as init_state = {"S":N-100,"I":100,"R":0}
sir.solve(init_state = 100).show(plotly = False)
Which is equivalent to the following expressions
sir.solve(init_state = (900,100,0))
sir.solve(init_state = {"S":900,"I":100,"R":0})
sir.solve(init_state = {"S":900,"I":100}) # Any compartment not initialized is implicitly = 0