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:
- Room 1 connects to Rooms 2 and 3
- Room 2 connects to Rooms 1 and 4
- Room 3 connects to Rooms 1, 4, and 5
- Room 4 connects to Rooms 2, 3, and 6
- Rooms 5 and 6 are absorbing exits
Let be the transition matrix, where rows and columns correspond to the rooms in order:
Rooms 5 and 6 are absorbing: the student remains there once entered. The rest are transient. In the following sections, we will compute:
- The expected number of steps before exiting the maze
- The probability of exiting through Room 5 versus Room 6
- The expected number of visits to each room
This chapter will describe a powerful mathematical tool: Markov Chains and in particular Absorbing Markov Chains.
Theory¶
Definition of a Markov Chain¶
Let be a finite set of states. A Markov chain is defined by:
- A sequence of random variables , where each
- A transition probability matrix , where
with for all .
A state of the Markov chain can be described by a probability distribution vector such that .
This gives:
and so:
Example: Escaping the Maze¶
Let us assume that students are known to start in one of the room with equal probability. This implies that:
Calculate
Calculate
Given that:
What is the likely location of a student after 1000 time steps?
We have:
- We have:
$$
$$
- Finally:
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 is absorbing if:
It has at least one absorbing state, i.e., a state such that .
From every non-absorbing (transient) state , 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 can be written (up to an ordering of states) in the following canonical form:
where:
- is the transient submatrix: it contains the probabilities of transitions from transient state to transient state.
- is the transition to absorption submatrix: it contains the probabilities of transition from transient state to absorption state.
Example: The Maze as an absorbing Markov chain¶
For Motivating Example: Escaping a Maze the Markov chain can be written in the form of (A1.10) with:
Definition: Fundamental Matrix¶
For an absorbing Markov chain in the form (A1.10) the fundamental matrix is given by:
The entry gives the expected number of times the process is in transient state before being absorbed having started in state .
Example: Fundamental matrix of the Maze¶
For Motivating Example: Escaping a Maze the fundamental matrix is given by:
This inverse can be computed, a technique for doing this will be reviewed in Definition: Gauss-Jordan Method for inverting a matrix to give:
We can read from this matrix that for example, starting in state the student will visit state on average 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 is given by:
The probability of being absorbed in to absorbing state having started at state is .
Example: Probability of absorbing state in the Maze¶
For Motivating Example: Escaping a Maze the absorption probability matrix is given by:
Definition: Gauss-Jordan Method for inverting a matrix¶
The Gauss-Jordan Method for inverting a non-singular matrix :
- Set up the augmented matrix , where is the identity matrix.
- Use row operations:
- Swap rows;
- Scaling rows;
- Adding scalar multiples of a row to another row.
- One the left hand side of the augmented matrix become the right hand side is .
Example: Compute the inverse of a 4 by 4 matrix¶
Let us compute the inverse of:
First we create the augmented matrix:
Let us add row 1 to row 2 and row 1 to row 3:
Let us multiple row 2 by (to create a leading 1):
Let us:
- Add of row 2 to row 1;
- Add of row 2 to row 3.
- Add of row 2 to row 4.
Let us multiply row 3 by :
Let us:
- Add of row 3 to row 1;
- Add of row 3 to row 2.
- Add of row 3 to row 4.
Let us multiply row 4 by :
Let us:
- Add of row 4 to row 1;
- Add of row 4 to row 2.
- Add of row 4 to row 3.
This has created the identity matrix on the left and results in the following inverse of (which was used in Example: Fundamental matrix of the Maze):
Exercises¶
Exercise: Transition Classification¶
Consider the following Markov chain with transition matrix:
- Identify which states are transient and which are absorbing.
- Write in canonical form.
- Compute the fundamental matrix .
- Use to compute the expected number of steps until absorption starting from each transient state.
Exercise: Expected Visits¶
Let be the maze transition matrix from Section Motivating Example: Escaping a Maze. Suppose the student starts in Room 1.
- How many times on average will the student visit Room 4 before reaching an exit?
- Which ordinary room is visited most often in expectation when starting from Room 3?
Exercise: Symbolic Fundamental Matrix¶
Let
where .
- Compute the fundamental matrix symbolically.
- Express the expected number of total steps before absorption from each starting state in terms of and .
Exercise: Absorption Probabilities¶
Suppose a Markov chain has:
- Compute the fundamental matrix .
- Compute the absorption probability matrix .
- Interpret the meaning of .
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 of row 1 to row 2, and 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 :
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:
- The original PageRank algorithm developed by Google has been analyzed through the lens of absorbing Markov chains Bianchini et al., 2005Langville & Meyer, 2004.
- In Palmer et al., 2018, absorbing chains are used to model deadlock in queuing systems, including applications in traffic flow and healthcare.
- The dynamics of battles in the board game Risk are captured using absorbing Markov chains in Tan, 1997Osborne, 2003.
- Student retention processes are modelled using absorbing chains in Tedeschi et al., 2023.
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
Concept | Description |
---|---|
Markov Chain | A sequence of random states with memoryless transitions |
Absorbing State | A state that, once entered, cannot be left |
Transient State | A non-absorbing state that leads to absorption with non-zero probability |
Canonical Form | Matrix structure separating transient and absorbing states |
Fundamental Matrix () | gives expected visits to transient states before absorption |
Absorption Probability Matrix | gives the probability of ending in each absorbing state |
Gauss-Jordan Elimination | A method to compute matrix inverses using row operations |
- 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
- 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
- Snell, J. L. (1959). Finite Markov Chains and their Applications. The American Mathematical Monthly, 66(2), 99–104. 10.1080/00029890.1959.11989252
- Kemeny, J. G., & Snell, J. L. (1976). Finite Markov chains. Springer-Verlag.
- Nowak, M. A., & Sigmund, K. (2004). Evolutionary dynamics of biological games. Science, 303(5659), 793–799.
- Bianchini, M., Gori, M., & Scarselli, F. (2005). Inside PageRank. ACM Transactions on Internet Technology, 5(1), 92–128. 10.1145/1052934.1052938
- Langville, A., & Meyer, C. (2004). Deeper Inside PageRank. Internet Mathematics, 1(3), 335–380. 10.1080/15427951.2004.10129091
- 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
- Tan, B. (1997). Markov Chains and the RISK Board Game. Mathematics Magazine, 70(5), 349–357. 10.1080/0025570X.1997.11996573
- Osborne, J. A. (2003). Markov Chains for the RISK Board Game Revisited. Mathematics Magazine, 76(2), 129–135. 10.1080/0025570X.2003.11953165
- 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