epispotdo the hard work for us.
epispotcomes with some built-in models which have been pre-compiled for us, meaning that they are already built and ready for use. In the next section, we'll work with this type of model to create the SIR model.
epispotif you haven't already. Installation instructions can be found on the GitHub repository, although the easiest way to install it would be simply through
.pyfile and import
epispotwith the alias
epi. This makes it easier to call functions from
epispotwith less code. In many instances in the documentation, it is assumed that
epispothas been imported like this.
epi.pre.SIRfunction to create a pre-compiled SIR model. As you can see from the documentation, it takes 4 parameters. They are R naught, the total population, and the recovery probability and rate.
epispot, all parameters are implemented as functions, not just constant values. This is to account for changes to these parameters over time. For now, we'll just return constant values in our functions, but later, we'll play with these functions to see their effect on the model.
t, which represents time. For now, we won't use this parameter in the function to make things simple. After setting this up, we can now call the
SIR_Modelvariable will hold an
Modelclass. In order to find solutions to the
Modelclass, we'll call the
integratemethod. At this point, the model has already been compiled (i.e. the system of equations needed to compute predictions has already been established). All we need to do now is solve that system of equations.
epispotimplements an algorithm known as Euler's method to do this. As you can see from its documentation, it takes a mandatory
timestepsargument and an optional
starting_stateargument we'll go over in the next section.
timestepsargument basically asks for a Python
stopvalues corresponding to the days of the outbreak that you want to model. This also determines the shape of the returned value.
Model.integratemethod, we can use a shortcut to generate a visual plot of the data. To do this, delete the
Solutionsdefinition and all the code that came after it. Now, simply type:
matplotlibplot pop up on your screen that looks something like this:
N, the same. However, one thing that does change over an outbreak is R naught. Typically, R naught will slowly decrease over the course of an outbreak as stringent measures are taken to avoid unnecessary contact. We can model this with logistic growth. In fact, the equation
gamma. Because we have an SIR model, everyone has a 100% probability of moving to the removed compartment, however, we can change the rate at which they move to that compartment. Let's decrease the rate to simulate faster recovery times as hospitals learn how to treat infected patients. We can do this via a scaled version of the equation we used for R naught previously. For this example, we'll use the equation
gamma, we also must reduce R naught. This is because now the same amount of infecteds need to infect the same amount of susceptibles in a much, much shorter window of time. Running this model without changing R naught would result in drastically unrealistic projections. For this example, we'll halve the value of R naught with:
epispotand writing a comment which demonstrates the flow of our model (this will come helpful later):
placewhich will just return
1/4as a placeholder for repeated definitions of rates and probabilities. This will look like:
0, but does not affect the results. For this model, we'll order the compartments as Susceptible, Infected, Hospitalized, Recovered, Dead. Compiling all the other compartments looks like:
init_popparameter must be a constant value because it represents the initial population. Now, we use the
.add_layermethod to add all the layers we've compiled:
layer_namerepresents the type of compartment that you are adding. You must use the correct compartment name or the layer will not be recognized. Lastly, the
layer_mapis a list of all the layers that this layer connects to. For layers that are terminal, the map is an empty list.
epispotwizard! You should now be able to understand epispot's documentation since you understand the basic layout of
epispotand how to compile models. The link to epispot's documentation is: https://epispot.github.io/epispot. If you have any questions or feedback, don't hesitate to submit an issue on the GitHub repository.