Alessandro Palliccia

Stochastic Dynamical Models

Markov chains and the transition matrix

1,181 words,

Markov chains were introduced in 1906 by Andrei Andreyevich Markov (1856–1922) and were named in his honour.

An example and some interesting questions

Example 1.1. A frog hops about on 7 lily pads. The number next to each arrow of Figure 1 is the probability with which, at the next jump, the frog moves along that arrow to a neighbouring pad. When the probabilities of the arrows leaving a pad sum to less than 1, the frog stays where it is with the remaining probability, drawn as a loop.

½½½11½½¼¼½½11234567

Figure 1. The 7 lily pads of Example 1.1 and the probabilities of the jumps between them.

There are 7 states, the lily pads. The probabilities of the jumps form the matrix

P=(0100000012120000120120000001412140000000121200010000000001).P = \begin{pmatrix} 0 & 1 & 0 & 0 & 0 & 0 & 0 \\[4pt] 0 & \frac12 & \frac12 & 0 & 0 & 0 & 0 \\[4pt] \frac12 & 0 & \frac12 & 0 & 0 & 0 & 0 \\[4pt] 0 & 0 & \frac14 & \frac12 & \frac14 & 0 & 0 \\[4pt] 0 & 0 & 0 & 0 & 0 & \frac12 & \frac12 \\[4pt] 0 & 0 & 0 & 1 & 0 & 0 & 0 \\[4pt] 0 & 0 & 0 & 0 & 0 & 0 & 1 \end{pmatrix}.

The element p57=12{p_{57} = \frac12} of PP is the probability that, when starting in state 5, the next jump takes the frog to state 7. We would like to know where the frog goes, how long it takes to get there, and what happens in the long run. Write p11(n)p^{(n)}_{11} for the probability that the frog, starting in state 1, is in state 1 after nn jumps. Specifically:
(a) Starting in state 1, what is the probability that the frog is still in state 1 after 3 jumps, after 5 jumps, after 1000 jumps? The answers are p11(3)=14,{p^{(3)}_{11} = \frac14,} p11(5)=316,{p^{(5)}_{11} = \frac{3}{16},} and about 15\frac15 after 1000 jumps, because lim⁡n→∞p11(n)=15.{\lim_{n \to \infty} p^{(n)}_{11} = \frac15.}
(b) Starting in state 4, what is the probability that the frog ever reaches state 7? The answer is 13.\frac13.
(c) Starting in state 4, how long on average does it take to reach either state 3 or state 7? The answer is 113.\frac{11}{3}.
(d) Starting in state 2, what is the long-run proportion of time spent in state 3? The answer is 25.\frac25.

Markov chain models and methods are useful in answering questions such as the following. How long does it take to shuffle a deck of cards? How likely is a queue to overflow its buffer? How long does it take for a knight making random moves on a chessboard to return to its initial square? The answer is 168 if it starts in a corner and 42 if it starts near the centre. What do the hyperlinks between web pages say about their relative popularity?

Definitions

Probability spaces and random variables

Definition (Probability space). A probability space is a triple (Ω,F,P).(\Omega, \mathscr{F}, P). The sample space Ω\Omega is the set of all possible outcomes of a random process. The event space F\mathscr{F} is a set of events, where an event is a subset of Ω.\Omega. The probability PP is a function that assigns a number between 0 and 1 to every event in F.\mathscr{F}.

Definition (Random variable). Let EE be a measurable space. A random variable with values in EE is a measurable function X ⁣:Ω→E.{X \colon \Omega \to E.}

Definition (Distribution). The probability distribution of a random variable XX describes how probability is assigned to the values of X.X.

Example (The outcome of 10 jumps). A sequence of positions of the frog is an experiment. The set of all experiments is the sample space Ω,\Omega, F\mathscr{F} is a set of subsets of Ω,\Omega, and PP is a probability. Take the experiment of exactly 11 positions, that is, 10 jumps,

ω=(1,2,3,2,3,4,3,4,2,1,2).\omega = (1, 2, 3, 2, 3, 4, 3, 4, 2, 1, 2).

The random variable XnX_n returns the position after nn jumps, Xn(ω)=ωn,{X_n(\omega) = \omega_n,} so X0(ω)=1,{X_0(\omega) = 1,} X1(ω)=2{X_1(\omega) = 2} and X2(ω)=3.{X_2(\omega) = 3.} A random variable takes as input an element of Ω,\Omega, an outcome and not an event, and returns a value.

Markov chains

Let II be a countable set, with elements denoted i,j,k,… .i, j, k, \dots. Each i∈I{i \in I} is called a state and II is called the state space. We work in a probability space (Ω,F,P).{(\Omega, \mathscr{F}, P).} The object of study is a sequence of random variables X0,X1,…{X_0, X_1, \dots} with values in II whose joint distribution is determined by simple rules.

A row vector λ=(λi:i∈I){\lambda = (\lambda_i : i \in I)} is called a measure if λi≥0{\lambda_i \ge 0} for all i∈I.{i \in I.} If moreover ∑iλi=1,{\sum_i \lambda_i = 1,} it is a distribution, or probability measure. We start with an initial distribution λ\lambda over I,I, which is the initial condition of the chain. The special case in which the chain starts in state ii with probability 1 is denoted

λ=δi=(0,…,0,1,0,… ),\lambda = \delta_i = (0, \dots, 0, 1, 0, \dots),

with the entry 1 in position i.i. We also have a transition matrix P=(pij:i,j∈I).{P = (p_{ij} : i, j \in I).} It is a stochastic matrix, meaning that pij≥0{p_{ij} \ge 0} for all i,j∈I{i, j \in I} and ∑jpij=1{\sum_{j} p_{ij} = 1} for all i∈I,{i \in I,} that is, each row of PP is a distribution over I.I.

Definition 1.2 (Markov chain). A sequence (Xn)n≥0(X_n)_{n \ge 0} of random variables with values in II is a Markov chain with initial distribution λ\lambda and transition matrix PP if, for all n≥0{n \ge 0} and i0,…,in+1∈I,{i_0, \dots, i_{n+1} \in I,} the following two conditions hold.
(i) P(X0=i0)=λi0.{P(X_0 = i_0) = \lambda_{i_0}.}
(ii) Whenever P(X0=i0,…,Xn=in)>0,{P(X_0 = i_0, \dots, X_n = i_n) > 0,}

P(Xn+1=in+1∣X0=i0,…,Xn=in)=P(Xn+1=in+1∣Xn=in)=pinin+1.P(X_{n+1} = i_{n+1} \mid X_0 = i_0, \dots, X_n = i_n) = P(X_{n+1} = i_{n+1} \mid X_n = i_n) = p_{i_n i_{n+1}}.

For short, we say that (Xn)n≥0(X_n)_{n \ge 0} is Markov(λ,P).\mathrm{Markov}(\lambda, P). Checking conditions (i) and (ii) is usually the most helpful way to determine whether or not a given random process (Xn)n≥0(X_n)_{n \ge 0} is a Markov chain. It can also be helpful to have the alternative description provided by Theorem 1.3.

Theorem 1.3. A sequence (Xn)n≥0(X_n)_{n \ge 0} of random variables with values in II is Markov(λ,P)\mathrm{Markov}(\lambda, P) if and only if, for all n≥0{n \ge 0} and i0,…,in∈I,{i_0, \dots, i_n \in I,}

P(X0=i0,…,Xn=in)=λi0pi0i1⋯pin−1in.(1.1)P(X_0 = i_0, \dots, X_n = i_n) = \lambda_{i_0} p_{i_0 i_1} \cdots p_{i_{n-1} i_n}. \tag{1.1}

Proof (sketch). Suppose that (Xn)n≥0(X_n)_{n \ge 0} is Markov(λ,P).\mathrm{Markov}(\lambda, P). Then, for n≥1,{n \ge 1,}

