Lecture 1, Markov chains and the transition matrix
1517 words,
Markov chains were introduced in 1906 by Andrei Andreyevich Markov (1856–1922) and were named in his honour. This lecture defines them, describes where they come from and how to simulate them, and computes the probabilities of moving between states in n steps.
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.
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
The element p57=21 of P 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) for the probability that the frog, starting in state 1, is in state 1 after n 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)=41,p11(5)=163, and about 51 after 1000 jumps, because limn→∞p11(n)=51. (b) Starting in state 4, what is the probability that the frog ever reaches state 7? The answer is 31. (c) Starting in state 4, how long on average does it take to reach either state 3 or state 7? The answer is 311. (d) Starting in state 2, what is the long-run proportion of time spent in state 3? The answer is 52.
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
A sequence of positions of the frog can be read as the outcome of a random process, or experiment.
Definition (Probability space). A probability space is a triple (Ω,F,P). The sample spaceΩ is the set of all possible outcomes of a random process. The event spaceF is a set of events, where an event is a subset of Ω. The probabilityP is a function that assigns a number between 0 and 1 to every event in F.
Definition (Random variable). Let (E,E) be a measurable space. A random variable with values in E is a measurable function X:Ω→E, that is, a function such that, for every B∈E,
X−1(B)={ω∈Ω:X(ω)∈B}∈F.
Definition (Distribution). The probability distribution of a random variable X describes how probability is assigned to the values of X: it assigns to every B∈E the number P(X∈B).
Example (The outcome of 10 jumps). An experiment of exactly 11 positions of the frog, that is, 10 jumps, is an outcome ω∈Ω={1,…,7}11, and F is a set of subsets of Ω. Take
ω=(1,2,3,2,3,4,3,4,2,1,2).
The random variable Xn returns the position after n jumps, Xn(ω)=ωn, so X0(ω)=1,X1(ω)=2 and X2(ω)=3. A random variable takes as input an element of Ω, an outcome and not an event, and returns a value. Figure 2 draws this ω.
Figure 2. The outcome ω of the example, position against n. The slider chooses n and the figure reads off Xn(ω).
Markov chains
Let I be a countable set, with elements denoted i,j,k,…. Each i∈I is called a state and I is called the state space. We work in a probability space (Ω,F,P). The object of study is a sequence of random variables X0,X1,… with values in I whose joint distribution is determined by simple rules.
A row vector λ=(λi:i∈I) is called a measure if λi≥0 for all i∈I. If moreover ∑iλi=1, it is a distribution, or probability measure. We start with an initial distributionλ over I, which is the initial condition of the chain. The special case in which the chain starts in state i with probability 1 is denoted
λ=δi=(0,…,0,1,0,…),
with the entry 1 in position i. We also have a transition matrixP=(pij:i,j∈I). It is a stochastic matrix, meaning that pij≥0 for all i,j∈I and ∑jpij=1 for all i∈I, that is, each row of P is a distribution over I.
Definition 1.2 (Markov chain). A sequence (Xn)n≥0 of random variables with values in I is a Markov chain with initial distribution λ and transition matrix P if, for all n≥0 and i0,…,in+1∈I, the following two conditions hold. (i)P(X0=i0)=λi0. (ii) Whenever P(X0=i0,…,Xn=in)>0,
For short, we say that (Xn)n≥0 is Markov(λ,P). Checking conditions (i) and (ii) is usually the most helpful way to determine whether or not a given random process (Xn)n≥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 of random variables with values in I is Markov(λ,P) if and only if, for all n≥0 and i0,…,in∈I,
and for n=0 (1.1) is condition (i). On the other hand, if (1.1) holds, summing it over all i1,…,in gives P(X0=i0)=λi0, that is, (i). Then summing (1.1) over in gives P(X0=i0,…,Xn−1=in−1)=λi0pi0i1⋯pin−2in−1. Hence
Details. The first computation divides by P(X0=i0,…,Xn−1=in−1), so it needs this probability to be positive. When it is zero, both sides of (1.1) are zero: the left-hand side is at most this probability, and if m is the smallest index with P(X0=i0,…,Xm=im)=0, then λi0=0 when m=0 and pim−1im=0 when m≥1, by the same computation up to time m. In the converse, the middle term of (ii) equals pin−1in as well, because summing (1.1) over i0,…,in−2 gives P(Xn−1=in−1,Xn=in)=P(Xn−1=in−1)pin−1in.
By (1.1), the probability of a sequence of jumps is a product of entries of P along it. For question (a) of Example 1.1, the only sequence of 3 jumps from state 1 back to state 1 with positive probability visits the states 1, 2, 3, 1, and its probability is 1⋅21⋅21=41=p11(3). Figure 3 computes the product for any sequence of states.
Figure 3. Formula (1.1) on the chain of Example 1.1 with λ=δi0. Clicking a pad appends it to the sequence, and the product of the entries of P along the sequence is updated; it is 0 as soon as one jump has probability 0.
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,… as independent and identically distributed (i.i.d.) random variables with values in a set E, and a function F:I×E→I such that u↦F(j,u) is measurable for every j∈I. Take i∈I. Set X0=i and define recursively
Xn+1=F(Xn,Un+1),n≥0.
Then (Xn)n≥0 is Markov(δi,P), where pjk=P(F(j,U)=k) for all j,k∈I and U has the common distribution of the Un. Indeed, X0,…,Xn are functions of U1,…,Un, so Un+1 is independent of them, and on the event {Xn=j} we have Xn+1=F(j,Un+1). Hence both conditional probabilities in (ii) equal pjk.
How can we simulate them?
Label the states 1,2,…. Use a computer to simulate U1,U2,… as i.i.d. random variables uniformly distributed on [0,1], written U[0,1]. Define F(i,U)=J by the rules
For fixed i these intervals are disjoint, the interval of J=j has length pij, and their union is [0,1) because ∑jpij=1. Hence P(F(i,U)=j)=pij, and the construction of the previous section produces a chain that is Markov(δi,P).
Figure 4. The rules above on the chain of Example 1.1. The row of the current state Xn splits [0,1) into one interval for each state j with pXnj>0, and the interval containing the mark Un+1 gives Xn+1. The slider sets X0 and the button draws new uniform variables.
The n-step transition matrix
Let A be an event. A convenient notation is
Pi(A)=P(A∣X0=i),
for every state i with λi>0; here and below a term λiPi(⋅) with λi=0 is read as 0. For example, Pi(X1=j)=pij. Given the initial distribution λ, we treat it as a row vector. Then
Here δi is a special case of λ. Thus P(n)=(pij(n)), the n-step transition matrix, is simply Pn, the matrix P raised to the power n. Also, for all i,j∈I and n,m≥0, the (obvious) Chapman–Kolmogorov equations hold:
pij(n+m)=k∈I∑pik(n)pkj(m).
They are obvious because the right-hand side is the entry (i,j) of PnPm=Pn+m. They are named for their independent formulation by Chapman (a Trinity College graduate, 1880–1970) and Kolmogorov (1903–1987).
∑kp1k(2)pk3(3) = 0.3750, p13(5) = 0.3750
Figure 5. The Chapman–Kolmogorov equations on the chain of Example 1.1. A line through state k at time n is drawn thicker when pik(n)pkj(m) is larger, and the sliders set i,j,n and m. The sum over k equals pij(n+m).
Figure 6. The matrix Pn of Example 1.1, each entry shaded by its value. The slider sets n from 0 to 60, and p11(n) is written above the grid: n=3 and n=5 give the values 41 and 163 of question (a).
The matrix P(n) of a two-state chain
Example 1.4 (A two-state Markov chain). Let α,β∈[0,1] with α+β>0, and consider the chain on I={1,2} with transition matrix
P=(1−αβα1−β).
The eigenvalues of P are 1 and 1−α−β, which are distinct because α+β>0. So we can write
P=U(1001−α−β)U−1⟹Pn=U(100(1−α−β)n)U−1.
Hence p11(n)=A+B(1−α−β)n for some constants A and B. Since p11(0)=1=A+B and p11(1)=1−α=A+B(1−α−β), we get (A,B)=(β,α)/(α+β), that is,
P1(Xn=1)=p11(n)=α+ββ+α+βα(1−α−β)n.
When α+β<2, this tends exponentially fast to a limit of β/(α+β). The other components of Pn can be computed similarly, and