Various implementations of the classical SIR model in Julia
Try the notebooks out in Binder:
The model equations are as follows.
$$ \begin{align} \dfrac{\mathrm dS}{\mathrm dt} &= -\frac{\beta c S I}{N}, \ \dfrac{\mathrm dI}{\mathrm dt} &= \frac{\beta c S I}{N} - \gamma I,\ \dfrac{\mathrm dR}{\mathrm dt} &= \gamma I, \ S(t) + I(t) + R(t) &= N \end{align} $$
Here's a description of the underlying SIR model.
There are two types of parameterization commonly used in this project; the 'standard' version, that considers the number of individuals in the S, I, and R groups, and an alternative version, in which the dynamics of transmission (βSI/N) and recovery (γI) are modelled directly, with S, I, and R being calculated based on these dynamics and the initial conditions for S, I and R.
The above process can be represented in different kinds of ways:
Building models from smaller, re-usable components make it easier to build complex models quickly, and also makes it easier to document the development of these models.
We usually do not observe the trajectory of susceptible, infected, and recovered individuals. Rather, we often obtain data in terms of new cases aggregated over a particular timescale (e.g. a day or a week).
In addition to the above examples of simulation, there are also examples of inference of the parameters of the model using counts of new cases. Although these are toy examples, they provide the building blocks for more complex situations.
In conducting inference, it is important to know the extent to which parameters are identifiable from the available data.
Incorporating uncertainty in its many forms is important for using models to make decisions.
When solving continuous-time models like ODEs, the discretization can lead to numerical errors. Probabilistic integration treats this error as a statistical problem to capture the uncertainty in the model outputs generated using the solver.
ProbNumDiffEq.jl
DiffEqUncertainty.jl
(can also handle SDEs and DDEs)mogp-emulator
, with an example of history matchinghmer
, with an example of history matchingWhile this repository is mainly about Julia, it is also possible to use Julia to call code written in other languages. Here are some examples of how to define the vector field of an ODE in C, Python, and R.
Many languages can compile to shared libraries that can be accessed via ccall
. Here are examples of how to define the vector field of an ODE in various languages, and call it using ccall
.
modelingtoolkitize
odin
R package, accessed via RCall.jlNote that the implementations and choice of parameters may be suboptimal, and are intended to illustrate more-or-less the same underlying biological process with different mathematical representations. Additional optimizations may be obtained e.g. by using StaticArrays
.
I've also tried to transform parameterisations in discrete time as closely as possible to their continuous counterparts. Please see the great work by Linda Allen for how these different representations compare.
Thanks to Weave.jl
, Julia Markdown files (in tutorials/
) are converted into multiple formats.
git clone https://github.com/epirecipes/sir-julia
cd sir-julia
Then launch julia
and run the following.
cd(@__DIR__)
import IJulia
IJulia.notebook(;dir="notebook")
Plans for new examples are typically posted on the Issues page.
To add an example, make a new subdirectory in the tutorials
directory, and add a Julia Markdown (.jmd
) document to it. Set the beginning to something like the following:
# Agent-based model using Agents.jl
Simon Frost (@sdwfrost), 2020-04-27
Suggested sections:
Change to the root directory of the repository and run the following from within Julia; you will need Weave.jl and any dependencies from the tutorial.
include("build.jl")
weave_all() # or e.g. weave_folder("abm") for an individual tutorial
If additional packages are added, then these need to be added to build_project_toml.jl
, which when run, will regenerate Project.toml
.
Examples use the following libraries (see the Project.toml
file for a full list of dependencies):
DifferentialEquations.jl
ecosystem for many of the examplesSimJulia
for discrete event simulationsAgents.jl
for agent-based modelsGillespie.jl
for the Doob-Gillespie processPetri.jl
for the Petri net modelsAlgebraicPetri.jl
for a category theory based modeling framework for creating Petri net modelsTuring.jl
for inference using probabilistic programsNestedSamplers.jl
for nested samplingGpABC
for inference using Approximate Bayesian ComputationSoss.jl
for Markov modelsMomentClosure.jl
for moment closureBridge.jl
for stochastic differential equationsParts of the code were taken from @ChrisRackauckas DiffEqTutorials
, which comes highly recommended.