P(X0=i0,…,Xn=in)=P(Xn=in∣X0=i0,…,Xn−1=in−1) P(X0=i0,…,Xn−1=in−1)=P(X0=i0) P(X1=i1∣X0=i0)⋯P(Xn=in∣X0=i0,…,Xn−1=in−1)=λi0pi0i1⋯pin−1in,\begin{aligned} &P(X_0 = i_0, \dots, X_n = i_n) \\ &\quad = P(X_n = i_n \mid X_0 = i_0, \dots, X_{n-1} = i_{n-1}) \, P(X_0 = i_0, \dots, X_{n-1} = i_{n-1}) \\ &\quad = P(X_0 = i_0) \, P(X_1 = i_1 \mid X_0 = i_0) \cdots P(X_n = i_n \mid X_0 = i_0, \dots, X_{n-1} = i_{n-1}) \\ &\quad = \lambda_{i_0} p_{i_0 i_1} \cdots p_{i_{n-1} i_n}, \end{aligned}

and for n=0,{n = 0,} (1.1) is condition (i). On the other hand, if (1.1) holds, summing it over all i1,…,in{i_1, \dots, i_n} gives P(X0=i0)=λi0,{P(X_0 = i_0) = \lambda_{i_0},} that is, (i). Then summing (1.1) over ini_n gives P(X0=i0,…,Xn−1=in−1)=λi0pi0i1⋯pin−2in−1.{P(X_0 = i_0, \dots, X_{n-1} = i_{n-1}) = \lambda_{i_0} p_{i_0 i_1} \cdots p_{i_{n-2} i_{n-1}}.} Hence

P(Xn=in∣X0=i0,…,Xn−1=in−1)=P(X0=i0,…,Xn=in)P(X0=i0,…,Xn−1=in−1)=pin−1in,P(X_n = i_n \mid X_0 = i_0, \dots, X_{n-1} = i_{n-1}) = \frac{P(X_0 = i_0, \dots, X_n = i_n)}{P(X_0 = i_0, \dots, X_{n-1} = i_{n-1})} = p_{i_{n-1} i_n},

which establishes (ii). ■\blacksquare

Where do Markov chains come from?

At each time we apply some new randomness to determine the next step, in a way that is a function only of the current state. We might take U1,U2,…{U_1, U_2, \dots} as independent and identically distributed (i.i.d.) random variables with values in a set E,E, and a function F ⁣:I×E→I{F \colon I \times E \to I} such that u↦F(j,u){u \mapsto F(j, u)} is measurable for every j∈I.{j \in I.} Take i∈I.{i \in I.} Set X0=i{X_0 = i} and define recursively

Xn+1=F(Xn,Un+1),n≥0.X_{n+1} = F(X_n, U_{n+1}), \qquad n \ge 0.

Then (Xn)n≥0(X_n)_{n \ge 0} is Markov(δi,P),\mathrm{Markov}(\delta_i, P), where pjk=P(F(j,U)=k){p_{jk} = P(F(j, U) = k)} for all j,k∈I{j, k \in I} and UU has the common distribution of the Un.U_n. Indeed, X0,…,Xn{X_0, \dots, X_n} are functions of U1,…,Un,{U_1, \dots, U_n,} so Un+1U_{n+1} is independent of them, and on the event {Xn=j}{\{ X_n = j \}} we have Xn+1=F(j,Un+1).{X_{n+1} = F(j, U_{n+1}).} Hence both conditional probabilities in (ii) equal pjk.p_{jk}.

How can we simulate them?

Label the states 1,2,… .{1, 2, \dots.} Use a computer to simulate U1,U2,…{U_1, U_2, \dots} as i.i.d. random variables uniformly distributed on [0,1],[0, 1], written U[0,1].U[0, 1]. Define F(i,U)=J{F(i, U) = J} by the rules

U∈[0,pi1)⟹J=1,U∈[∑k=1j−1pik, ∑k=1jpik),j≥2⟹J=j.\begin{aligned} U &\in [0, p_{i1}) & &\Longrightarrow \quad J = 1, \\ U &\in \left[ \sum_{k=1}^{j-1} p_{ik}, \ \sum_{k=1}^{j} p_{ik} \right), \quad j \ge 2 & &\Longrightarrow \quad J = j. \end{aligned}

Figure 2. The rules above on the chain of Example 1.1. The row of the current state XnX_n splits [0,1)[0, 1) into one interval for each state jj with pXnj>0,{p_{X_n j} > 0,} and the interval containing the mark Un+1U_{n+1} gives Xn+1.X_{n+1}. The slider sets X0X_0 and the button draws new uniform variables.

The nn-step transition matrix

Let AA be an event. A convenient notation is

Pi(A)=P(A∣X0=i),P_i(A) = P(A \mid X_0 = i),

for every state ii with λi>0;{\lambda_i > 0;} here and below a term λiPi(⋅)\lambda_i P_i(\cdot) with λi=0{\lambda_i = 0} is read as 0. For example, Pi(X1=j)=pij.{P_i(X_1 = j) = p_{ij}.} Given the initial distribution λ,\lambda, we treat it as a row vector. Then

P(X1=j)=∑i∈IλiPi(X1=j)=∑i∈Iλipij.P(X_1 = j) = \sum_{i \in I} \lambda_i P_i(X_1 = j) = \sum_{i \in I} \lambda_i p_{ij}.

Similarly,

Pi(X2=j)=∑kPi(X1=k,X2=j)=∑kpikpkj=(P2)ij,P(X2=j)=∑i,kλiPi(X1=k,X2=j)=∑i,kλipikpkj=(λP2)j.\begin{aligned} P_i(X_2 = j) &= \sum_{k} P_i(X_1 = k, X_2 = j) = \sum_{k} p_{ik} p_{kj} = (P^2)_{ij}, \\ P(X_2 = j) &= \sum_{i, k} \lambda_i P_i(X_1 = k, X_2 = j) = \sum_{i, k} \lambda_i p_{ik} p_{kj} = (\lambda P^2)_j. \end{aligned}

Continuing in this way,

Pi(Xn=j)=(δiPn)j=(Pn)ij=pij(n),P(Xn=j)=∑i0,…,in−1λi0pi0i1⋯pin−1j=(λPn)j.\begin{aligned} P_i(X_n = j) &= (\delta_i P^n)_j = (P^n)_{ij} = p^{(n)}_{ij}, \\ P(X_n = j) &= \sum_{i_0, \dots, i_{n-1}} \lambda_{i_0} p_{i_0 i_1} \cdots p_{i_{n-1} j} = (\lambda P^n)_j. \end{aligned}

Here δi\delta_i is a special case of λ.\lambda. Thus P(n)=(pij(n)),{P^{(n)} = (p^{(n)}_{ij}),} the nn-step transition matrix, is simply Pn,P^n, the matrix PP raised to the power n.n. Also, for all i,j∈I{i, j \in I} and n,m≥0,{n, m \ge 0,} the (obvious) Chapman–Kolmogorov equations hold:

pij(n+m)=∑k∈Ipik(n)pkj(m).p^{(n+m)}_{ij} = \sum_{k \in I} p^{(n)}_{ik} p^{(m)}_{kj}.

They are named for their independent formulation by Chapman (a Trinity College graduate, 1880–1970) and Kolmogorov (1903–1987).

In Example 1.1, as n→∞,{n \to \infty,}

P(n)→(1525250000152525000015252500002154154150001311521521500023215415415000130000001).P^{(n)} \to \begin{pmatrix} \frac15 & \frac25 & \frac25 & 0 & 0 & 0 & 0 \\[6pt] \frac15 & \frac25 & \frac25 & 0 & 0 & 0 & 0 \\[6pt] \frac15 & \frac25 & \frac25 & 0 & 0 & 0 & 0 \\[6pt] \frac{2}{15} & \frac{4}{15} & \frac{4}{15} & 0 & 0 & 0 & \frac13 \\[6pt] \frac{1}{15} & \frac{2}{15} & \frac{2}{15} & 0 & 0 & 0 & \frac23 \\[6pt] \frac{2}{15} & \frac{4}{15} & \frac{4}{15} & 0 & 0 & 0 & \frac13 \\[6pt] 0 & 0 & 0 & 0 & 0 & 0 & 1 \end{pmatrix}.

The matrix P(n)P^{(n)} of a two-state chain

Example 1.4 (A two-state Markov chain). Let α,β∈[0,1]{\alpha, \beta \in [0, 1]} with α+β>0,{\alpha + \beta > 0,} and consider the chain on I={1,2}{I = \{1, 2\}} with transition matrix

P=(1−ααβ1−β).P = \begin{pmatrix} 1 - \alpha & \alpha \\ \beta & 1 - \beta \end{pmatrix}.

The eigenvalues of PP are 1 and 1−α−β,{1 - \alpha - \beta,} which are distinct because α+β>0.{\alpha + \beta > 0.} So we can write

P=U(1001−α−β)U−1⟹Pn=U(100(1−α−β)n)U−1.P = U \begin{pmatrix} 1 & 0 \\ 0 & 1 - \alpha - \beta \end{pmatrix} U^{-1} \quad \Longrightarrow \quad P^n = U \begin{pmatrix} 1 & 0 \\ 0 & (1 - \alpha - \beta)^n \end{pmatrix} U^{-1}.

Hence p11(n)=A+B(1−α−β)n{p^{(n)}_{11} = A + B (1 - \alpha - \beta)^n} for some constants AA and B.B. Since p11(0)=1=A+B{p^{(0)}_{11} = 1 = A + B} and p11(1)=1−α=A+B(1−α−β),{p^{(1)}_{11} = 1 - \alpha = A + B (1 - \alpha - \beta),} we get (A,B)=(β,α)/(α+β),{(A, B) = (\beta, \alpha)/(\alpha + \beta),} that is,

P1(Xn=1)=p11(n)=βα+β+αα+β(1−α−β)n.P_1(X_n = 1) = p^{(n)}_{11} = \frac{\beta}{\alpha + \beta} + \frac{\alpha}{\alpha + \beta} (1 - \alpha - \beta)^n.

When α+β<2,{\alpha + \beta < 2,} this tends exponentially fast to a limit of β/(α+β).{\beta/(\alpha + \beta).} The other components of PnP^n can be computed similarly, and

Pn=(βα+β+αα+β(1−α−β)nαα+β−αα+β(1−α−β)nβα+β−βα+β(1−α−β)nαα+β+βα+β(1−α−β)n).P^n = \begin{pmatrix} \frac{\beta}{\alpha + \beta} + \frac{\alpha}{\alpha + \beta} (1 - \alpha - \beta)^n & \frac{\alpha}{\alpha + \beta} - \frac{\alpha}{\alpha + \beta} (1 - \alpha - \beta)^n \\[6pt] \frac{\beta}{\alpha + \beta} - \frac{\beta}{\alpha + \beta} (1 - \alpha - \beta)^n & \frac{\alpha}{\alpha + \beta} + \frac{\beta}{\alpha + \beta} (1 - \alpha - \beta)^n \end{pmatrix}.

Figure 3. The chain of Example 1.4 for the values of α\alpha and β\beta set by the sliders, and p11(n)p^{(n)}_{11} for n=0,1,…,30{n = 0, 1, \dots, 30} with the level β/(α+β).{\beta/(\alpha + \beta).}

Note. We might have reached the same answer by arguing that

p11(n)=p11(n−1)p11+p12(n−1)p21=p11(n−1)(1−α)+(1−p11(n−1))β.p^{(n)}_{11} = p^{(n-1)}_{11} p_{11} + p^{(n-1)}_{12} p_{21} = p^{(n-1)}_{11} (1 - \alpha) + \Bigl( 1 - p^{(n-1)}_{11} \Bigr) \beta.

This gives the linear recurrence relation, an equation that expresses each element of a sequence as a function of the preceding ones,

p11(n)=β+(1−α−β) p11(n−1),p^{(n)}_{11} = \beta + (1 - \alpha - \beta) \, p^{(n-1)}_{11},

to which the solution is of the form p11(n)=A+B(1−α−β)n.{p^{(n)}_{11} = A + B (1 - \alpha - \beta)^n.}