Markov Chain

A stochastic processes $\displaystyle{ \{X_t\mid t\in T\} }$ is a collection of random variables. The index $\displaystyle{ t }$ is often called time, as the process represents the value of a random variable changing over time. Let $\displaystyle{ \Omega }$ be the set of values assumed by the random variables $\displaystyle{ X_t }$. We call each element of $\displaystyle{ \Omega }$ a state, as $\displaystyle{ X_t }$ represents the state of the process at time $\displaystyle{ t }$.

The model of stochastic processes can be very general. In this class, we only consider the stochastic processes with the following properties:

discrete time
The index set $\displaystyle{ T }$ is countable. Specifically, we assume that $\displaystyle{ T=\{0,1,2,\ldots\} }$ and the process is $\displaystyle{ X_0,X_1,X_2,\ldots }$
discrete space
The state space $\displaystyle{ \Omega }$ is countable. We are especially interested in the case that $\displaystyle{ \Omega }$ is finite, in which case the process is called a finite process.

The next property is about the dependency structure among random variables. The simplest dependency structure for $\displaystyle{ X_0,X_1,\ldots }$ is no dependency at all, that is, independence. We consider the next simplest dependency structure called the Markov property.

 Definition (the Markov property) A process $\displaystyle{ X_0,X_1,\ldots }$ satisfies the Markov property if $\displaystyle{ \Pr[X_{n+1}=x_{n+1}\mid X_{0}=x_{0}, X_{1}=x_{1},\ldots,X_{n}=x_{n}]=\Pr[X_{n+1}=x_{n+1}\mid X_{n}=x_{n}] }$ for all $\displaystyle{ n }$ and all $\displaystyle{ x_0,\ldots,x_{n+1}\in \Omega }$.

Informally, the Markov property means: "conditioning on the present, the future does not depend on the past." Hence, the Markov property is also called the memoryless property.

A stochastic process $\displaystyle{ X_0,X_1,\ldots }$ of discrete time and discrete space is a Markov chain if it has the Markov property.

Transition matrix

Let $\displaystyle{ P^{(t+1)}_{x,y}=\Pr[X_{t+1}=y\mid X_t=x] }$. For a Markov chain with a finite state space $\displaystyle{ \Omega=[N] }$. This gives us a transition matrix $\displaystyle{ P^{(t+1)} }$ at time $\displaystyle{ t }$. The transition matrix is an $\displaystyle{ N\times N }$ matrix of nonnegative entries such that the sum over each row of $\displaystyle{ P^{(t)} }$ is 1, since

\displaystyle{ \begin{align}\sum_{y}P^{(t+1)}_{x,y}=\sum_{y}\Pr[X_{t+1}=y\mid X_t=x]=1\end{align} }.

In linear algebra, matrices of this type are called stochastic matrices.

Let $\displaystyle{ \pi^{(t)} }$ be the distribution of the chain at time $\displaystyle{ t }$, that is, \displaystyle{ \begin{align}\pi^{(t)}_x=\Pr[X_t=x]\end{align} }. For a finite chain, $\displaystyle{ \pi^{(t)} }$ is a vector of $\displaystyle{ N }$ nonnegative entries such that \displaystyle{ \begin{align}\sum_{x}\pi^{(t)}_x=1\end{align} }. In linear algebra, vectors of this type are called stochastic vectors. Then, it holds that

\displaystyle{ \begin{align}\pi^{(t+1)}=\pi^{(t)}P^{(t+1)}\end{align} }.

To see this, we apply the law of total probability,

\displaystyle{ \begin{align} \pi^{(t+1)}_y &= \Pr[X_{t+1}=y]\\ &= \sum_{x}\Pr[X_{t+1}=y\mid X_t=x]\Pr[X_t=x]\\ &=\sum_{x}\pi^{(t)}_xP^{(t+1)}_{x,y}\\ &=(\pi^{(t)}P^{(t+1)})_y. \end{align} }

Therefore, a finite Markov chain $\displaystyle{ X_0,X_1,\ldots }$ is specified by an initial distribution $\displaystyle{ \pi^{(0)} }$ and a sequence of transition matrices $\displaystyle{ P^{(1)},P^{(2)},\ldots }$. And the transitions of chain can be described by a series of matrix products:

$\displaystyle{ \pi^{(0)}\stackrel{P^{(1)}}{\longrightarrow}\pi^{(1)}\stackrel{P^{(2)}}{\longrightarrow}\pi^{(2)}\stackrel{P^{(3)}}{\longrightarrow}\cdots\cdots\pi^{(t)}\stackrel{P^{(t+1)}}{\longrightarrow}\pi^{(t+1)}\cdots }$

A Markov chain is said to be homogenous if the transitions depend only on the current states but not on the time, that is

$\displaystyle{ P^{(t)}_{x,y}=P_{x,y} }$ for all $\displaystyle{ t }$.

The transitions of a homogenous Markov chain is given by a single matrix $\displaystyle{ P }$. Suppose that $\displaystyle{ \pi^{(0)} }$ is the initial distribution. At each time $\displaystyle{ t }$,

\displaystyle{ \begin{align}\pi^{(t+1)}=\pi^{(t)}P\end{align} }.

Expanding this recursion, we have

\displaystyle{ \begin{align}\pi^{(n)}=\pi^{(0)}P^n\end{align} }.

From now on, we restrict ourselves to the homogenous Markov chains, and the term "Markov chain" means "homogenous Markov chian" unless stated otherwise.

 Definition (finite Markov chain) Let $\displaystyle{ P }$ be an $\displaystyle{ N\times N }$ stochastic matrix. A process $\displaystyle{ X_0,X_1,\ldots }$ with finite space $\displaystyle{ \Omega=[N] }$ is said to be a (homogenous) Markov chain with transition matrix $\displaystyle{ P }$, if for all $\displaystyle{ n\ge0, }$ all $\displaystyle{ x,y\in[N] }$ and all $\displaystyle{ x_0,\ldots,x_{n-1}\in[N] }$ we have \displaystyle{ \begin{align} \Pr[X_{n+1}=y\mid X_0=x_0,\ldots,X_{n-1}=x_{n-1},X_n=x] &=Pr[X_{n+1}=y\mid X_n=x]\\ &=P_{x,y}. \end{align} }

