/
SEIR Model
59 lines (49 loc) · 1.33 KB
/
SEIR Model
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
55
56
57
58
59
import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt
u = 0.3 # social distancing (0-1)
# 0 = no social distancing
# 0.1 = masks
# 0.2 = masks and hybrid classes
# 0.3 = masks, hybrid, and online classes
# Contact/Transmission Metric
t_incubation = 5.1
t_infective = 10
R0 = 2.25
N = 1415872 # Population of Hawaii
# initial number of infected and recovered individuals
e0 = 1/N
i0 = 0.00
r0 = 0.00
s0 = 1 - e0 - i0 - r0
x0 = [s0,e0,i0,r0]
alpha = 1/t_incubation
gamma = 1/t_infective
beta = R0*gamma
def covid(x,t):
s,e,i,r = x
dx = np.zeros(4)
dx[0] = -(1-u)*beta * s * i
dx[1] = (1-u)*beta * s * i - alpha * e
dx[2] = alpha * e - gamma * i
dx[3] = gamma*i
return dx
t = np.linspace(0, 1000, 101)
x = odeint(covid,x0,t)
s = x[:,0]; e = x[:,1]; i = x[:,2]; r = x[:,3]
# plot the data
plt.figure(figsize=(8,5))
plt.subplot(2,1,1)
plt.title('Social Distancing = '+str(u*100)+'%')
plt.plot(t,s, color='blue', lw=3, label='Susceptible')
plt.plot(t,r, color='red', lw=3, label='Recovered')
#plt.ylabel('Fraction')
#plt.legend()
#plt.subplot(2,1,2)
plt.plot(t,i, color='orange', lw=3, label='Infective')
plt.plot(t,e, color='purple', lw=3, label='Exposed')
#plt.ylim(0, 0.2)
plt.xlabel('Time (days)')
plt.ylabel('Fraction')
plt.legend()
plt.show()