← Continuous-Time Markov Chains

10

Generator matrices and transition structure

A generator matrix collects every possible CTMC transition rate into one table. It shows where the process can jump, how quickly it leaves each state, and which states are absorbing.

From one current state to all possible destinations

The preceding lessons generated one random event at a time. A generator matrix gives a global description of the same CTMC: every row represents a current state and every column represents a possible next state.

Convention used throughout this lesson

\[q_{ij}=\text{rate of moving from current state }i\text{ to destination state }j.\]

Therefore, rows are origins and columns are destinations. Other books may use the transpose convention, so always check the definition before interpreting a matrix.

A small SIS example

Use a closed SIS population of \(N=5\). The state is the infectious count:

\[I\in\{0,1,2,3,4,5\}.\]

From state \(i\), infection moves to \(i+1\) and recovery moves to \(i-1\), with rates

\[b(i)=\beta\frac{(N-i)i}{N},\qquad d(i)=\gamma i.\]

Only neighbouring states communicate in one jump. The process cannot jump directly from \(i=1\) to \(i=4\).

Three rules for constructing the generator

Off-diagonal entriesFor \(i\ne j\), place the non-negative rate from state \(i\) to state \(j\).
Diagonal entrySet \(q_{ii}\) to the negative total rate of leaving state \(i\).
Impossible jumpsUse zero when the CTMC cannot move from \(i\) to \(j\) in one event.
\[q_{ii}=-\sum_{j\ne i}q_{ij}.\]

Consequently every row sums to zero. The diagonal is not an event rate and is not a negative probability; it balances the outward rates.

The SIS generator pattern

For interior states \(1\le i\le N-1\):

\[ q_{i,i+1}=b(i),\qquad q_{i,i-1}=d(i),\qquad q_{ii}=-[b(i)+d(i)]. \]

At \(i=N\), infection is impossible but recovery remains possible. At \(i=0\), both rates are zero, so the complete row is zero.

Interior row

Contains one recovery rate, one negative diagonal entry and one infection rate.

Absorbing row

A zero row means the state has no outward transition. Here, \(I=0\) is disease-free and absorbing.

Why a zero row does not mean zero probability

The generator \(Q\) contains rates, not one-step probabilities. For a sufficiently short interval \(h\), the transition-probability matrix is approximated by

\[P(h)\approx I+hQ.\]

For the absorbing state, row 0 of \(Q\) is zero, but row 0 of \(P(h)\) has a 1 on its diagonal. Thus, once the process reaches state 0, it remains there with probability 1.

Necessary generator conditions

ConditionMeaning
\(q_{ij}\ge0\) for \(i\ne j\)Transition rates cannot be negative.
\(q_{ii}\le0\)The diagonal is the negative exit rate.
\(\sum_j q_{ij}=0\)Each row balances its outward rates.
Zero off-diagonal entryNo direct one-event transition between those two states.

Interactive Python laboratory

Run the code to build \(Q\) from the biological events rather than typing the matrix manually. It prints the generator, verifies its conditions, forms a valid small-interval approximation, and draws both the matrix structure and the state-transition diagram.

Interactive PythonSIS generator matrix

Output

Run the code to see the result.

Read one row biologically

With \(N=5\), \(\beta=0.30\) and \(\gamma=0.10\), consider state \(i=2\):

\[ b(2)=0.30\frac{(5-2)2}{5}=0.36, \qquad d(2)=0.10(2)=0.20. \] \[ (q_{2,1},q_{2,2},q_{2,3})=(0.20,-0.56,0.36). \]

The CTMC can recover to state 1 at rate 0.20 or infect to state 3 at rate 0.36. Its total exit rate is 0.56, giving diagonal entry \(-0.56\). Every other entry in row 2 is zero.

Understand the Python construction

CodePurpose
np.zeros((N + 1, N + 1))Creates one row and column for each of the \(N+1\) possible infectious counts.
Q[i, i + 1]Stores the infection rate from state \(i\) to state \(i+1\).
Q[i, i - 1]Stores the recovery rate from state \(i\) to state \(i-1\).
np.fill_diagonal(...)Removes diagonal entries from a copy so only off-diagonal rates are tested.
np.allclose(..., 0)Checks numerical equality while allowing tiny floating-point rounding errors.
np.eye(N + 1)Creates the identity matrix used in \(I+hQ\).

Why the interval restriction matters

For \(I+hQ\) to act as a probability matrix, its diagonal entries must remain non-negative:

\[1-h a_0(i)\ge0\quad\text{for every state }i.\]

The code chooses \(h=0.5/\max_i a_0(i)\), which safely satisfies this condition. This short-interval matrix is an approximation. The exact transition matrix over a general time interval requires the matrix exponential, which belongs to later probability-evolution work.

Generator versus Gillespie simulation

Gillespie algorithm

Uses the rates in the current row to generate one random waiting time and one random destination.

Generator matrix

Collects the rates for every possible current state and supports equations for the full probability distribution.

They describe the same CTMC at different levels. The generator is not an alternative biological model to the event list; it is a matrix representation of that event list.

Common mistakes

What this lesson adds

You can now translate biological transitions into a generator matrix, interpret off-diagonal and diagonal entries, identify absorbing states, validate the matrix in Python, and connect \(Q\) to short-interval probabilities. The next lesson returns to simulation and uses many independent CTMC trajectories to study variability.