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
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:
From state \(i\), infection moves to \(i+1\) and recovery moves to \(i-1\), with rates
Only neighbouring states communicate in one jump. The process cannot jump directly from \(i=1\) to \(i=4\).
Three rules for constructing the generator
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\):
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
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
| Condition | Meaning |
|---|---|
| \(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 entry | No 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.
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\):
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
| Code | Purpose |
|---|---|
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:
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
- Putting positive exit rates on the diagonal.
- Making each row sum to 1 as if \(Q\) were a probability matrix.
- Confusing row-origin and column-origin conventions.
- Adding rates for biologically impossible direct jumps.
- Forgetting to modify boundary rows at \(I=0\) and \(I=N\).
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.