随机算法 (Spring 2013)/Markov Chain and Random Walk

From TCS Wiki
Revision as of 14:34, 8 June 2013 by imported>Etone (The Markov chain convergence theorem)
Jump to navigation Jump to search

Markov Chain

A stochastic processes {XttT} is a collection of random variables. The index t is often called time, as the process represents the value of a random variable changing over time. Let Ω be the set of values assumed by the random variables Xt. We call each element of Ω a state, as Xt represents the state of the process at time 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 T is countable. Specifically, we assume that T={0,1,2,} and the process is X0,X1,X2,
discrete space
The state space Ω is countable. We are especially interested in the case that Ω 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 X0,X1, 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 X0,X1, satisfies the Markov property if
Pr[Xn+1=xn+1X0=x0,X1=x1,,Xn=xn]=Pr[Xn+1=xn+1Xn=xn]
for all n and all x0,,xn+1Ω.

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 X0,X1, of discrete time and discrete space is a Markov chain if it has the Markov property.

Transition matrix

Let Px,y(t+1)=Pr[Xt+1=yXt=x]. For a Markov chain with a finite state space Ω=[N]. This gives us a transition matrix P(t+1) at time t. The transition matrix is an N×N matrix of nonnegative entries such that the sum over each row of P(t) is 1, since

yPx,y(t+1)=yPr[Xt+1=yXt=x]=1.

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

Let π(t) be the distribution of the chain at time t, that is, πx(t)=Pr[Xt=x]. For a finite chain, π(t) is a vector of N nonnegative entries such that xπx(t)=1. In linear algebra, vectors of this type are called stochastic vectors. Then, it holds that

π(t+1)=π(t)P(t+1).

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

πy(t+1)=Pr[Xt+1=y]=xPr[Xt+1=yXt=x]Pr[Xt=x]=xπx(t)Px,y(t+1)=(π(t)P(t+1))y.

Therefore, a finite Markov chain X0,X1, is specified by an initial distribution π(0) and a sequence of transition matrices P(1),P(2),. And the transitions of chain can be described by a series of matrix products:

π(0)P(1)π(1)P(2)π(2)P(3)π(t)P(t+1)π(t+1)

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

Px,y(t)=Px,y for all t.

The transitions of a homogenous Markov chain is given by a single matrix P. Suppose that π(0) is the initial distribution. At each time t,

π(t+1)=π(t)P.

Expanding this recursion, we have

π(n)=π(0)Pn.

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 P be an N×N stochastic matrix. A process X0,X1, with finite space Ω=[N] is said to be a (homogenous) Markov chain with transition matrix P, if for all n0, all x,y[N] and all x0,,xn1[N] we have
Pr[Xn+1=yX0=x0,,Xn1=xn1,Xn=x]=Pr[Xn+1=yXn=x]=Px,y.

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

  • initial distribution π(0);
  • transition matrix P.

Then the transitions can be simulated by matrix products:

π(0)Pπ(1)Pπ(2)Pπ(t)Pπ(t+1)P

The distribution of the chain at time n can be computed by π(n)=π(0)Pn.

Transition graph

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

  • V=Ω, i.e. each node of the transition graph corresponds to a state of the Markov chain;
  • for any x,yV, (x,y)E if and only if Px,y>0, and the weight w(x,y)=Px,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 yPx,y=1 for every x. Therefore, a Markov chain is equivalent to a random walk, so these two terms are often used interchangeably.

Stationary distributions

Suppose π is a distribution over the state space Ω such that, if the Markov chain starts with initial distribution π(0)=π, then after a transition, the distribution of the chain is still π(1)=π. Then the chain will stay in the distribution π forever:

πPπPπP

Such π is called a stationary distribution.

Definition (stationary distribution)
A stationary distribution of a finite Markov chain with transition matrix P is a probability distribution π such that
πP=π.
Example
An N×N matrix is called double stochastic if every row sums to 1 and every column sums to 1. If the transition matrix P of the chain is double stochastic, the uniform distribution πx=1/N for all x, is a stationary distribution. (Check by yourself.)
If the transition matrix 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:

P=[01013023131313].

Run the chain for a while, we have:

P5[0.24690.40740.34570.25100.36210.38680.25100.36630.3827],P10[0.25000.37470.37520.25000.37510.37490.25000.37510.3749],P20[0.25000.37500.37500.25000.37500.37500.25000.37500.3750].

Therefore, no matter what the initial distribution π(0) is, after 20 steps, π(0)P20 is very close to the distribution (0.25,0.375,0.375), which is a stationary distribution for 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:

P=[121200132300003414001434].

And

P20[0.40.6000.40.600000.50.5000.50.5].

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 (0.4,0.6,0,0) and (0,0,0.5,0.5). We observe that this is because the original chain 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:

P=[0110].

The chain oscillates between the two states. Then

Pt=[0110] for any odd t, and
Pt=[1001] for any even 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 y is accessible from state x if it is possible for the chain to visit state y if the chain starts in state x, or, in other words,
Pn(x,y)>0
for some integer n0. State x communicates with state y if y is accessible from x and x is accessible from 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:

  • y is accessible from x means that y is connected from x in the transition graph, i.e. there is a directed path from x to y.
  • x communicates with y means that x and 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 x is the greatest common divisor (gcd)
dx=gcd{n(Pn)x,x>0}.
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 x is dx=3. Then, starting from state x,

x,,,,,,,,,,,,,

only the squares are possible to be x.

