Python Programs for Modelling Infectious Diseases book:Chapter 3:Program 3.1

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

Program 3.1 is a SIS model with 2 risk groups (page 58 of the book). These are the equations and the code of the model:

Equations

 \frac{dI_{H}}{dt} = \beta_{HH}*S_{H}*I_{H}+\beta_{HL}*S_{H}*I_{L}-\gamma*I{H}

 \frac{dI_{L}}{dt} = \beta_{LH}*S_{L}*I_{H}+\beta_{LL}*S_{L}*I_{L}-\gamma*I{L}

Code

Program 3.1: SIS model with 2 risk groups
#!/usr/bin/env python

####################################################################
###    This is the PYTHON version of program 3.1 from page 58 of   #
### "Modeling Infectious Disease in humans and animals"            #
### by Keeling & Rohani.					   #
###								   #
### It is the SIS model with two different risk-groups.		   #
####################################################################


##########################################################################
### 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=[10., 0.1, 0.1, 1.]
gamma=1.0
nH=0.2
IH=1e-5
IL=1e-3
nT=1.0
nL=nT-nH
SH=nH-IH
SL=nL-IL
ND=15.
TS=1.0

INPUT = (SH,IH,SL,IL)

def diff_eqs(INP,t):  
	'''The main set of equations'''
	Y=np.zeros((4))
	V = INP   
	Y[0] = - (beta[0] * V[1] + beta[1] * V[3]) * V[0] + gamma * V[1]
	Y[1] = (beta[0] * V[1] + beta[1] * V[3]) * V[0] - gamma * V[1]
	Y[2] = - (beta[2] * V[1] + beta[3] * V[3]) * V[2] + gamma * V[3]
	Y[3] = (beta[2] * V[1] + beta[3] * V[3]) * V[2] - gamma * V[3]
	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)

print RES

#Ploting
pl.subplot(211)
pl.plot(RES[:,1], '-r', label='High Risk')
pl.plot(RES[:,3], '--r', label='Low Risk')
pl.legend(loc=0)
pl.title('Program_3_1.py')
pl.xlabel('Time')
pl.ylabel('Infectious')
pl.subplot(212)
pl.semilogy(RES[:,1], '-r', label='High Risk')
pl.semilogy(RES[:,3], '--r', label='Low Risk')
pl.legend(loc=0)
pl.xlabel('Time')
pl.ylabel('Infectious')
pl.show()

--Ilias.soumpasis 18:22, 11 October 2008 (UTC)