-
-
Save pinus/c60a079921d389755e81993c1a53c24a to your computer and use it in GitHub Desktop.
COVID-19 simuation by SEIR model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The preprints is available from https://www.preprints.org/manuscript/202002.0179/v1 | |
# S Susceptible | |
# E Exposed | |
# I Infected | |
# R Recovery | |
%matplotlib inline | |
import numpy as np | |
import matplotlib.pyplot as plt | |
from ipywidgets import interact | |
def dsdt(S, I, beta): | |
return -beta * S * I / N | |
def dedt(S, I, E, beta): | |
return beta * S * I / N - delta * E | |
def didt(E, I, delta): | |
return delta * E - nu * I | |
def drdt(I, nu): | |
return nu * I | |
@interact | |
def main(r0: (0.1,5,0.1), initial_infection: (0.1,10,0.1)): | |
#r0 = 3. # basic reproduction number | |
p = 10. # Infectious period(day) | |
prevalence = 0.7 # patients/at-risk people | |
recovery = 1.0 # recovery rate from disease | |
#initial_infection = 10. # initial number of carrier | |
beta = r0/p # propergation rate of infection | |
delta = prevalence/p # | |
nu = recovery/p # | |
N = 1000 # Population | |
D = 300 # observation days | |
t = np.arange(0, D, 1) | |
Ss = np.array([N]) | |
Es = np.array([0]) | |
Is = np.array([initial_infection]) | |
Rs = np.array([0]) | |
for i in t[0:D-1]: | |
Ss = np.append(Ss, Ss[i] + dsdt(Ss[i], Is[i], beta)) | |
Es = np.append(Es, Es[i] + dedt(Ss[i], Is[i], Es[i], beta)) | |
Is = np.append(Is, Is[i] + didt(Es[i], Is[i], delta)) | |
Rs = np.append(Rs, Rs[i] + drdt(Is[i], nu)) | |
#print(Ss, Es, Is, Rs) | |
plt.plot(t, Ss, label='S') | |
plt.plot(t, Es, label='E') | |
plt.plot(t, Is, label='I') | |
plt.plot(t, Rs, label='R') | |
plt.legend() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment