Simple Problem
For a simple problem, we consider the SIR model defined by
\[\begin{split}\frac{dS}{dt} &= -\beta SI \\
\frac{dI}{dt} &= \beta SI - \gamma I \\
\frac{dR}{dt} &= \gamma I.\end{split}\]
which consists of two transitions
![digraph SIR_Model {
rankdir=LR;
size="8"
node [shape = circle];
S -> I [ label = "βSI" ];
I -> R [ label = "γI" ];
}](../_images/graphviz-92b16b12fa47339f1b4b0b260afc3a978b332a51.png)
Let’s define this using the code block below
In [1]: from pygom import SimulateOde, Transition, TransitionType
In [2]: ode1 = Transition(origin='S', equation='-beta*S*I', transition_type=TransitionType.ODE)
In [3]: ode2 = Transition(origin='I', equation='beta*S*I - gamma*I', transition_type=TransitionType.ODE)
In [4]: ode3 = Transition(origin='R', equation='gamma*I', transition_type=TransitionType.ODE)
In [5]: stateList = ['S', 'I', 'R']
In [6]: paramList = ['beta', 'gamma']
In [7]: ode = SimulateOde(stateList,
...: paramList,
...: ode=[ode1, ode2, ode3])
...:
In [8]: ode.get_transition_matrix()
Out[8]:
Matrix([
[0, 0, 0],
[0, 0, 0],
[0, 0, 0]])
and the last line shows that the transition matrix is empty. This is the expected result because SimulateOdeModel was not initialized using transitions. We populate the transition matrix below and demonstrate the difference.
In [9]: ode = ode.get_unrolled_obj()
In [10]: ode.get_transition_matrix()
Out[10]:
Matrix([
[0, I*S*beta, 0],
[0, 0, I*gamma],
[0, 0, 0]])