In the transition graph of a finite Markov chain, (Pn)x,x>0 is equivalent to that x is on a cycle of length n. Period of a state x is the greatest common devisor of the lengths of cycles passing x.

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

Theorem
If the states x and y communicate, then dx=dy.
Proof.
For communicating x and j>x<, there is a path P1 from x to y of length n1, and there is a path P2 from y to x of length n2. Then P1P2 gives a cycle starting at x of length n1+n+2, and

for any cycle C starting at y of length n, P1CP2 gives a cycle starting at x of length n1+n2+n. Since the period of x is dx, then both (n1+n2) and (n1+n2+n) are devisable by dx. Subtracting the two, n is devisable by dx. Note that this holds for arbitrary cycle C starting at y, then dx is the common divisor of all such n that Py,yn>0. Since dy is defined to be the greatest common divisor of the same set of n, it holds that dydx. Interchanging the role of x and y, we can show that dxdy. Therefore dx=dy.

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

The Markov chain convergence theorem

Theorem (Markov chain convergence theorem)
Let X0,X1,, be an irreducible aperiodic Markov chain with finite state space Ω, transition matrix P, and arbitrary initial distribution π(0). Then, there exists a stationary distribution π such that πP=π, and
limtπ(0)Pt=π.

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

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
P=[1/21/201]
is reducible, but only has one stationary distribution (0,1), because the transition graph is still weakly connected.
  • For a periodic chain, the stationary probability πx of state x is not the limiting probability of being in state x but instead just the long-term frequency of visiting state x.

Coupling

The 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

X0,X1,X2

where the distribution of X0 is given by an initial distribution π(0); and for each t=1,2,, assuming that Xt1=x, the distribution of Xt is given by the xth row of the transition matrix P, denoted as Px.

So we can generate the chain by a sequence of uniform and independent random variables U0,U1, ranging over [0,1]. Initially

X0=y if z<yπz(0)U0<zyπz(0);

and for each t=1,2,, assuming Xt1=x,

Xt=y if z<yPx,zU0<zyP(x,z).

The Markov chain generated in this way is distributed exactly the same as having initial distribution π(0) and transition matrix P.

Let X0,X1, be a finite Markov chain with initial distribution π(0) and transition matrix P, and generated by the uniform and independent random variables U0,U1,. Suppose that the Markov chain has a stationary distribution π, such that πP=π. We run another chain X0,X1, with the initial distribution π, transition matrix P, and independent random sources U0,U1,. So we have two independent sequences:

X0,X1,X2 and X0,X1,X2.

We define another chain, which starts as X0,X1,X2 and for the first time that Xn=Xn, the chain switches to Xn,Xn+1,Xn+2,. The transitions are illustrated by the following figure.

π(0):X0X1Xnπ:X0X1XnXn+1Xn+2

It is not hard to see that the distribution of the chain X0,X1,,Xn,Xn+1,Xn+2, is identically distributed as the original chain X0,X1,, since we do nothing except switching the source of randomness from U0,U1,, to the sequence Un,Un+1,, which does not affect the distribution of the chain.

On the other hand, since the chain X0,X1, starts from a stationary distribution π, by the definition of stationary distribution, it will stay in that distribution forever. Thus, the distribution of every one of Xn+1,Xn+2, is π. Therefore, once Xn=Xn for a finite n, the chain X0,X1, converges to the stationary distribution π.


Now we need to show that Xn=Xn for some n will eventually happen. To this end, let M be the minimum integer such that (PM)x,y>0 for all i,jΩ, we have

Pr[XM=XM]Pr(XM=xXM=x)=Pr[XM=x]Pr[XM=x]c2

where c=min{(PM)x,yi,jΩ} and hence it is a positive constant.

Similarly, we have

Pr[X2MX2M]=Pr[XMXM]Pr[X2MX2MXMXM](1c2)2

Repeat the above argument, we have for every integer 0

Pr[XMXM](1c2)

This implies Pr[Xn=Xn]1 as n.

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 x, let

Tx,y=min{n>0Xn=y},

which is the first time that a chain starting from state x visits state y, with the convention that Tx,y= if the chain never visit y. We define the hitting time

τx,y=E[Tx,y].

The special case τx,x gives the expected time a chain starting from state x returns to state x.

Theorem
Any irreducible aperiodic Markov chain with finite state space Ω, and transition matrix P has a stationary distribution π such that
πx=limn(Pn)y,x=1τx,x for any xΩ.

Note that in the above theorem, the limit limn(Pn)y,x does not depend on the y, which means that Pn 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 x is τx,x, and therefore state x is visited 1τx,x of the time. Not that limn(Pn)y,x represents the probability a state chosen far in the future (at time n) is at state x when the chain starts at state y, but if the future is far, who y is does not really matter, and limn(Pn)y,x is the frequency that x is visited, which is 1τ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 G(V,E), with web pages as vertices and hyperlinks as directed edges. The rank of vertex v is denoted r(v), and is supposed to satisfy:

r(v)=u:(u,v)Er(u)d+(u),()

where d+(u) is the number of edges going out of u. Note that the sum is over edges going in to 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 P be a matrix with rows and columns corresponded to vertices, and u,vV,

P(u,v)={1d+(u)if (u,v)E,0otherwise.

Then the formular () can be expressed as

rP=r.

It is also easy to verify that P is stochastic, that is, vP(u,v)=1 for all uV. Then the ranks of a pages is actually a stationary distribution of the Markov chain with transition matrix P. This is not entirely a coincidence. 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.