Skip to article frontmatterSkip to article content

Appendix: Absorbing Markov Chains

Motivating Example: Escaping a Maze

A student finds themselves in a strange maze of connected rooms. Some rooms are marked as exits. Once the student reaches one, they leave the maze and do not return. The other rooms are ordinary: the student moves between them until they reach an exit. Each turn, the student chooses a connected room uniformly at random.

Suppose the maze consists of six rooms labeled 1 through 6, with rooms 5 and 6 being exits. The student starts in one of the other rooms and moves randomly along available corridors. The structure of the maze is shown below:

Let PP be the transition matrix, where rows and columns correspond to the rooms in order:

P=(01/21/20001/2001/2001/3001/31/3001/31/3001/3000010000001)P = \begin{pmatrix} 0 & 1/2 & 1/2 & 0 & 0 & 0 \\ 1/2 & 0 & 0 & 1/2 & 0 & 0 \\ 1/3 & 0 & 0 & 1/3 & 1/3 & 0 \\ 0 & 1/3 & 1/3 & 0 & 0 & 1/3 \\ 0 & 0 & 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 0 & 0 & 1 \\ \end{pmatrix}

Rooms 5 and 6 are absorbing: the student remains there once entered. The rest are transient. In the following sections, we will compute:

This chapter will describe a powerful mathematical tool: Markov Chains and in particular Absorbing Markov Chains.

Theory

Definition of a Markov Chain


Let S={s1,s2,,sn} S = \{s_1, s_2, \dots, s_n\} be a finite set of states. A Markov chain is defined by:

Pij=P(Xt+1=sjXt=si)P_{ij} = \mathbb{P}(X_{t+1} = s_j \mid X_t = s_i)

with j=1nPij=1\sum_{j=1}^nP_{ij}=1 for all 1in1\leq i \leq n.


A state of the Markov chain can be described by a probability distribution vector πR[0,1]1\pi\in\mathbb{R}_[0, 1]^1 such that i=1nπi=1\sum_{i=1}^n \pi_i=1.

This gives:

π(t+1)=π(t)P\pi^{(t + 1)} = \pi ^{(t)}P

and so:

π(t)=π(0)Pt\pi^{(t)} = \pi ^{(0)} P ^ t

Example: Escaping the Maze

Let us assume that students are known to start in one of the room with equal probability. This implies that:

π(0)=(1/41/41/41/400)\pi ^{(0)}=\begin{pmatrix}1/4&1/4&1/4&1/4&0&0\end{pmatrix}
  1. Calculate π(1)\pi ^{(1)}

  2. Calculate π(2)\pi ^{(2)}

  3. Given that:

    P1000(0.0.0.0.0.54550.45450.0.0.0.0.45450.54550.0.0.0.0.63640.36360.0.0.0.0.36360.63640.0.0.0.1.0.0.0.0.0.0.1.)P ^ {1000} \approx \begin{pmatrix} 0.& 0.& 0.& 0.& 0.5455& 0.4545\\ 0.& 0.& 0.& 0.& 0.4545& 0.5455\\ 0.& 0.& 0.& 0.& 0.6364& 0.3636\\ 0.& 0.& 0.& 0.& 0.3636& 0.6364\\ 0.& 0.& 0.& 0.& 1.& 0. \\ 0.& 0.& 0.& 0.& 0.& 1. \end{pmatrix}

    What is the likely location of a student after 1000 time steps?

  4. We have:

π(1)=π(0)P=(1/41/2+1/41/3,1/41/2+1/41/3,1/41/2+1/41/3,1/41/2+1/41/3,1/41/3+01,1/41/3+01)=(5/24,5/24,5/24,5/24,1/12,1/12)\begin{align*} \pi ^{(1)} &= \pi ^{(0)} P\\ &= (1/4\cdot1/2 + 1/4 \cdot 1/3, 1/4\cdot1/2 + 1/4 \cdot 1/3, 1/4\cdot1/2 + 1/4 \cdot 1/3, 1/4\cdot1/2 + 1/4 \cdot 1/3, 1/4\cdot 1/3 + 0\cdot 1, 1/4\cdot 1/3 + 0\cdot 1)\\ &= (5/24, 5/24, 5/24, 5/24, 1/12, 1/12) \end{align*}
  1. We have:

