-
Notifications
You must be signed in to change notification settings - Fork 2
/
covid_lockdown.py
68 lines (54 loc) · 1.45 KB
/
covid_lockdown.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
55
56
57
58
59
60
61
62
63
64
65
66
"""
Model for COVID-19 lockdowns
"""
# Load packages
import pandas as pd
import numpy as np
import matplotlib.pyplot as pl
# Define our parameters
R0 = 3.5
gamma = 1/7
beta = R0*gamma
beta_after_lockdown = beta / 2 # Lockdown halves beta
# Initial conditions and other settings
npts = 100
I0 = 1
N = 1000
dt = 1
t_lockdown = 10 # Lockdown on day 10
# Make arrays where we will store the estimates
x = np.arange(npts)
S = np.zeros(npts)
I = np.zeros(npts)
R = np.zeros(npts)
Sn = np.zeros(npts) # Copy of the arrays with no lockdown
In = np.zeros(npts)
Rn = np.zeros(npts)
# Initial conditions
S[0] = N - I0
I[0] = I0
Sn[0] = N - I0
In[0] = I0
# Simulate the model over time
for t in x[:-1]:
if t < t_lockdown:
infections = beta * S[t] * I[t]/N * dt
recoveries = gamma * I[t] * dt
else:
infections = beta_after_lockdown * S[t] * I[t] / N * dt
recoveries = gamma * I[t] * dt
infections_nt = beta * Sn[t] * In[t]/N * dt
recoveries_nt = gamma * In[t] * dt
S[t + 1] = S[t] - infections
I[t + 1] = I[t] + infections - recoveries
R[t + 1] = R[t] + recoveries
Sn[t + 1] = Sn[t] - infections_nt
In[t + 1] = In[t] + infections_nt - recoveries_nt
Rn[t + 1] = Rn[t] + recoveries_nt
# # Plot the model estimate of the number of infections alongside the data
time = x * dt
pl.plot(time, In, label='Without lockdown')
pl.plot(time, I, label='With lockdown')
pl.legend()
pl.title('Infectious people')
pl.show()