During this seminar we will numerically solve systems of differential equations of SI, SIS and SIR models. <br> This experience is going to help us as we switch to network models.
In this model a sustainable infection process is considered. Infected part of population has no chance to be healed..
In other words:
\begin{equation}
\begin{cases}
\cfrac{ds(t)}{dt} = -\beta s(t)i(t)\\
\cfrac{di(t)}{dt} = \beta s(t)i(t)
\end{cases}
\\
i(t) + s(t) = 1
\end{equation}
In [ ]:
import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import odeint
%matplotlib inline
In [ ]:
def si_model( z0, T, **kwargs) :
beta = kwargs['beta']
t = np.arange( T, step = 0.1 )
si = lambda z ,t, beta : np.array([
-beta * z[0] * z[1],
beta * z[0] * z[1]])
return t, odeint(si, z0, t, (beta,))
In [ ]:
t, z = si_model( z0 = [0.9,0.1], T = 50, beta = 0.2 )
In [ ]:
# Lets plot our solution and phase-plot
fig, ax = plt.subplots(1,2,figsize=(14,6))
ax[0].plot(t, z[:,0], color='red')
ax[0].plot(t, z[:,1], color='blue')
ax[0].set_xlabel('$t$')
ax[0].set_ylabel('proportion')
ax[0].legend(['$S$','$I$'])
ax[1].plot(z[:,1], z[:,0], color = 'blue')
ax[1].set_xlabel('$I$')
ax[1].set_ylabel('$S$')
The cool thing is that we can set $\beta$ and $\gamma$ to be dependent on $t$, that is interpreted as some ''sessional'' profile of the desease. <br> Now, based on this code, implement SIS and SIR models:
SIS model allowes infected agents to be cured, but without any further immunity. \begin{equation} \begin{cases} \cfrac{ds(t)}{dt} = -\beta s(t)i(t) + \gamma i(t)\\ \cfrac{di(t)}{dt} = \beta s(t)i(t) - \gamma i(t) \end{cases} \\ i(t) + s(t) = 1 \end{equation} Implement this model and check cases when $\gamma \lessgtr \beta$
In [ ]:
def sis_model( z0, T, **kwargs) :
beta, gamma = kwargs['beta'], kwargs['gamma']
t = np.arange( T, step = 0.1 )
sis = lambda z ,t, beta, gamma : np.array([
-beta * z[0] * z[1] + gamma * z[1],
beta * z[0] * z[1] - gamma * z[1]])
return t, odeint(sis, z0, t, (beta,gamma,))
In [ ]:
t, z = si_model( z0 = [0.5,0.5], T = 50, beta = 0.5, gamma = 0.2 )
In [ ]:
# Lets plot our solution and phase-plot
fig, ax = plt.subplots(1,2,figsize=(14,6))
ax[0].plot(t, z[:,0], color='red')
ax[0].plot(t, z[:,1], color='blue')
ax[0].set_xlabel('$t$')
ax[0].set_ylabel('proportion')
ax[0].legend(['$S$','$I$'])
ax[1].plot( z[:,1], z[:,0])
ax[1].set_xlabel('$I$')
ax[1].set_ylabel('$S$')
In SIR model healed population gain immunity to the infection \begin{equation} \begin{cases} \cfrac{ds(t)}{dt} = -\beta s(t)i(t)\\ \cfrac{di(t)}{dt} = \beta s(t)i(t) - \gamma i(t)\\ \cfrac{dr(t)}{dt} = \gamma i(t) \end{cases} \\ i(t) + s(t) + r(t) = 1 \end{equation}
In [ ]:
def sir_model( z0, T, **kwargs) :
beta, gamma = kwargs['beta'], kwargs['gamma']
t = np.arange( T, step = 0.1 )
sir = lambda z, t, beta, gamma : np.array([
-beta * z[0] * z[1],
beta * z[0] * z[1] - gamma * z[1],
gamma * z[1]])
return t, odeint(sir, z0, t, (beta,gamma,))
In [ ]:
t, z = sir_model( z0 = [0.9,0.09,0.01], T = 50, beta = 0.5, gamma = 0.02 )
In [ ]:
# Lets plot our solution and phase-plot
fig, ax = plt.subplots(1,2,figsize=(14,6))
ax[0].plot(t, z[:,0], color='blue')
ax[0].plot(t, z[:,1], color='red')
ax[0].plot(t, z[:,2], color='orange')
ax[0].set_xlabel('$t$')
ax[0].set_ylabel('proportion')
ax[0].legend(['$S$','$I$', '$R$'])
ax[1].plot( z[:,0], z[:,2])
ax[1].set_xlabel('$S$')
ax[1].set_ylabel('$R$')
In [ ]: