Python Programs for Modelling Infectious Diseases book:Chapter 7:Program 7.8

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

Program 7.8 is a pairwise SIS approximation model (page 285 of the book). These are the equations and the code of the model:

Equations

 \frac{dX}{dt} = \gamma*(N-X)-\tau*[XY]

 \frac{d[XY]}{dt} = \tau*\frac{n-1}{n}*\frac{((n*X-[XY])*[XY]}{X}+\gamma*(n*N-n*X-[XY])-\tau*[XY]-\tau*\frac{n-1}{n}*\frac{[XY]^{2}}{X}-\gamma*[XY]

Code

Program 7.8: Pairwise SIS approximation model
#!/usr/bin/env python

####################################################################
###    This is the PYTHON version of program 7.8 from page 285 of  #
### "Modeling Infectious Disease in humans and animals"            #
### by Keeling & Rohani.					   #
###								   #
### It is the pairwise approximation to the SIS model on a random  #
### network of N individuals, each with n contacts.                #
###								   #
### Initially it is assumed that there is no correlation between   #
### infected and susceptible individuals in the network.           #
####################################################################

##########################################################################
### 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

n=4;
tau=0.1;
gamma=0.05;
Y0=1.0;
N0=10000;
ND=MaxTime=100.0;
TS=1.0
X0=N0-Y0
XY0=n*Y0*X0/N0; 

INPUT=np.hstack((X0,XY0))

def diff_eqs(INP,t):  
	'''The main set of equations'''
	Y=np.zeros((2))
	V = INP   
	Y[0] = gamma*(N0-V[0]) - tau*V[1];
	Y[1] = tau*(n-1)*(n*V[0]-V[1])*V[1]/(n*V[0]) + gamma*(n*N0-n*V[0]-V[1]) - tau*V[1]\
	- tau*(n-1)*V[1]*V[1]/(n*V[0]) - gamma*V[1];
	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)
X = RES[:,0]
XY= RES[:,1]
Y=N0-X


#Ploting
pl.subplot(311)
pl.plot(Y, '-g')
pl.ylabel('Infectious')
pl.subplot(312)
pl.plot(XY, '-r')
pl.ylabel('[XY] pairs')
pl.subplot(313)
pl.plot(XY/((n*X)*(Y/N0)), '-r')
pl.ylabel('relative XY correlation')
pl.xlabel('Time (Years)')
print XY/(n*X*Y/N0)

pl.show()

--Ilias.soumpasis 17:52, 12 October 2008 (UTC)