Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri July 17 2020
D. D. Nolte, "Introduction to Modern Dynamics:
Chaos, Networks, Space and Time, 2nd Edition (Oxford University Press, 2019)
@author: nolte
"""
import numpy as np
from scipy import integrate
from matplotlib import pyplot as plt
plt.close('all')
def tripartite(x,y,z):
sm = x + y + z
xp = x/sm
yp = y/sm
f = np.sqrt(3)/2
y0 = f*xp
x0 = -0.5*xp - yp + 1;
lines = plt.plot(x0,y0)
plt.setp(lines, linewidth=0.5)
plt.plot([0, 1],[0, 0],'k',linewidth=1)
plt.plot([0, 0.5],[0, f],'k',linewidth=1)
plt.plot([1, 0.5],[0, f],'k',linewidth=1)
plt.show()
print(' ')
print('SIRS.py')
def solve_flow(param,max_time=1000.0):
def flow_deriv(x_y,tspan,mu,betap,nu):
x, y = x_y
return [-mu*x + betap*x*(1-x-y),mu*x-nu*y]
x0 = [del1, del2]
# Solve for the trajectories
t = np.linspace(0, int(tlim), int(250*tlim))
x_t = integrate.odeint(flow_deriv, x0, t, param)
return t, x_t
# rates per week
betap = 0.3; # infection rate
mu = 0.2; # recovery rate
nu = 0.02 # immunity decay rate
print('beta = ',betap)
print('mu = ',mu)
print('nu =',nu)
print('betap/mu = ',betap/mu)
del1 = 0.005 # initial infected
del2 = 0.005 # recovered
tlim = 600 # weeks (about 12 years)
param = (mu, betap, nu) # flow parameters
t, y = solve_flow(param)
I = y[:,0]
R = y[:,1]
S = 1 - I - R
plt.figure(1)
lines = plt.semilogy(t,I,t,S,t,R)
plt.ylim([0.001,1])
plt.xlim([0,tlim])
plt.legend(('Infected','Susceptible','Recovered'))
plt.setp(lines, linewidth=0.5)
plt.xlabel('Days')
plt.ylabel('Fraction of Population')
plt.title('Population Dynamics for COVID-19')
plt.show()
plt.figure(2)
plt.hold(True)
for xloop in range(0,10):
del1 = xloop/10.1 + 0.001
del2 = 0.01
tlim = 300
param = (mu, betap, nu) # flow parameters
t, y = solve_flow(param)
I = y[:,0]
R = y[:,1]
S = 1 - I - R
tripartite(I,R,S);
for yloop in range(1,6):
del1 = 0.001;
del2 = yloop/10.1
t, y = solve_flow(param)
I = y[:,0]
R = y[:,1]
S = 1 - I - R
tripartite(I,R,S);
for loop in range(2,10):
del1 = loop/10.1
del2 = 1 - del1 - 0.01
t, y = solve_flow(param)
I = y[:,0]
R = y[:,1]
S = 1 - I - R
tripartite(I,R,S);
plt.hold(False)
plt.title('Simplex Plot of COVID-19 Pop Dynamics')
vac = [1, 0.8, 0.6]
for loop in vac:
# Run the epidemic to the first peak
del1 = 0.005
del2 = 0.005
tlim = 52
param = (mu, betap, nu)
t1, y1 = solve_flow(param)
# Now vaccinate a fraction of the population
st = np.size(t1)
del1 = y1[st-1,0]
del2 = y1[st-1,1]
tlim = 400
param = (mu, loop*betap, nu)
t2, y2 = solve_flow(param)
t2 = t2 + t1[st-1]
tc = np.concatenate((t1,t2))
yc = np.concatenate((y1,y2))
I = yc[:,0]
R = yc[:,1]
S = 1 - I - R
plt.figure(3)
plt.hold(True)
lines = plt.semilogy(tc,I,tc,S,tc,R)
plt.ylim([0.001,1])
plt.xlim([0,tlim])
plt.legend(('Infected','Susceptible','Recovered'))
plt.setp(lines, linewidth=0.5)
plt.xlabel('Days')
plt.ylabel('Fraction of Population')
plt.title('Vaccination at 1 Year')
plt.show()
plt.hold(False)