Simulating Discrete models¶
[1]:
from epimodels.discrete import models as DM
from IPython.display import Markdown as md
[2]:
import matplotlib.pyplot as P
SIS model¶
The SIS (Susceptible-Infectious-Susceptible) model for diseases that do not confer immunity after recovery.
[3]:
modelsis = DM.SIS()
md(str(modelsis))
[4]:
modelsis([0, 1, 1000], [0,50], 1001, {'beta': 2, 'gamma': 1})
modelsis.plot_traces()
SIR Model¶
The SIR (Susceptible-Infectious-Removed) model is a classic compartmental model.
[5]:
sirmodel = DM.SIR()
md(str(sirmodel))
[6]:
sirmodel([1000, 1, 0], [0,500], 1001, {'beta': .2, 'gamma': .1})
sirmodel.plot_traces()
SEIS Model¶
The SEIS (Susceptible-Exposed-Infectious-Susceptible) model includes an exposed compartment but no permanent immunity.
[7]:
model = DM.SEIS()
md(str(model))
[8]:
model([1000, 0, 1], [0, 100], 1001, {'beta': 0.5, 'e': 0.3, 'r': 0.1, 'b': 0})
model.plot_traces()
SEIR Model¶
The SEIR (Susceptible-Exposed-Infectious-Removed) model includes an exposed compartment for diseases with incubation period.
[9]:
model = DM.SEIR()
md(str(model))
[10]:
model([1000, 0, 1, 0], [0, 100], 1001, {'beta': 0.5, 'e': 0.3, 'r': 0.1, 'b': 0, 'alpha': 0.01})
model.plot_traces()
SIRS Model¶
The SIRS (Susceptible-Infectious-Removed-Susceptible) model accounts for waning immunity.
[11]:
model = DM.SIRS()
md(str(model))
[12]:
model([1000, 1, 0], [0, 200], 1001, {'beta': 0.3, 'r': 0.1, 'b': 0, 'w': 0.02})
model.plot_traces()
SIpRpS model¶
This model assumes that a fraction \(\delta\) of infectious individuals acquire full immunity while the remaining \((1-\delta)\) returns to the susceptible stage.
[13]:
model = DM.SIpRpS()
md(str(model))
[14]:
model([1000, 1, 0], [0, 100], 1001, {'beta': 0.5, 'r': 0.2, 'b': 0, 'delta': 0.7})
model.plot_traces()
SEIpRpS model¶
Similar to SIpRpS but with an exposed compartment. A fraction \(\delta\) of infectious individuals acquire full immunity while the remaining \((1-\delta)\) returns to the susceptible stage.
[15]:
model = DM.SEIpRpS()
md(str(model))
[16]:
model([1000, 0, 1, 0], [0, 50], 1001, {'beta': 1, 'r': .3, 'e': 1, 'b': 0, 'delta': 0.6})
model.plot_traces()
[17]:
model.parameter_table()
SIpR model¶
This model allows recovered individuals to be reinfected at a reduced rate \(p\beta\).
[18]:
model = DM.SIpR()
md(str(model))
[19]:
model([1000, 1, 0], [0, 150], 1001, {'beta': 0.3, 'r': 0.1, 'b': 0, 'p': 0.3})
model.plot_traces()
SEIpR model¶
Similar to SIpR but with an exposed compartment. Recovered individuals can be reinfected at a reduced rate \(p\beta\).
[20]:
model = DM.SEIpR()
md(str(model))
[21]:
model([1000, 0, 1, 0], [0, 150], 1001, {'beta': 0.3, 'e': 0.2, 'r': 0.1, 'b': 0, 'alpha': 0.01, 'p': 0.3})
model.plot_traces()
SEQIAHR model¶
A complex model with asymptomatic and hospitalized compartments, suitable for modeling diseases like COVID-19.
[22]:
model = DM.SEQIAHR()
md(str(model))
[23]:
params = {
'chi': 0.3, # Quarantine reduction factor
'phi': 0.1, # Hospitalization rate from I
'beta': 0.5, # Transmission rate
'rho': 0.1, # Recovery rate from H
'delta': 0.2, # Recovery rate from I
'gamma': 0.1, # Recovery rate from A
'alpha': 0.3, # Incubation rate
'mu': 0.01, # Mortality rate in H
'p': 0.5, # Proportion asymptomatic
'q': 20, # Quarantine start day
'r': 30 # Quarantine duration
}
inits = [10000, 0, 1, 0, 0, 0, 0, 0]
model(inits, [0, 100], 10001, params)
model.plot_traces()
Influenza model¶
A complex age-structured model for influenza with four age classes (0-2, 3-14, 15-59, >60 years). Each age class has compartments for susceptible, incubating, subclinical, clinical, and complicated individuals.
[24]:
model = DM.Influenza()
md(str(model))
[25]:
inits = [
100, 0, 0, 0, 0, # Age group 1 (0-2 years): S1, E1, Is1, Ic1, Ig1
200, 0, 0, 0, 0, # Age group 2 (3-14 years): S2, E2, Is2, Ic2, Ig2
500, 0, 1, 0, 0, # Age group 3 (15-59 years): S3, E3, Is3, Ic3, Ig3
200, 0, 0, 0, 0 # Age group 4 (>60 years): S4, E4, Is4, Ic4, Ig4
]
params = {
'beta': 0.0003, # Transmission rate
'r': 0.3, # Recovery rate
'e': 0.5, # Incubation rate
'c': 0.5, # Clinical progression rate
'g': 0.2, # Complication rate
'd': 0.1, # Death/recovery rate from complications
'pc1': 0.3, # Clinical proportion age group 1
'pc2': 0.3, # Clinical proportion age group 2
'pc3': 0.4, # Clinical proportion age group 3
'pc4': 0.6, # Clinical proportion age group 4
'pp1': 0.05, # Complication proportion age group 1
'pp2': 0.05, # Complication proportion age group 2
'pp3': 0.1, # Complication proportion age group 3
'pp4': 0.3, # Complication proportion age group 4
'b': 0 # Birth rate
}
model(inits, [0, 100], 1001, params)
model.plot_traces()
[ ]: