I want to use the SDEint package to give a numerical solution (plot) of the following stochastic SIR model. Namely, a system of SDEs.
$$\begin{cases} dS = -\beta SIdt - \sigma SIdW \\ dI = (\beta SI - \gamma I)dt + \sigma SIdW \\ dR = \gamma Idt \end{cases}$$
Here is the code I have been trying so far. Below I will explain my issues.
import matplotlib.pyplot as plt
import numpy as np
import sdeint
tspan = np.linspace(0, 5, 1001)
y0 = np.array([900/1000, 100/1000, 0.,])
S = y0[0]
I = y0[1]
R = y0[2]
def f(y, t):
f0 = -.80*S*I
f1 = .80*S*I - 1.1*I
f2 = 1.1*I
return np.array([f0, f1, f2,])
def G(y,t):
return np.array([[-0.9*S*I, 0, 0],
[0.9*S*I, 0, 0],
[0,0,0]])
result = sdeint.itoint(f, G, y0, tspan )
plt.plot(result)
plt.show()
$dS$ and $dI$ are effected by the same noise $dW$, previous I had used np.diag but that is for independent Wiener processes but they are not independent here, they should be the same. That is if I look at just the diffusion portion of the system I can write that as
$$ \left[ \begin{matrix} -\sigma SI \\ \sigma SI \\ 0 \end{matrix} \right]dW$$
Unsure of how to input this into I use the following matrix/array in my definition of G in my code
$$ \left[ \begin{matrix} -\sigma SI & 0 & 0 \\ \sigma SI & 0 & 0 \\ 0&0&0 \end{matrix} \right] $$
which when multiplied by a column vector of say three Wiener processes will yield what I want above.
The key issue I am noticing when I run my script, I get the plotted paths, and specifically for $I$, it dipping below $0$ which should not be the case, these numerical solutions should be remaining non-negative.
My second issue is the plotted path for $S$ and $I$ are coming out as reflections of each other, which should not be exactly the case as they are not symmetric in their respective definitions.
Any input, or recommendations for another package or method is appreciated.
itoSRI2
(Heun-like method, strong order 1)? One would have better chances to avoid negative values with implicit or semi-implicit methods, Kloeden/Platen have some methods of this kind. $\endgroup$itoSRI2
yet but do plan to experiment with it. $\endgroup$np.array([[-0.9*S*I], [0.9*S*I], [0]])
. $\endgroup$