$$

π(2)=π(1)P=(5/241/2+51/3,5/241/2+51/3,5/241/2+51/3,5/241/2+51/3,5/241/3+1/2,5/241/3+1/2)=(25/144,25/144,25/144,25/144,11/72,11/72)\begin{align*} \pi ^{(2)} &= \pi ^{(1)} P\\ &= (5/24\cdot 1/2 + 5\cdot 1/3, 5/24\cdot 1/2 + 5\cdot 1/3, 5/24\cdot 1/2 + 5\cdot 1/3, 5/24\cdot 1/2 + 5\cdot 1/3, 5/24\cdot1/3+1/2, 5/24\cdot1/3+1/2) &= (25/144, 25/144, 25/144, 25/144, 11/72, 11/72) \end{align*}

$$

  1. Finally:
π(1000)=π(0)P1000(0,0,0,0,.5,.5)\begin{align*} \pi ^{(1000)} &= \pi ^{(0)} P ^ 1000\\ &\approx (0, 0, 0, 0, .5, .5) \end{align*}

We note that after 1000 time steps all of our probability is in the last two states. This is due to the nature of the maze but also the nature of the particular type of Markov chain which is an absorbing Markov chain: the last two states are absorbing states.

Definition: Absorbing Markov Chain


A Markov chain with transition matrix PP is absorbing if:

  1. It has at least one absorbing state, i.e., a state ii such that Pii=1P_{ii} = 1.

  2. From every non-absorbing (transient) state jj, there is a non-zero probability of reaching some absorbing state in a finite number of steps.

In other words, the chain cannot get “stuck” forever in a subset of transient states.


An absorbing Markov chain is a Markov chain whose transition matrix PP can be written (up to an ordering of states) in the following canonical form:

P=(QR0I)P = \begin{pmatrix} Q & R\\ 0 & I \end{pmatrix}

where:

Example: The Maze as an absorbing Markov chain

For Motivating Example: Escaping a Maze the Markov chain PP can be written in the form of (A1.10) with:

Q=(01/21/201/2001/21/3001/301/31/30)Q = \begin{pmatrix} 0 & 1/2 & 1/2 & 0 \\ 1/2 & 0 & 0 & 1/2 \\ 1/3 & 0 & 0 & 1/3 \\ 0 & 1/3 & 1/3 & 0 \\ \end{pmatrix}
R=(00001/3001/3)R = \begin{pmatrix} 0 & 0 \\ 0 & 0 \\ 1/3 & 0 \\ 0 & 1/3 \\ \end{pmatrix}
I=(1001)I = \begin{pmatrix} 1 & 0 \\ 0 & 1 \end{pmatrix}

Definition: Fundamental Matrix

For an absorbing Markov chain in the form (A1.10) the fundamental matrix NN is given by:

N=(IQ)1N = (I - Q) ^ {-1}

The entry NijN_ij gives the expected number of times the process is in transient state jj before being absorbed having started in state ii.

Example: Fundamental matrix of the Maze

For Motivating Example: Escaping a Maze the fundamental matrix is given by:

N=((1000010000100001)(01/21/201/2001/21/3001/301/31/30))1=((11/21/201/2101/21/3011/301/31/31))1\begin{align*} N &= \left( \begin{pmatrix} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\ 0 & 0 & 1 & 0\\ 0 & 0 & 0 & 1 \end{pmatrix} - \begin{pmatrix} 0 & 1/2 & 1/2 & 0 \\ 1/2 & 0 & 0 & 1/2 \\ 1/3 & 0 & 0 & 1/3 \\ 0 & 1/3 & 1/3 & 0 \\ \end{pmatrix} \right) ^ {-1}\\ &= \left( \begin{pmatrix} 1 & -1/2 & -1/2 & 0\\ -1/2 & 1 & 0 & -1/2\\ -1/3 & 0 & 1 & -1/3\\ 0 & -1/3 & -1/3 & 1 \end{pmatrix} \right) ^ {-1}\\ \end{align*}

