-
Notifications
You must be signed in to change notification settings - Fork 0
/
siqctr.py
54 lines (49 loc) · 1.98 KB
/
siqctr.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# the original python code of the SIR model is https://scipython.com/book/chapter-8-scipy/additional-examples/the-sir-epidemic-model/ by Christian Hill
import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt
# Total population: N
# the number of tests per day: Test
# the numeber of confounding disease: C
N = 100000000
Test = 6000
C = 100000
# Initial number of infected, quarantined, and recovered individuals, I0, Q0, and R0.
I0, Q0, R0 = 10000, 0, 0
# Everyone else, S0, is susceptible to infection initially.
S0 = N - I0 - Q0 - R0
# Contact rate, beta, and mean recovery rate, gamma, (in 1/days).
beta, gamma = 0.35, 0.25
# A grid of time points (in days)
t = np.linspace(0, 200, 200)
# The SIR model differential equations.
def deriv(y, t, N, Test, C, beta, gamma):
S, I, Q, R = y
dSdt = -beta * S * I / (S+I+R)
dIdt = beta * S * I / (S+I+R) - gamma * I - Test * I /(C + I)
dQdt = Test * I /(C + I) - gamma * Q
dRdt = gamma * I + gamma * Q
return dSdt, dIdt, dQdt, dRdt
# Initial conditions vector
y0 = S0, I0, Q0, R0
# Integrate the SIR equations over the time grid, t.
ret = odeint(deriv, y0, t, args=(N, Test, C, beta, gamma))
S, I, Q, R = ret.T
# Plot the data on three separate curves for S(t), I(t), Q(t) and R(t)
fig = plt.figure(facecolor='w')
ax = fig.add_subplot(111, facecolor='#dddddd', axisbelow=True)
ax.plot(t, S/100000000, 'b', alpha=0.5, lw=2, label='Susceptible')
ax.plot(t, I/100000000, 'r', alpha=0.5, lw=2, label='Infected')
ax.plot(t, Q/100000000, 'y', alpha=0.5, lw=2, label='Quarantined/isolated')
ax.plot(t, R/100000000, 'g', alpha=0.5, lw=2, label='Recovered with immunity')
ax.set_xlabel('Time /days')
ax.set_ylabel('Number (100000s)')
ax.set_ylim(0,1.2)
ax.yaxis.set_tick_params(length=0)
ax.xaxis.set_tick_params(length=0)
ax.grid(b=True, which='major', c='w', lw=2, ls='-')
legend = ax.legend()
legend.get_frame().set_alpha(0.5)
for spine in ('top', 'right', 'bottom', 'left'):
ax.spines[spine].set_visible(False)
plt.show()