10
Transition matrices and probability vectors
A simulated trajectory selects one state at each time. The matrix approach instead calculates the probability of being in every possible state after one time step.
A change of viewpoint
Trajectory viewpoint
Start in one state, draw a random number and select one next state.
Distribution viewpoint
Start with probabilities over the states and calculate all next-state probabilities simultaneously.
A probability distribution assigns a probability to every possible state. Its entries are non-negative and sum to 1.
The matrix calculation uses no random number. For a finite DTMC with a known transition matrix, the one-step distribution update is exact apart from ordinary computer rounding.
A small SIS example
Use a closed population of \(N=3\). The state is the infectious count:
Choose \(\beta=0.6\) per day, \(\gamma=0.2\) per day and \(\Delta t=0.5\) day. From state \(i\):
These are infection, recovery and no-change probabilities, as established in the SIS lesson.
Fix the matrix convention before calculating
This page uses a row-stochastic matrix:
Row \(i\) is the current state. Column \(j\) is the next state. Therefore every row must sum to 1.
The states are ordered \(0,1,2,3\). Row and column positions must use this same ordering.
Construct each row biologically
From an interior state \(i\), only three destinations are possible:
All other entries in that row are zero because a one-event step cannot jump over a neighbouring state.
| Current state | Next 0 | Next 1 | Next 2 | Next 3 |
|---|---|---|---|---|
| Current 0 | 1.0 | 0 | 0 | 0 |
| Current 1 | 0.1 | 0.7 | 0.2 | 0 |
| Current 2 | 0 | 0.2 | 0.6 | 0.2 |
| Current 3 | 0 | 0 | 0.3 | 0.7 |
Hence:
Interpret important rows
- Row 0: \((1,0,0,0)\). Extinction is absorbing.
- Row 1: recovery gives state 0, no change gives state 1, and infection gives state 2.
- Row 2: one step can reach states 1, 2 or 3, but not state 0.
- Row 3: infection is impossible because no susceptible people remain; recovery can reach state 2.
The many zero entries encode biologically impossible one-step movements. Because non-zero entries lie only on the main diagonal and its two neighbours, this birth–death transition matrix is tridiagonal.
The probability row vector
Using the same state order, define:
This page writes \(\boldsymbol\pi_n\) as a row vector. If the process certainly begins in state 1:
The 1 means 100% probability at state 1. It does not mean the infectious count itself is stored in the vector.
Calculate one distribution update
With a row probability vector and row-stochastic matrix:
For the certain initial state 1:
Because the initial vector places all probability on state 1, the next vector is simply row 1 of \(P\).
What matrix multiplication is doing
For each next state \(j\):
The calculation adds contributions arriving at state \(j\) from every possible current state \(i\). Each contribution is:
For a certain initial state, only one current-state contribution is non-zero. For a mixed initial distribution, several rows contribute.
Row versus column conventions
| Probability representation | Update using this page's row-stochastic (P) |
|---|---|
| Row vector | \(\boldsymbol\pi_{n+1}=\boldsymbol\pi_nP\) |
| Column vector | \(\mathbf p_{n+1}=P^{\mathsf T}\mathbf p_n\) |
Some books instead define columns as current states. Their transition matrix is the transpose of ours, and they write \(\mathbf p_{n+1}=P\mathbf p_n\). Both conventions are valid.
Never mix conventions. First state whether rows or columns represent the current state, then check the corresponding sums and use the matching multiplication order.
Three essential checks
The probability vector must also contain four non-negative entries summing to 1.
Interactive Python laboratory
The code constructs \(P\) from the SIS formulas, validates it, performs exactly one distribution update and displays the matrix and vectors as tables and graphs.
Output
Run the code to see the result.
Understand the new matrix code
| Code | Meaning |
|---|---|
np.zeros((4, 4)) | Creates a 4-by-4 matrix initially filled with zeros. |
P[i, j] | Accesses the entry in current-state row \(i\) and next-state column \(j\). |
P.sum(axis=1) | Sums across columns within each row. axis=1 therefore checks row sums. |
np.allclose(...) | Checks whether all calculated floating-point values are sufficiently close to their targets. |
pi_current @ P | Uses @ for matrix multiplication to calculate the next distribution. |
pi_current * P | Would perform element-by-element multiplication with broadcasting; it is not the required distribution update. |
P.shape | Returns the matrix dimensions as a tuple. |
Interpret the one-step result
Beginning certainly at \(I_0=1\), after one step:
- \(\Pr(I_1=0)=0.1\): recovery causes extinction;
- \(\Pr(I_1=1)=0.7\): no event occurs;
- \(\Pr(I_1=2)=0.2\): infection increases the count; and
- \(\Pr(I_1=3)=0\): reaching state 3 would require two infections in one step and is excluded.
The vector contains all four possible one-step outcomes and their probabilities. A single simulated trajectory would display only one of these outcomes.
Try these experiments
- Change the certain initial state to \(I_0=2\) using
pi_current = np.array([0, 0, 1, 0]). Which matrix row becomes the next vector? - Use the mixed distribution
[0.2, 0.5, 0.3, 0.0]. Observe how several current-state rows contribute. - Change one entry of
pi_currentwithout preserving its sum. Confirm that the validation reports the problem. - Increase
dt. Find when at least one state's no-change probability becomes invalid. - Replace
axis=1withaxis=0. Compare column sums with the required row sums.
What this lesson has—and has not—done
You can now:
- construct a transition matrix from biological event probabilities;
- interpret rows as current states and columns as next states;
- check shape, entries and row sums;
- represent certain and mixed state distributions;
- calculate one exact update using
pi_current @ P; and - distinguish a probability distribution from one random trajectory.
Not yet: this page performs only one matrix update. Lesson 11 repeatedly multiplies the vector by \(P\), follows the distribution through time and studies probability conservation and extinction probability.