This inverse can be computed, a technique for doing this will be reviewed in Definition: Gauss-Jordan Method for inverting a matrix to give:

N=(26/1118/1118/1115/1118/1126/1115/1118/1112/1110/1121/1112/1110/1112/1112/1121/11)N = \begin{pmatrix}26/11 & 18/11 & 18/11 & 15/11\\ 18/11 & 26/11 & 15/11 & 18/11\\ 12/11 & 10/11 & 21/11 & 12/11\\ 10/11 & 12/11 & 12/11 & 21/11 \end{pmatrix}

We can read from this matrix that for example, starting in state i=2i=2 the student will visit state j=3j=3 on average N23=1.36N_{23}=1.36 times.

This will allow us to identify which absorption state is the most likely.

Definition: Absorption Probability Matrix

For an absorbing Markov chain in the form (A1.10) the absorption probability matrix BB is given by:

B=NRB = NR

The probability of being absorbed in to absorbing state jj having started at state ii is BijB_{ij}.

Example: Probability of absorbing state in the Maze

For Motivating Example: Escaping a Maze the absorption probability matrix is given by:

B=NR=(26/1118/1118/1115/1118/1126/1115/1118/1112/1110/1121/1112/1110/1112/1112/1121/11)(00001/3001/3)=(6/115/115/116/117/114/114/117/11)\begin{align*} B & = N R\\ & = \begin{pmatrix}26/11 & 18/11 & 18/11 & 15/11\\ 18/11 & 26/11 & 15/11 & 18/11\\ 12/11 & 10/11 & 21/11 & 12/11\\ 10/11 & 12/11 & 12/11 & 21/11 \end{pmatrix} \begin{pmatrix} 0 & 0 \\ 0 & 0 \\ 1/3 & 0 \\ 0 & 1/3 \\ \end{pmatrix}\\ &=\begin{pmatrix} 6/11 & 5/11\\ 5/11 & 6/11\\ 7/11 & 4/11\\ 4/11 & 7/11 \end{pmatrix} \end{align*}

Definition: Gauss-Jordan Method for inverting a matrix

The Gauss-Jordan Method for inverting a non-singular matrix ARn×nA\in\mathbb{R}^{n \times n}:

  1. Set up the augmented matrix [AI][A \mid I], where II is the n×nn \times n identity matrix.
  2. Use row operations:
    • Swap rows;
    • Scaling rows;
    • Adding scalar multiples of a row to another row.
  3. One the left hand side of the augmented matrix become II the right hand side is A1A^{-1}.

Example: Compute the inverse of a 4 by 4 matrix

Let us compute the inverse of:

A=(11/21/201/2101/21/3011/301/31/31)A = \begin{pmatrix} 1 & -1/2 & -1/2 & 0\\ -1/2 & 1 & 0 & -1/2\\ -1/3 & 0 & 1 & -1/3\\ 0 & -1/3 & -1/3 & 1 \end{pmatrix}

First we create the augmented matrix:

(11/21/2010001/2101/201001/3011/3001001/31/310001)\begin{pmatrix} 1 & -1/2 & -1/2 & 0 & 1 & 0 & 0 & 0\\ -1/2 & 1 & 0 & -1/2 & 0 & 1 & 0 & 0\\ -1/3 & 0 & 1 & -1/3 & 0 & 0 & 1 & 0\\ 0 & -1/3 & -1/3 & 1 & 0 & 0 & 0 & 1 \end{pmatrix}

Let us add 1/21/2 row 1 to row 2 and 1/31/3 row 1 to row 3:

(11/21/20100003/41/41/21/210001/65/61/21/301001/31/310001)\begin{pmatrix} 1 & -1/2 & -1/2 & 0 & 1 & 0 & 0 & 0\\ 0 & 3/4 & -1/4 & -1/2 & 1/2 & 1 & 0 & 0\\ 0 & -1/6 & 5/6 & -1/2 & 1/3 & 0 & 1 & 0\\ 0 & -1/3 & -1/3 & 1 & 0 & 0 & 0 & 1 \end{pmatrix}