To describe a Markov chain, we only need to specify:

• initial distribution $\displaystyle{ \pi^{(0)} }$;
• transition matrix $\displaystyle{ P }$.

Then the transitions can be simulated by matrix products:

$\displaystyle{ \pi^{(0)}\stackrel{P}{\longrightarrow}\pi^{(1)}\stackrel{P}{\longrightarrow}\pi^{(2)}\stackrel{P}{\longrightarrow}\cdots\cdots\pi^{(t)}\stackrel{P}{\longrightarrow}\pi^{(t+1)}\stackrel{P}{\longrightarrow}\cdots }$

The distribution of the chain at time $\displaystyle{ n }$ can be computed by $\displaystyle{ \pi^{(n)}=\pi^{(0)}P^n }$.

Transition graph

Another way to picture a Markov chain is by its transition graph. A weighted directed graph $\displaystyle{ G(V,E,w) }$ is said to be a transition graph of a finite Markov chain with transition matrix $\displaystyle{ P }$ if:

• $\displaystyle{ V=\Omega }$, i.e. each node of the transition graph corresponds to a state of the Markov chain;
• for any $\displaystyle{ x,y\in V }$, $\displaystyle{ (x,y)\in E }$ if and only if $\displaystyle{ P_{x,y}\gt 0 }$, and the weight $\displaystyle{ w(x,y)=P_{x,y} }$.

A transition graph defines a natural random walk: at each time step, at the current node, the walk moves through an adjacent edge with the probability of the weight of the edge. It is easy to see that this is a well-defined random walk, since \displaystyle{ \begin{align}\sum_y P_{x,y}=1\end{align} } for every $\displaystyle{ x }$. Therefore, a Markov chain is equivalent to a random walk, so these two terms are often used interchangeably.

Stationary distributions

Suppose $\displaystyle{ \pi }$ is a distribution over the state space $\displaystyle{ \Omega }$ such that, if the Markov chain starts with initial distribution $\displaystyle{ \pi^{(0)}=\pi }$, then after a transition, the distribution of the chain is still $\displaystyle{ \pi^{(1)}=\pi }$. Then the chain will stay in the distribution $\displaystyle{ \pi }$ forever:

$\displaystyle{ \pi\stackrel{P}{\longrightarrow}\pi\stackrel{P}{\longrightarrow}\pi\stackrel{P}{\longrightarrow}\cdots\cdots }$

Such $\displaystyle{ \pi }$ is called a stationary distribution.

 Definition (stationary distribution) A stationary distribution of a finite Markov chain with transition matrix $\displaystyle{ P }$ is a probability distribution $\displaystyle{ \pi }$ such that \displaystyle{ \begin{align}\pi P=\pi\end{align} }.
Example
An $\displaystyle{ N\times N }$ matrix is called double stochastic if every row sums to 1 and every column sums to 1. If the transition matrix $\displaystyle{ P }$ of the chain is double stochastic, the uniform distribution $\displaystyle{ \pi_x=1/N }$ for all $\displaystyle{ x }$, is a stationary distribution. (Check by yourself.)
If the transition matrix $\displaystyle{ P }$ is symmetric, the uniform distribution is a stationary distribution. This is because a symmetric stochastic matrix is double stochastic. (Check by yourself.)

Every finite Markov chain has a stationary distribution. This is a consequence of Perron's theorem in linear algebra.

For some Markov chains, no matter what the initial distribution is, after running the chain for a while, the distribution of the chain approaches the stationary distribution. For example, consider the transition matrix:

$\displaystyle{ P=\begin{bmatrix} 0 & 1 & 0\\ \frac{1}{3} & 0 & \frac{2}{3}\\ \frac{1}{3} & \frac{1}{3} & \frac{1}{3} \end{bmatrix}. }$

Run the chain for a while, we have:

$\displaystyle{ P^5\approx\begin{bmatrix} 0.2469 & 0.4074 & 0.3457\\ 0.2510 & 0.3621 & 0.3868\\ 0.2510 & 0.3663 & 0.3827 \end{bmatrix}, P^{10}\approx\begin{bmatrix} 0.2500 & 0.3747 & 0.3752\\ 0.2500 & 0.3751 & 0.3749\\ 0.2500 & 0.3751 & 0.3749 \end{bmatrix}, P^{20}\approx\begin{bmatrix} 0.2500 & 0.3750 & 0.3750\\ 0.2500 & 0.3750 & 0.3750\\ 0.2500 & 0.3750 & 0.3750 \end{bmatrix}. }$

Therefore, no matter what the initial distribution $\displaystyle{ \pi^{(0)} }$ is, after 20 steps, $\displaystyle{ \pi^{(0)}P^{20} }$ is very close to the distribution $\displaystyle{ (0.25,0.375,0.375) }$, which is a stationary distribution for $\displaystyle{ P }$. So the Markov chain converges to the same stationary distribution no matter what the initial distribution is.

However, this is not always true. For example, for the Markov chain with the following transition matrix:

$\displaystyle{ P=\begin{bmatrix} \frac{1}{2} & \frac{1}{2} & 0 & 0\\ \frac{1}{3} & \frac{2}{3} & 0 & 0 \\ 0 & 0 & \frac{3}{4} & \frac{1}{4}\\ 0 & 0 & \frac{1}{4} & \frac{3}{4} \end{bmatrix}. }$

And

$\displaystyle{ P^{20}\approx \begin{bmatrix} 0.4 & 0.6 & 0 & 0\\ 0.4 & 0.6 & 0 & 0\\ 0 & 0 & 0.5 & 0.5\\ 0 & 0 & 0.5 & 0.5 \end{bmatrix}. }$

So the chain will converge, but not to the same stationary distribution. Depending on the initial distribution, the chain could converge to any distribution which is a linear combination of $\displaystyle{ (0.4, 0.6, 0, 0) }$ and $\displaystyle{ (0, 0, 0.5, 0.5) }$. We observe that this is because the original chain $\displaystyle{ P }$ can be broken into two disjoint Markov chains, which have their own stationary distributions. We say that the chain is reducible.

Another example is as follows:

$\displaystyle{ P=\begin{bmatrix} 0 & 1\\ 1& 0 \end{bmatrix}. }$

The chain oscillates between the two states. Then

$\displaystyle{ P^t=\begin{bmatrix} 0 & 1\\ 1& 0 \end{bmatrix} }$ for any odd $\displaystyle{ t }$, and
$\displaystyle{ P^t=\begin{bmatrix} 1 & 0\\ 0 & 1 \end{bmatrix} }$ for any even $\displaystyle{ t }$.

So the chain does not converge. We say that the chain is periodic.

We will see that for finite Markov chains, being reducible and being periodic are the only two possible cases that a Markov chain does not converge to a unique stationary distribution.

Irreducibility and aperiodicity

 Definition (irreducibility) State $\displaystyle{ y }$ is accessible from state $\displaystyle{ x }$ if it is possible for the chain to visit state $\displaystyle{ y }$ if the chain starts in state $\displaystyle{ x }$, or, in other words, \displaystyle{ \begin{align}P^n(x,y)\gt 0\end{align} } for some integer $\displaystyle{ n\ge 0 }$. State $\displaystyle{ x }$ communicates with state $\displaystyle{ y }$ if $\displaystyle{ y }$ is accessible from $\displaystyle{ x }$ and $\displaystyle{ x }$ is accessible from $\displaystyle{ y }$. We say that the Markov chain is irreducible if all pairs of states communicate.

It is more clear to interprete these concepts in terms of transition graphs:

• $\displaystyle{ y }$ is accessible from $\displaystyle{ x }$ means that $\displaystyle{ y }$ is connected from $\displaystyle{ x }$ in the transition graph, i.e. there is a directed path from $\displaystyle{ x }$ to $\displaystyle{ y }$.
• $\displaystyle{ x }$ communicates with $\displaystyle{ y }$ means that $\displaystyle{ x }$ and $\displaystyle{ y }$ are strongly connected in the transition graph.
• A finite Markov chain is irreducible if and only if its transition graph is strongly connected.

It is easy to see that communicating is an equivalence relation. That is, it is reflexive, symmetric, and transitive. Thus, the communicating relation partition the state space into disjoint equivalence classes, called communicating classes. For a finite Markov chain, communicating classes correspond to the strongly connected components in the transition graph. It is possible for the chain to move from one communicating class to another, but in that case it is impossible to return to the original class.

 Definition (aperiodicity) The period of a state $\displaystyle{ x }$ is the greatest common divisor (gcd) \displaystyle{ \begin{align}d_x=\gcd\{n\mid (P^n)_{x,x}\gt 0\}\end{align} }. A state is aperiodic if its period is 1. A Markov chain is aperiodic if all its states are aperiodic.

For example, suppose that the period of state $\displaystyle{ x }$ is $\displaystyle{ d_x=3 }$. Then, starting from state $\displaystyle{ x }$,

$\displaystyle{ x,\bigcirc,\bigcirc,\square,\bigcirc,\bigcirc,\square,\bigcirc,\bigcirc,\square,\bigcirc,\bigcirc,\square,\cdots\cdots }$

only the squares are possible to be $\displaystyle{ x }$.

In the transition graph of a finite Markov chain, $\displaystyle{ (P^n)_{x,x}\gt 0 }$ is equivalent to that $\displaystyle{ x }$ is on a cycle of length $\displaystyle{ n }$. Period of a state $\displaystyle{ x }$ is the greatest common devisor of the lengths of cycles passing $\displaystyle{ x }$.

The next theorem shows that period is in fact a class property.

 Theorem If the states $\displaystyle{ x }$ and $\displaystyle{ y }$ communicate, then $\displaystyle{ d_x=d_y }$.
Proof.
 For communicating $\displaystyle{ x }$ and $\displaystyle{ j\gt x\lt }$, there is a path $\displaystyle{ P_1 }$ from $\displaystyle{ x }$ to $\displaystyle{ y }$ of length $\displaystyle{ n_1 }$, and there is a path $\displaystyle{ P_2 }$ from $\displaystyle{ y }$ to $\displaystyle{ x }$ of length $\displaystyle{ n_2 }$. Then $\displaystyle{ P_1P_2 }$ gives a cycle starting at $\displaystyle{ x }$ of length $\displaystyle{ n_1+n+2 }$, and for any cycle $\displaystyle{ C }$ starting at $\displaystyle{ y }$ of length $\displaystyle{ n }$, $\displaystyle{ P_1CP_2 }$ gives a cycle starting at $\displaystyle{ x }$ of length $\displaystyle{ n_1+n_2+n }$. Since the period of $\displaystyle{ x }$ is $\displaystyle{ d_x }$, then both $\displaystyle{ (n_1+n_2) }$ and $\displaystyle{ (n_1+n_2+n) }$ are devisable by $\displaystyle{ d_x }$. Subtracting the two, $\displaystyle{ n }$ is devisable by $\displaystyle{ d_x }$. Note that this holds for arbitrary cycle $\displaystyle{ C }$ starting at $\displaystyle{ y }$, then $\displaystyle{ d_x }$ is the common divisor of all such $\displaystyle{ n }$ that $\displaystyle{ P^n_{y,y}\gt 0 }$. Since $\displaystyle{ d_y }$ is defined to be the greatest common divisor of the same set of $\displaystyle{ n }$, it holds that $\displaystyle{ d_y\ge d_x }$. Interchanging the role of $\displaystyle{ x }$ and $\displaystyle{ y }$, we can show that $\displaystyle{ d_x\ge d_y }$. Therefore $\displaystyle{ d_x=d_y }$.
$\displaystyle{ \square }$

Due to the above theorem, an irreducible Markov chain is aperiodic if one of the states is aperiodic.

Convergence of Markov chain

 Fundamental Theorem of Markov Chain Let $\displaystyle{ X_0,X_1,\ldots, }$ be an irreducible aperiodic Markov chain with finite state space $\displaystyle{ \Omega }$, transition matrix $\displaystyle{ P }$, and arbitrary initial distribution $\displaystyle{ \pi^{(0)} }$. Then, there exists a unique stationary distribution $\displaystyle{ \pi }$ such that $\displaystyle{ \pi P=\pi }$, and $\displaystyle{ \lim_{t\rightarrow\infty}\pi^{(0)}P^t=\pi. }$

The theorem says that if we run an irreducible aperiodic finite Markov chain for a sufficient long time $\displaystyle{ t }$, then, regardless of what the initial distribution was, the distribution at time $\displaystyle{ t }$ will be close to the stationary distribution $\displaystyle{ \pi }$.

Three pieces of information are delivered by the theorem regarding the stationary distribution:

• Existence: there exists a stationary distribution.
• Uniqueness: the stationary distribution is unique.
• Convergence: starting from any initial distribution, the chain converges to the stationary distribution.

Neither irreducibility nor aperiodicity is necessary for the existence of a stationary distribution. In fact, any finite Markov chain has a stationary distribution. Irreducibility and aperiodicity guarantee the uniqueness and convergence behavior of the stationary distribution.

• For a reducible chain, there could be more than one stationary distributions. We have seen such examples. Note that there do exist reducible Markov chains with just one stationary distribution. For example, the chain
$\displaystyle{ P=\begin{bmatrix} 1/2 & 1/2\\ 0 & 1\\ \end{bmatrix} }$
is reducible, but only has one stationary distribution $\displaystyle{ (0,1) }$, because the transition graph is still weakly connected.
• For a periodic chain, the stationary probability $\displaystyle{ \pi_x }$ of state $\displaystyle{ x }$ is not the limiting probability of being in state $\displaystyle{ x }$ but instead just the long-term frequency of visiting state $\displaystyle{ x }$.

Coupling

The above convergence theorem is proved by coupling, which is an important idea in probabilistic argument, and is a powerful tool for the analysis of Markov chains.

A Markov chain is a sequence of random variables

\displaystyle{ \begin{align}X_0,X_1,X_2\ldots\end{align} }

where the distribution of $\displaystyle{ X_0 }$ is given by an initial distribution $\displaystyle{ \pi^{(0)} }$; and for each $\displaystyle{ t=1,2,\ldots }$, assuming that $\displaystyle{ X_{t-1}=x }$, the distribution of $\displaystyle{ X_t }$ is given by the $\displaystyle{ x }$th row of the transition matrix $\displaystyle{ P }$, denoted as $\displaystyle{ P_x }$.

We can generate the chain by a sequence of uniform and independent random variables $\displaystyle{ U_0,U_1,\ldots }$ ranging over $\displaystyle{ [0,1] }$. Suppose that the states in $\displaystyle{ \Omega }$ assume an arbitrary total order $\displaystyle{ \lt }$. Initially

$\displaystyle{ X_0=y }$ if $\displaystyle{ \sum_{z\lt y}\pi^{(0)}_z\le U_0\lt \sum_{z\le y}\pi^{(0)}_z }$;

and for each $\displaystyle{ t=1,2,\ldots }$, assuming $\displaystyle{ X_{t-1}=x }$,

$\displaystyle{ X_t=y }$ if $\displaystyle{ \sum_{z\lt y}P_{x,z}\le U_0\lt \sum_{z\le y}P(x,z) }$.

The Markov chain generated in this way is distributed exactly the same as having initial distribution $\displaystyle{ \pi^{(0)} }$ and transition matrix $\displaystyle{ P }$.

Let $\displaystyle{ X_0,X_1,\ldots }$ be a finite Markov chain with initial distribution $\displaystyle{ \pi^{(0)} }$ and transition matrix $\displaystyle{ P }$, and generated by the uniform and independent random variables $\displaystyle{ U_0,U_1,\ldots }$. Suppose that the Markov chain has a stationary distribution $\displaystyle{ \pi }$, such that $\displaystyle{ \pi P=\pi }$. We run another chain $\displaystyle{ X_0',X_1',\ldots }$ with the initial distribution $\displaystyle{ \pi }$, transition matrix $\displaystyle{ P }$, and independent random sources $\displaystyle{ U_0',U_1',\ldots }$. So we have two independent sequences:

\displaystyle{ \begin{align} X_0,X_1,X_2\ldots\end{align} } and \displaystyle{ \begin{align}X_0',X_1',X_2'\ldots\end{align} }.

We define another chain, which starts as \displaystyle{ \begin{align}X_0,X_1,X_2\ldots\end{align} } and for the first time that $\displaystyle{ X_n=X_n' }$, the chain switches to $\displaystyle{ X_n',X_{n+1}',X_{n+2},\ldots }$. The transitions are illustrated by the following figure.

$\displaystyle{ \begin{matrix} \pi^{(0)}:& X_0 & \rightarrow & X_1 & \rightarrow & \cdots & \rightarrow & X_{n} \\ &\nparallel & & \nparallel & & \nparallel & & \parallel & \searrow\\ \pi^{}:& X_0' & \rightarrow & X_1' & \rightarrow & \cdots & \rightarrow & X_{n}' & \rightarrow & X_{n+1}' \rightarrow X_{n+2}' \rightarrow \cdots \end{matrix} }$

It is not hard to see that the distribution of the chain \displaystyle{ \begin{align}X_0,X_1,\ldots, X_{n}, X_{n+1}',X_{n+2}',\ldots\end{align} } is identically distributed as the original chain \displaystyle{ \begin{align}X_0,X_1,\ldots\end{align} }, since we do nothing except switching the source of randomness from $\displaystyle{ U_0,U_1,\ldots, }$ to the sequence $\displaystyle{ U_n',U_{n+1}',\ldots }$, which does not affect the distribution of the chain.

On the other hand, since the chain \displaystyle{ \begin{align}X_0',X_1',\ldots\end{align} } starts from a stationary distribution $\displaystyle{ \pi }$, by the definition of stationary distribution, it will stay in that distribution forever. Thus, the distribution of every one of \displaystyle{ \begin{align}X_{n+1}',X_{n+2}',\ldots\end{align} } is $\displaystyle{ \pi }$. Therefore, once $\displaystyle{ X_n=X_n' }$ for a finite $\displaystyle{ n }$, the chain \displaystyle{ \begin{align}X_0,X_1,\ldots\end{align} } converges to the stationary distribution $\displaystyle{ \pi }$.

Now we need to show that $\displaystyle{ X_n=X_n' }$ for some $\displaystyle{ n }$ will eventually happen. To this end, let $\displaystyle{ M }$ be the minimum integer such that $\displaystyle{ (P^M)_{x,y}\gt 0 }$ for all $\displaystyle{ x,y\in\Omega }$, we have

\displaystyle{ \begin{align} \Pr[X_M=X'_M] &\ge \Pr(X_M=x \land X_M'=x)\\ &= \Pr[X_M=x]\cdot \Pr[X_M'=x]\\ &\ge c^2 \end{align} }

where $\displaystyle{ c=\min\{(P^M)_{x,y}\mid x,y\in\Omega\} }$ and hence it is a positive constant.

Similarly, we have

\displaystyle{ \begin{align} \Pr[X_{2M}\ne X'_{2M}] &= \Pr[X_M\ne X'_M]\cdot \Pr[X_{2M}\ne X'_{2M}\mid X_M\ne X'_M]\\ &\le (1-c^2)^2 \end{align} }

Repeat the above argument, we have for every integer $\displaystyle{ \ell\ge 0 }$

$\displaystyle{ \Pr[X_{\ell M}\ne X'_{\ell M}]\le (1-c^2)^{\ell} }$

This implies $\displaystyle{ \Pr[X_n=X'_n]\to 1 }$ as $\displaystyle{ n\to\infty }$.

Hitting time and the stationary distribution

We will see that the stationary distribution of a Markov chain is related to its hitting times. For a Markov chain starting from state $\displaystyle{ x }$, let

$\displaystyle{ T_{x,y}=\min\{n\gt 0\mid X_n=y\} }$,

which is the first time that a chain starting from state $\displaystyle{ x }$ visits state $\displaystyle{ y }$, with the convention that $\displaystyle{ T_{x,y}=\infty }$ if the chain never visit $\displaystyle{ y }$. We define the hitting time

$\displaystyle{ \tau_{x,y}=\mathbf{E}[T_{x,y}] }$.

The special case $\displaystyle{ \tau_{x,x} }$ gives the expected time a chain starting from state $\displaystyle{ x }$ returns to state $\displaystyle{ x }$.

 Theorem Any irreducible aperiodic Markov chain with finite state space $\displaystyle{ \Omega }$, and transition matrix $\displaystyle{ P }$ has a stationary distribution $\displaystyle{ \pi }$ such that $\displaystyle{ \pi_x=\lim_{n\rightarrow\infty}(P^n)_{y,x}=\frac{1}{\tau_{x,x}} }$ for any $\displaystyle{ x\in\Omega }$.

Note that in the above theorem, the limit $\displaystyle{ \lim_{n\rightarrow\infty}(P^n)_{y,x} }$ does not depend on the $\displaystyle{ y }$, which means that $\displaystyle{ P^n }$ in the limit has identical rows.

We will not prove the lemma, but only give an informal justification: the expected time between visits to state $\displaystyle{ x }$ is $\displaystyle{ \tau_{x,x} }$, and therefore state $\displaystyle{ x }$ is visited $\displaystyle{ \frac{1}{\tau_{x,x}} }$ of the time. Not that $\displaystyle{ \lim_{n\rightarrow\infty}(P^n)_{y,x} }$ represents the probability a state chosen far in the future (at time $\displaystyle{ n\rightarrow\infty }$) is at state $\displaystyle{ x }$ when the chain starts at state $\displaystyle{ y }$, but if the future is far, who $\displaystyle{ y }$ is does not really matter, and $\displaystyle{ \lim_{n\rightarrow\infty}(P^n)_{y,x} }$ is the frequency that $\displaystyle{ x }$ is visited, which is $\displaystyle{ \frac{1}{\tau_{x,x}} }$.

PageRank

PageRank is the algorithm reportedly used by Google to assign a numerical rank to every web page. The rank of a page measures the "importance" of the page. A page has higher rank if it is pointed to by more high-rank pages. Low-rank pages have less influence on the rank of a page. If one page points to many others, it will have less influence on their ranking than if it just points to a few.

This intuitive idea can be formalized as follows. The world-wide-web is treated as a directed graph $\displaystyle{ G(V,E) }$, with web pages as vertices and hyperlinks as directed edges. The rank of vertex $\displaystyle{ v }$ is denoted $\displaystyle{ r(v) }$, and is supposed to satisfy:

$\displaystyle{ r(v)=\sum_{u:(u,v)\in E}\frac{r(u)}{d_+(u)}, \qquad (*) }$

where $\displaystyle{ d_+(u) }$ is the number of edges going out of $\displaystyle{ u }$. Note that the sum is over edges going in to $\displaystyle{ v }$.

This formula nicely models both the intuitions that a page gets higher rank if it is pointed by more high-rank pages, and that the influence of a page is penalized by the number of pages it points to. Let $\displaystyle{ P }$ be a matrix with rows and columns corresponded to vertices, and $\displaystyle{ \forall u,v\in V }$,

$\displaystyle{ P(u,v)=\begin{cases} \frac{1}{d_+(u)}& \mbox{if }(u,v)\in E,\\ 0& \mbox{otherwise}. \end{cases} }$

Then the formular \displaystyle{ \begin{align}(*)\end{align} } can be expressed as

\displaystyle{ \begin{align} rP=r. \end{align} }

It is also easy to verify that $\displaystyle{ P }$ is stochastic, that is, \displaystyle{ \begin{align}\sum_{v}P(u,v)=1\end{align} } for all $\displaystyle{ u\in V }$. Then the ranks of a pages is actually a stationary distribution of the Markov chain with transition matrix $\displaystyle{ P }$. This is not entirely a coincidence. $\displaystyle{ P }$ is the transition matrix for the random walk over the web pages, defined as that at each time, pick a uniform page pointed by the current page and walk to it. This can be imagined as a "tireless random surfer" who starts from an arbitrary page, randomly follows the hyperlinks, and given infinitely long time, will eventually approaches the stationary distribution. The importance of a web page is reflected by the frequency that the random surfer visits the page, which is the stationary probability.

We assume the world-wide-web is strongly connected, thus the Markov chain is irreducible. And given the huge number of webpages over the Internet, it is almost impossible that the lengths of all cycles have a common divisor greater than 1, thus the Markov chain is aperiodic. Therefore, the random surfer model indeed converges.

In practice, PageRank also consider a damping factor, since a typical surfer cannot browse the web forever. The damping factor effectively gives an upper bound on the number of hyperlinks the surfer would follow before he/she has a random start over.

Random Walk on Graphs

A walk on a graph $\displaystyle{ G = (V,E) }$ is a sequence of vertices $\displaystyle{ v_1, v_2, \ldots \in V }$ such that $\displaystyle{ v_{i+1} }$ is a neighbor of $\displaystyle{ v_i }$ for every index $\displaystyle{ i }$. When $\displaystyle{ v_{i+1} }$ is selected uniformly at random from among $\displaystyle{ v_i }$’s neighbors, independently for every $\displaystyle{ i }$, this is called a random walk on $\displaystyle{ G }$.

We consider the special case that $\displaystyle{ G(V,E) }$ is an undirected graph, and denote that $\displaystyle{ n=|V| }$ and $\displaystyle{ m=|E| }$.

A Markov chain is defined by this random walk, with the vertex set $\displaystyle{ V }$ as the state space, and the transition matrix $\displaystyle{ P }$, which is defined as follows:

$\displaystyle{ P(u,v)=\begin{cases} \frac{1}{d(u)}&\mbox{if }(u,v)\in E,\\ 0 & \mbox{otherwise }, \end{cases} }$

where $\displaystyle{ d(u) }$ denotes the degree of vertex $\displaystyle{ u }$.

Note that unlike the PageRank example, now the probability depends on $\displaystyle{ d(u) }$ instead of $\displaystyle{ d_+(u) }$. This is because the graph is undirected.

 Proposition Let $\displaystyle{ M_G }$ be the Markov chain defined as above. $\displaystyle{ M_G }$ is irreducible if and only if $\displaystyle{ G }$ is connected. $\displaystyle{ M_G }$ is aperiodic if and only if $\displaystyle{ G }$ is non-bipartite.

We leave the proof as an exercise.

We can just assume $\displaystyle{ G }$ is connected, so we do not have to worry about the reducibility any more.

The periodicity of a random walk on a undirected bipartite graph is usually dealt with by the following trick of "lazy" random walk.

Lazy random walk
Given an undirected graph $\displaystyle{ G(V,E) }$, a random walk is defined by the transition matrix
$\displaystyle{ P'(u,v)=\begin{cases} \frac{1}{2} & \mbox{if }u=v,\\ \frac{1}{2d(u)}&\mbox{if }(u,v)\in E,\\ 0 & \mbox{otherwise }. \end{cases} }$
For this random walk, at each step, we first flip a fair coin to decide whether to move or to stay, and if the coin told us to move, we pick a uniform edge and move to the adjacent vertex. It is easy to see that the resulting Markov chain is aperiodic for any $\displaystyle{ G }$.

We consider the non-lazy version of random walk. We observe that the random walk has the following stationary distribution.

 Theorem The random walk on $\displaystyle{ G(V,E) }$ with $\displaystyle{ |E|=m }$ has a stationary distribution $\displaystyle{ \pi }$, where $\displaystyle{ \forall v\in V }$, \displaystyle{ \begin{align} \pi_v=\frac{d(v)}{2m}\end{align} } for $\displaystyle{ v\in V }$.
Proof.
 First, since $\displaystyle{ \sum_{v\in V}d(v)=2m }$, it follows that $\displaystyle{ \sum_{v\in V}\pi_v=\sum_{v\in V}\frac{d(v)}{2m}=1, }$ thus $\displaystyle{ \pi }$ is a well-defined distribution. And let $\displaystyle{ N(v) }$ denote the set of neighbors of $\displaystyle{ v }$. Then for any $\displaystyle{ v\in V }$, $\displaystyle{ (\pi P)_v=\sum_{u\in V}\pi_uP(u,v)=\sum_{u\in N(v)}\frac{d(u)}{2m}\frac{1}{d(u)}=\frac{1}{2m}\sum_{u\in N(v)}1=\frac{d(v)}{2m}=\pi_v. }$ Thus $\displaystyle{ \pi P=\pi }$, and $\displaystyle{ \pi }$ is stationary.
$\displaystyle{ \square }$

For connected and non-bipartite $\displaystyle{ G }$, the random walk converges to this stationary distribution. Note that the stationary distribution is proportional to the degrees of the vertices, therefore, if $\displaystyle{ G }$ is a regular graph, that is, $\displaystyle{ d(v) }$ is the same for all $\displaystyle{ v\in V }$, the stationary distribution is the uniform distribution.

The following parameters of random walks are closely related to the performances of randomized algorithms based on random walks:

• Hitting time: It takes how long for a random walk to visit some specific vertex.
• Cover time: It takes how long for a random walk to visit all vertices.
• Mixing time: It takes how long for a random walk to be close enough to the stationary distribution.

Hitting and Covering

For any $\displaystyle{ u,v\in V }$, the hitting time $\displaystyle{ \tau_{u,v} }$ is the expected number of steps before vertex $\displaystyle{ v }$ is visited, starting from vertex $\displaystyle{ u }$.

Recall that any irreducible aperiodic Markov chain with finite state space converges to the unique stationary distribution \displaystyle{ \begin{align} \pi_v=\frac{1}{\tau_{v,v}}. \end{align} } Combining with what we know about the stationary distribution $\displaystyle{ \pi }$ of a random walk on an undirected graph $\displaystyle{ G(V,E) }$ where $\displaystyle{ |E|=m }$, we have that for any vertex $\displaystyle{ v\in V }$,

$\displaystyle{ \tau_{v,v}=\frac{1}{\pi_v}=\frac{2m}{d(v)}. }$

This fact can be used to estimate the hitting time between two adjacent vertices.

 Lemma For a random walk on an undirected graph $\displaystyle{ G(V,E) }$ where$\displaystyle{ |E|=m }$, for any $\displaystyle{ u,v\in V }$ that $\displaystyle{ (u,v)\in E }$, the mean hitting time \displaystyle{ \begin{align}\tau_{u,v}\lt 2m\end{align} }.
Proof.
 The proof is by double counting. We know that $\displaystyle{ \tau_{v,v}=\frac{1}{\pi_v}=\frac{2m}{d(v)}. }$ Let $\displaystyle{ N(v) }$ be the set of neighbors of vertex $\displaystyle{ v }$. We run the random walk from $\displaystyle{ v }$ for one step, and by the law of total expectation, $\displaystyle{ \tau_{v,v}=\sum_{w\in N(v)}\frac{1}{d(v)}(1+\tau_{w,v}). }$ Combining the above two equations, we have $\displaystyle{ 2m=\sum_{w\in N(v)}(1+\tau_{w,v}), }$ which implies that $\displaystyle{ \tau_{u,v}\lt 2m }$.
$\displaystyle{ \square }$

Note that the lemma holds only for the adjacent $\displaystyle{ u }$ and $\displaystyle{ v }$. With this lemma, we can prove an upper bound on the cover time.

• Let $\displaystyle{ C_u }$ be the expected number of steps taken by a random walk which starts at $\displaystyle{ u }$ to visit every vertex in $\displaystyle{ G }$ at least once. The cover time of $\displaystyle{ G }$, denoted $\displaystyle{ C(G) }$ is defined as $\displaystyle{ C(G)=\max_{u\in V}C_u }$.
 Theorem (cover time) For any connected undirected graph $\displaystyle{ G(V,E) }$ with $\displaystyle{ |V|=n }$ and $\displaystyle{ |E|=m }$, the cover time $\displaystyle{ C(G)\le 4nm }$
Proof.
 Let $\displaystyle{ T }$ be an arbitrary spanning tree of $\displaystyle{ G }$. There exists an Eulerian tour of $\displaystyle{ T }$ in which each edge is traversed once in each direction. Let $\displaystyle{ v_1\rightarrow v_2\rightarrow \cdots \rightarrow v_{2(n-1)}\rightarrow v_{2n-1}=v_1 }$ be such a tour. Clearly the expected time to go through the vertices in the tour is an upper bound on the cover time. Hence, $\displaystyle{ C(G)\le\sum_{i=1}^{2(n-1)}\tau_{v_{i},v_{i+1}}\lt 2(n-1)\cdot 2m\lt 4nm. }$
$\displaystyle{ \square }$

A tighter bound (with a smaller constant factor) can be proved with a more careful analysis. Please read the textbook [MR].

Electric Networks

An undirected graph $\displaystyle{ G=(V,E) }$ is called an electrical network, if

1. Every edge $\displaystyle{ e=\{u,v\} }$ is associated with resistance $\displaystyle{ R_{uv} }$.
2. The flow of current and the voltage at each vertex in the network follows Kirchhoff's Law and Ohm's Law.

In the following, we use $\displaystyle{ C_{u\rightarrow v} }$ to denote the current flow from $\displaystyle{ u }$ to $\displaystyle{ v }$, $\displaystyle{ \phi_u }$ to denote the potential at vertex $\displaystyle{ u }$, $\displaystyle{ \phi_{u,v} }$ to denote the potential difference between $\displaystyle{ u }$ and $\displaystyle{ v }$, i.e. $\displaystyle{ \phi_{u,v}=\phi_u-\phi_v }$.

• Kirchhoff's Law: For every vertex $\displaystyle{ v }$, the sum of currents entering $\displaystyle{ v }$ is equal to the the sum of currents leaving $\displaystyle{ v }$.
• Ohm's Law: For every edge $\displaystyle{ e=\{u,v\} }$ in the graph, the currents across $\displaystyle{ e }$ is equal to the difference of potential between $\displaystyle{ u }$ and $\displaystyle{ v }$ over the resistance of $\displaystyle{ e }$, i.e. $\displaystyle{ C_{u\rightarrow v}=\frac{\phi_{u,v}}{R_{uv}} }$.
 Definition (Effective Resistance) Let $\displaystyle{ u,v\in V }$, the effective resistance $\displaystyle{ R(u,v) }$ between $\displaystyle{ u }$ and $\displaystyle{ v }$ is defined to be the potential difference between $\displaystyle{ u }$ and $\displaystyle{ v }$ while one unit of current is sent from $\displaystyle{ u }$ to $\displaystyle{ v }$.

Now we use the idea of electrical network to analyze the cover time of random walk. Consider an undirected graph $\displaystyle{ G=(V,E) }$, we construct an electrical network whose underlying graph is $\displaystyle{ G }$ and $\displaystyle{ R_e=1 }$ for every $\displaystyle{ e\in E }$. If we inject $\displaystyle{ d(w) }$ units of currents into each vertex $\displaystyle{ w\in V }$, where $\displaystyle{ d(w) }$ is the degree of $\displaystyle{ w }$, and remove all the $\displaystyle{ 2|E|=2m }$ units of currents from $\displaystyle{ v }$, then

 Lemma For every $\displaystyle{ u,v\in V }$ $\displaystyle{ \phi_{u,v}=\tau_{u,v} }$
Proof.
 We first represent $\displaystyle{ \tau_{u,v} }$ by a linear system. Consider one step of random walk, we have \displaystyle{ \begin{align} \tau_{u,v}&=\sum_{xu\in E}\frac{1}{d(u)}(1+\tau_{x,v})\\ &=1+\frac{1}{d(u)}\sum_{xu\in E}\tau_{x,v}. \qquad(*) \end{align} } On the other hand, for the corresponding electric network constructed as above, \displaystyle{ \begin{align} d(u)&=\sum_{ux\in E}C_{u\rightarrow x} && \mbox{(Kirchhoff)}\\ &=\sum_{ux\in E}\phi_{u,x} && \mbox{(Ohm)}\\ &=\sum_{ux\in E}(\phi_{u,v}-\phi_{x,v})\\ &=d(u)\phi_{u,v}-\sum_{ux\in E}\phi_{x,v}. \end{align} } Thus $\displaystyle{ \phi_{u,v}=1+\frac{1}{d(u)}\sum_{ux\in E}\phi_{x,v} \qquad(**) }$ Note that (*) and (**) are both linear systems with unique solution, thus $\displaystyle{ \tau_{u,v}=\phi_{u,v} }$.
$\displaystyle{ \square }$
 Theorem (Chandra-Raghavan-Ruzzo-Smolensky-Tiwari 1989) Let $\displaystyle{ u,v\in V }$, then $\displaystyle{ \tau_{u,v}+\tau_{v,u}=2|E|\cdot R(u,v) }$
Proof.
 We now construct four electrical networks $\displaystyle{ A,B,C,D }$ with underlying graph $\displaystyle{ G }$. First, we inject $\displaystyle{ d(w) }$ units of currents into each vertex $\displaystyle{ w }$ and remove $\displaystyle{ 2|E| }$ units of currents from $\displaystyle{ v }$. Let $\displaystyle{ A }$ denote this electrical network, then by the above lemma, we have $\displaystyle{ \tau_{u,v}=\phi_{u,v}^A }$. Similarly, if we inject $\displaystyle{ d(w) }$ units of currents into every vertex $\displaystyle{ w }$, remove $\displaystyle{ 2|E| }$ units of currents from $\displaystyle{ u }$ and denote this electrical network by $\displaystyle{ B }$, then $\displaystyle{ \tau_{v,u}=\phi_{v,u}^B }$. Now we change the direction of all the currents in $\displaystyle{ B }$, that is, $\displaystyle{ 2|E| }$ units of currents are injected into $\displaystyle{ u }$ and $\displaystyle{ d(w) }$ units of currents are removed from every vertex $\displaystyle{ w }$. In this electrical network $\displaystyle{ C }$, we have $\displaystyle{ \phi_{u,v}^C=-\phi_{u,v}^B=\phi_{v,u}^B }$, which gives us $\displaystyle{ \tau_{v,u}=\phi_{v,u}^B=\phi_{u,v}^C }$ as a consequence. Since electrical networks are linear systems, we can super-pose $\displaystyle{ A }$ and $\displaystyle{ C }$ (summing up the voltage and currents on corresponding vertices and edges) and let the resulting electrical network be $\displaystyle{ D }$. By the linearity, we have $\displaystyle{ \phi_{u,v}^D=\phi_{u,v}^A+\phi_{u,v}^C=\tau_{u,v}+\tau_{v,u} }$. Note that the resulting electric network $\displaystyle{ D }$ is an electrical network such that $\displaystyle{ 2|E| }$ units of currents are injected into $\displaystyle{ u }$ and $\displaystyle{ 2|E| }$ units of currents are removed form $\displaystyle{ v }$, thus $\displaystyle{ \phi_{u,v}^D=2|E|\cdot R(u,v) }$ by definition of effective resistance. Altogether we have $\displaystyle{ \tau_{u,v}+\tau_{v,u}=\phi_{u,v}^A+\phi_{u,v}^C=\phi_{u,v}^D=2|E|\cdot R(u,v). }$
$\displaystyle{ \square }$

Armed with this theorem, we can now give a better estimation of the cover time of random walk. Let $\displaystyle{ T }$ be a spanning tree of $\displaystyle{ G }$, and $\displaystyle{ x=v_{1}\to v_{2}\to\ldots\to v_{2n}=x }$ be an Euler tour of $\displaystyle{ T }$ for any particular vertex $\displaystyle{ x\in V }$, then

$\displaystyle{ C_x\le \sum_{i=1}^{2n-1}H_{v_i v_{i+1}}=\sum_{uv\in T}(\tau_{u,v}+\tau_{v,u})=2m \sum_{uv\in T}R(u,v)\lt 2mn. }$

Thus the cover time for any connected graph $\displaystyle{ G }$ of $\displaystyle{ n }$ vertices and $\displaystyle{ m }$ edges is bounded as

$\displaystyle{ C(G)=\max_{x\in V}C_x\le 2mn }$.

Graph Connectivity

USTCON stands for undirected $\displaystyle{ s }$-$\displaystyle{ t }$ connectivity. It is the problem which asks whether there is a path from vertex $\displaystyle{ s }$ to vertex $\displaystyle{ t }$ in a given undirected graph $\displaystyle{ G(V,E) }$. This problem is an abstraction of various search problems in graphs, and has theoretical significance in complexity theory.

The problem can be solved deterministically by traversing the graph $\displaystyle{ G(V,E) }$, which takes $\displaystyle{ \Omega(n) }$ extra space to keep track of which vertices have been visited, where $\displaystyle{ n=|V| }$. And the following theorem is implied by the upper bound on the cover time.

 Theorem (Aleliunas-Karp-Lipton-Lovász-Rackoff 1979) USTCON can be solved by a polynomial time Monte Carlo randomized algorithm with bounded one-sided error, which uses $\displaystyle{ O(\log n) }$ extra space.

The algorithm is a random walk starting at $\displaystyle{ s }$. If the walk reaches $\displaystyle{ t }$ in $\displaystyle{ 4n^3 }$ steps, then return "yes", otherwise return "no".

It is obvious that if $\displaystyle{ s }$ and $\displaystyle{ t }$ are disconnected, the random walk from $\displaystyle{ s }$ can never reach $\displaystyle{ t }$, thus the algorithm always returns "no".

We know that for an undirected $\displaystyle{ G }$, the cover time is $\displaystyle{ \lt 4nm\lt 2n^3 }$. So if $\displaystyle{ s }$ and $\displaystyle{ t }$ are connected, the expected time to reach $\displaystyle{ t }$ from $\displaystyle{ s }$ is $\displaystyle{ \lt 2n^3 }$. By Markov's inequality, the probability that it takes longer than $\displaystyle{ 4n^3 }$ steps to reach $\displaystyle{ t }$ from $\displaystyle{ s }$ is $\displaystyle{ \lt 1/2 }$.

The random walk use $\displaystyle{ O(\log n) }$ bits to store the current position, and another $\displaystyle{ O(\log n) }$ bits to count the number of steps. So the total space used by the algorithm inaddition to the input is $\displaystyle{ O(\log n) }$.

This shows that USTCON is in the complexity class RL (randomized log-space).

Story in complexity theory

If the randomness is forbidden, it is known that USTCON can be solved nondeterministically in logarithmic space, thus USTCON is in NL. In fact USTCON is complete for the symmetric version of nondeterministic log-space. That is, every problem in the class of SL can be solved by USTCON via log-space reductions. Therefore, USTCON$\displaystyle{ \in }$RL implies that SL$\displaystyle{ \subseteq }$RL.

In 2004, Reingold shows that USTCON can be solved deterministically in log-space, which proves SL=L. The deterministic algorithm for USTCON is by the derandomization of random walk.

It is conjectured that RL=L, but this is still open.