Python Programs for Modelling Infectious Diseases book:Chapter 2:Program 2.7

From DeductiveThinking Wiki
(Redirected from Program 2.7)
Jump to: navigation, search

Program 2.7 is a SIR model with carrier state (page 44 of the book). These are the equations and the code of the model:

Equations

 \frac{dS}{dt} = \mu-(\beta*I+\varepsilon*\beta*C)*S-\mu*S

 \frac{dI}{dt} = (\beta*I+\varepsilon*\beta*C)*S-\gamma*I-\mu*I

 \frac{dC}{dt} = \gamma*q*I-\Gamma*C-\mu*C

 \frac{dR}{dt} = \gamma*(1-q)*I+\Gamma*C-\mu*R

Code

Program 2.7: A SIR model with carrier state
#!/usr/bin/env python

####################################################################
###    This is the PYTHON version of program 2.7 from page 44 of   #
### "Modeling Infectious Disease in humans and animals"            #
### by Keeling & Rohani.					   #
###								   #
### It is the SICR which includes a carrier class.		   #
####################################################################

##########################################################################
### Copyright (C) <2008> Ilias Soumpasis                                 #
### ilias.soumpasis@deductivethinking.com                                #
### ilias.soumpasis@gmail.com	                                         #
###                                                                      #
### This program is free software: you can redistribute it and/or modify #
### it under the terms of the GNU General Public License as published by #
### the Free Software Foundation, version 3.                             #
###                                                                      #
### This program is distributed in the hope that it will be useful,      #
### but WITHOUT ANY WARRANTY; without even the implied warranty of       #
### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        #
### GNU General Public License for more details.                         #
###                                                                      #
### You should find a copy of the GNU General Public License at          #
###the Copyrights section or, see http://www.gnu.org/licenses.           #
##########################################################################


import scipy.integrate as spi
import numpy as np
import pylab as pl

beta=0.2
epsilon=0.1
gamma=0.01
Gamma=0.001
mu=1/(50*365.0)
q=0.4
S0=0.1
I0=1e-4
C0=1e-3
ND=60*365
TS=1.0
INPUT = (S0, I0, C0)

def diff_eqs(INP,t):  
	'''The main set of equations'''
	Y=np.zeros((3))
	V = INP    
	Y[0] = mu - beta * V[0] * (V[1] + epsilon * V[2]) - mu * V[0]
	Y[1] = beta * V[0] * (V[1] + epsilon * V[2]) - gamma * V[1] - mu * V[1]
	Y[2] = q * gamma * V[1] - Gamma * V[2] - mu * V[2]
	return Y   # For odeint



t_start = 0.0; t_end = ND; t_inc = TS
t_range = np.arange(t_start, t_end+t_inc, t_inc)
RES = spi.odeint(diff_eqs,INPUT,t_range)

Rec=1. - (RES[:,0]+RES[:,1]+RES[:,2])
print RES

#Ploting
pl.subplot(311)
pl.plot(RES[:,0], '-g', label='Susceptibles')
pl.title('Program_2_7.py')
pl.xlabel('Time')
pl.ylabel('Susceptibles')
pl.subplot(312)
pl.plot(RES[:,1], '-r', label='Infectious')
pl.xlabel('Time')
pl.ylabel('Infected')
pl.subplot(313)
pl.plot(RES[:,1], '-m', label='Carriers')
pl.xlabel('Time')
pl.ylabel('Carriers')
pl.show()

--Ilias.soumpasis 15:54, 11 October 2008 (UTC)