Let us multiple row 2 by 4/34/3 (to create a leading 1):

(11/21/201000011/32/32/34/30001/65/61/31/301001/31/310001)\begin{pmatrix} 1 & - 1/2 & - 1/2 & 0 & 1 & 0 & 0 & 0\\ 0 & 1 & - 1/3 & - 2/3 & 2/3 & 4/3 & 0 & 0\\ 0 & - 1/6 & 5/6 & - 1/3 & 1/3 & 0 & 1 & 0\\ 0 & - 1/3 & - 1/3 & 1 & 0 & 0 & 0 & 1 \end{pmatrix}

Let us:

(102/31/34/32/300011/32/32/34/300007/94/94/92/910004/97/92/94/901)\begin{pmatrix} 1 & 0 & - 2/3 & - 1/3 & 4/3 & 2/3 & 0 & 0\\ 0 & 1 & - 1/3 & - 2/3 & 2/3 & 4/3 & 0 & 0\\ 0 & 0 & 7/9 & - 4/9 & 4/9 & 2/9 & 1 & 0\\ 0 & 0 & - 4/9 & 7/9 & 2/9 & 4/9 & 0 & 1 \end{pmatrix}

Let us multiply row 3 by 9/79/7:

(102/31/34/32/300011/32/32/34/3000014/74/72/79/70004/97/92/94/901)\begin{pmatrix} 1 & 0 & - 2/3 & - 1/3 & 4/3 & 2/3 & 0 & 0\\ 0 & 1 & - 1/3 & - 2/3 & 2/3 & 4/3 & 0 & 0\\ 0 & 0 & 1 & - 4/7 & 4/7 & 2/7 & 9/7 & 0\\ 0 & 0 & - 4/9 & 7/9 & 2/9 & 4/9 & 0 & 1 \end{pmatrix}

Let us:

(1005/712/76/76/700106/76/710/73/700014/74/72/79/7000011/2110/214/74/71)\begin{pmatrix} 1 & 0 & 0 & - 5/7 & 12/7 & 6/7 & 6/7 & 0\\ 0 & 1 & 0 & - 6/7 & 6/7 & 10/7 & 3/7 & 0\\ 0 & 0 & 1 & - 4/7 & 4/7 & 2/7 & 9/7 & 0\\ 0 & 0 & 0 & 11/21 & 10/21 & 4/7 & 4/7 & 1 \end{pmatrix}

Let us multiply row 4 by 21/1121/11:

(1005/712/76/76/700106/76/710/73/700014/74/72/79/70000110/1112/1112/1121/11)\begin{pmatrix} 1 & 0 & 0 & - 5/7 & 12/7 & 6/7 & 6/7 & 0\\ 0 & 1 & 0 & - 6/7 & 6/7 & 10/7 & 3/7 & 0\\ 0 & 0 & 1 & - 4/7 & 4/7 & 2/7 & 9/7 & 0\\ 0 & 0 & 0 & 1 & 10/11 & 12/11 & 12/11 & 21/11 \end{pmatrix}

Let us:

(100026/1118/1118/1115/11010018/1126/1115/1118/11001012/1110/1121/1112/11000110/1112/1112/1121/11)\begin{pmatrix} 1 & 0 & 0 & 0 & 26/11 & 18/11 & 18/11 & 15/11\\ 0 & 1 & 0 & 0 & 18/11 & 26/11 & 15/11 & 18/11\\ 0 & 0 & 1 & 0 & 12/11 & 10/11 & 21/11 & 12/11\\ 0 & 0 & 0 & 1 & 10/11 & 12/11 & 12/11 & 21/11 \end{pmatrix}

This has created the identity matrix on the left and results in the following inverse of AA (which was used in Example: Fundamental matrix of the Maze):

A1=(11/21/201/2101/21/3011/301/31/31)A^{-1} = \begin{pmatrix} 1 & -1/2 & -1/2 & 0\\ -1/2 & 1 & 0 & -1/2\\ -1/3 & 0 & 1 & -1/3\\ 0 & -1/3 & -1/3 & 1 \end{pmatrix}

Exercises

Exercise: Transition Classification

Consider the following Markov chain with transition matrix:

P=(0.50.5000.250.50.25000.250.50.250001)P = \begin{pmatrix} 0.5 & 0.5 & 0 & 0 \\ 0.25 & 0.5 & 0.25 & 0 \\ 0 & 0.25 & 0.5 & 0.25 \\ 0 & 0 & 0 & 1 \end{pmatrix}
  1. Identify which states are transient and which are absorbing.
  2. Write PP in canonical form.
  3. Compute the fundamental matrix NN.
  4. Use NN to compute the expected number of steps until absorption starting from each transient state.

Exercise: Expected Visits

Let PP be the maze transition matrix from Section Motivating Example: Escaping a Maze. Suppose the student starts in Room 1.

  1. How many times on average will the student visit Room 4 before reaching an exit?
  2. Which ordinary room is visited most often in expectation when starting from Room 3?

Exercise: Symbolic Fundamental Matrix

Let

Q=(0ab0)Q = \begin{pmatrix} 0 & a \\ b & 0 \end{pmatrix}

where 0<a,b<10 < a, b < 1.

  1. Compute the fundamental matrix N=(IQ)1N = (I - Q)^{-1} symbolically.
  2. Express the expected number of total steps before absorption from each starting state in terms of aa and bb.

Exercise: Absorption Probabilities

Suppose a Markov chain has:

Q=(0.20.30.40.1),R=(0.5000.5)Q = \begin{pmatrix} 0.2 & 0.3 \\ 0.4 & 0.1 \end{pmatrix}, \qquad R = \begin{pmatrix} 0.5 & 0 \\ 0 & 0.5 \end{pmatrix}
  1. Compute the fundamental matrix NN.
  2. Compute the absorption probability matrix B=NRB = NR.
  3. Interpret the meaning of B12B_{12}.

Programming

The main computational tools required in this chapter are matrix manipulations. In this section, we demonstrate two Python libraries that support this: one for numerical computation and one for symbolic computation. These operate in different number systems, allowing both approximate and exact linear algebra.

Using Numpy for Numeric Matrix Calculations

Numpy Harris et al., 2020 is the standard Python library for numerical computations. Here are some basic examples:

import numpy as np

A = np.array(
    [
        [4, 5],
        [7, 8],
    ]
)
B = np.array(
    [
        [1 / 4, 1 / 5],
        [8, 7],
    ]
)

A + 7 * B

Matrix multiplication is carried out using the @ operator:

A @ B

To raise a matrix to a power or compute its inverse, we use the numpy.linalg submodule:

import numpy.linalg

np.linalg.matrix_power(A, 3)
np.linalg.inv(A)

Using Sympy for Symbolic Matrix Computations

Sympy Meurer et al., 2017 is the standard Python library for symbolic mathematics. It allows for exact arithmetic using symbolic expressions:

import sympy as sym

a = sym.Symbol("a")
b = sym.Symbol("b")
c = sym.Symbol("c")
d = sym.Symbol("d")

A = sym.Matrix(
    [
        [a, b],
        [c, d],
    ]
)

Most operations follow the same syntax as in Numpy. For matrix exponentiation and inversion:

A ** 3
A.inv()

Using Sympy for Exact Row Operations

Row operations can also be performed using Sympy with exact rational arithmetic. The S operator creates exact symbolic constants:

A = sym.Matrix(
    [
        [1          , -sym.S(1)/2, -sym.S(1)/2, 0          , 1, 0, 0, 0],
        [-sym.S(1)/2, 1          , 0          , -sym.S(1)/2, 0, 1, 0, 0],
        [-sym.S(1)/3, 0          , 1          , -sym.S(1)/3, 0, 0, 1, 0],
        [0          , -sym.S(1)/3, -sym.S(1)/3, 1          , 0, 0, 0, 1],
    ]
)
A

To add 1/21/2 of row 1 to row 2, and 1/31/3 of row 1 to row 3:

A[1, :] = A[0, :] / 2 + A[1, :]
A[2, :] = A[0, :] / 3 + A[2, :]
A

To scale row 2 by 4/34/3:

A[1, :] = 4 * A[1, :] / 3
A

Notable Research

The first formal description of the canonical form of an absorbing Markov chain is given in Snell, 1959, which served as a precursor to the influential book published in 1960 and later reissued in Kemeny & Snell, 1976.

Absorbing Markov chains have a wide range of applications. Of particular relevance to this book is their use in discrete models of evolutionary dynamics, as discussed in Moran Process. A notable example of this approach appears in Nowak & Sigmund, 2004.

Beyond the scope of this book, absorbing Markov chains have been applied to many other domains, demonstrating their versatility and theoretical interest:

Conclusion

In this appendix, we explored absorbing Markov chains through both theory and application. These models provide powerful tools for analysing systems where eventual absorption is guaranteed — such as escape processes, games, and evolutionary dynamics.

The key concepts covered in this chapter are summarised Table A1.1.

Table A1.1:Summary of absorbing Markov chains

ConceptDescription
Markov ChainA sequence of random states with memoryless transitions
Absorbing StateA state that, once entered, cannot be left
Transient StateA non-absorbing state that leads to absorption with non-zero probability
Canonical FormMatrix structure separating transient and absorbing states
Fundamental Matrix (NN)N=(IQ)1N = (I - Q)^{-1} gives expected visits to transient states before absorption
Absorption Probability MatrixB=NRB = NR gives the probability of ending in each absorbing state
Gauss-Jordan EliminationA method to compute matrix inverses using row operations
References
  1. Harris, C. R., Millman, K. J., van der Walt, S. J., Gommers, R., Virtanen, P., Cournapeau, D., Wieser, E., Taylor, J., Berg, S., Smith, N. J., Kern, R., Picus, M., Hoyer, S., van Kerkwijk, M. H., Brett, M., Haldane, A., del Río, J. F., Wiebe, M., Peterson, P., … Oliphant, T. E. (2020). Array programming with NumPy. Nature, 585(7825), 357–362. 10.1038/s41586-020-2649-2
  2. Meurer, A., Smith, C. P., Paprocki, M., Čertík, O., Kirpichev, S. B., Rocklin, M., Kumar, Am., Ivanov, S., Moore, J. K., Singh, S., Rathnayake, T., Vig, S., Granger, B. E., Muller, R. P., Bonazzi, F., Gupta, H., Vats, S., Johansson, F., Pedregosa, F., … Scopatz, A. (2017). SymPy: symbolic computing in Python. PeerJ Computer Science, 3, e103. 10.7717/peerj-cs.103
  3. Snell, J. L. (1959). Finite Markov Chains and their Applications. The American Mathematical Monthly, 66(2), 99–104. 10.1080/00029890.1959.11989252
  4. Kemeny, J. G., & Snell, J. L. (1976). Finite Markov chains. Springer-Verlag.
  5. Nowak, M. A., & Sigmund, K. (2004). Evolutionary dynamics of biological games. Science, 303(5659), 793–799.
  6. Bianchini, M., Gori, M., & Scarselli, F. (2005). Inside PageRank. ACM Transactions on Internet Technology, 5(1), 92–128. 10.1145/1052934.1052938
  7. Langville, A., & Meyer, C. (2004). Deeper Inside PageRank. Internet Mathematics, 1(3), 335–380. 10.1080/15427951.2004.10129091
  8. Palmer, G. I., Harper, P. R., & Knight, V. A. (2018). Modelling deadlock in open restricted queueing networks. European Journal of Operational Research, 266(2), 609–621. 10.1016/j.ejor.2017.10.039
  9. Tan, B. (1997). Markov Chains and the RISK Board Game. Mathematics Magazine, 70(5), 349–357. 10.1080/0025570X.1997.11996573
  10. Osborne, J. A. (2003). Markov Chains for the RISK Board Game Revisited. Mathematics Magazine, 76(2), 129–135. 10.1080/0025570X.2003.11953165
  11. Tedeschi, M. N., Hose, T. M., Mehlman, E. K., Franklin, S., & Wong, T. E. (2023). Improving models for student retention and graduation using Markov chains. PLOS ONE, 18(6), e0287775. 10.1371/journal.pone.0287775