Python Programs for Modelling Infectious Diseases book:Chapter 4:Program 4.4

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

Program 4.4 is a SIR model for mosquito vectors (page 123 of the book). These are the equations and the code of the model:

Equations

 \frac{dX_{H}}{dt} = \nu_{H}-r*T_{HM}*X_{H}*Y_{M}-\mu_{H}*X_{H}

 \frac{dY_{H}}{dt} = r*T_{HM}*X_{H}*Y_{M}-\mu_{H}*Y_{H}-\gamma_{H}*Y_{H}

 \frac{dX_{M}}{dt} = \nu_{M}-r*T_{MH}*X_{M}*Y_{H}-\mu_{M}*X_{M}

 \frac{dY_{H}}{dt} = r*T_{MH}*X_{M}*Y_{H}-\mu_{M}*Y_{M}

Code

Program 4.4: SIR model for mosquito vectors
#!/usr/bin/env python

####################################################################
###    This is the PYTHON version of program 4.4 from page 136 of  #
### "Modeling Infectious Disease in humans and animals"            #
### by Keeling & Rohani.					   #
###								   #
### It is a simple model of vector borne transmission of infection.# 
### We implicitly assume a vector-notation, which humans being the #
### first entry and mosquitoes being the second.                   #
### n the default parameterisation of the model mosquitoes never   #
### recover from infection, although this is allowed by the 	   #
### general formulation.                                           #
####################################################################

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

r=0.5/1e3;
beta=np.array([[0, 0.5], [0.8, 0]]);
gamma=np.array([0.033, 0]);
mu=np.array([5.5e-5, 0.143]);
nu=np.array([5.5e-2, 1.443e3]);
X0=np.array([1e3, 1e4]);
Y0=np.array([1, 1]);
ND=MaxTime=1000.0;
TS=1.0

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

def diff_eqs(INP,t):  
	'''The main set of equations'''
	Y=np.zeros((4))
	V = INP   
	Y[0] = nu[0] - V[0] * r * (beta[0][1]*V[3]) - mu[0] * V[0]
	Y[1] = nu[1] - V[1] * r * (beta[1][0]*V[2]) - mu[1] * V[1]
	Y[2] = V[0] * r * (beta[0][1]*V[3]) - gamma[0] * V[2] - mu[0] * V[2]
	Y[3] = V[1] * r * (beta[1][0]*V[2]) - mu[1] * 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(311)
pl.subplot(221)
pl.semilogy(RES[:,0], 'g', label='SH')
pl.xlabel('Time')
pl.ylabel('Susceptible Humans')
pl.subplot(222)
pl.semilogy(RES[:,1], 'g', label='SM')
pl.xlabel('Time')
pl.ylabel('Susceptible Mosquitoes')
pl.subplot(223)
pl.semilogy(RES[:,2], 'r', label='IH')
pl.xlabel('Time')
pl.ylabel('Infected Humans')
pl.subplot(224)
pl.semilogy(RES[:,3], 'r', label='IM')
pl.xlabel('Time')
pl.ylabel('Infected Mosquitoes')
pl.show()

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