A Markov Chain is a sequence of states where transitions between states occur ordered in time with the probability of transition depending only on the previous state. Here the states will be assumed a discrete finite set and time a discrete unbounded set. If the set of states is given by {x1, x2,, xN}\{x_1,\ x_2,\ldots,\ x_N\} the probability that the process will be in state xix_i at time tt is denoted by P(Xt=xi)P(X_t=x_i), referred to as the distribution. Markov Chain equilibrium is defined by limtP(Xt=xi) < \lim_{t\to\infty}P(X_t=x_i)\ <\ \infty, that is, as time advances
P(Xt=xi)P(X_t=x_i) becomes independent of time. Here a solution for this limit is discussed and illustrated with examples.

Model

The Markov Chain model is constructed from the set of states {x1, x2,, xN}\{x_1,\ x_2,\ldots,\ x_N\} ordered in time. The process starts at time t=0t=0 with state X0=xiX_0=x_i. At the next step, t=1t=1, the process will assume a state X1=xjX_1=x_j with probability P(X1=xjX0=xi)P(X_1=x_j|X_0=x_i) since it will depend on the previous state x0x_0 as defined for a Markov Process. At the next time step t=2t=2 the process state will be X2=xkX_2=x_k with probability, P(X2=xkX0=xi,X1=xj)=P(X2=xkX1=xj), P(X_2=x_k|X_0=x_i, X_1=x_j)=P(X_2=x_k|X_1=x_j), since by definition the probability of state transition depends only upon the state at the previous time step. For an arbitrary time the transition from a state Xt=xjX_{t}=x_j to a state Xt+1=xjX_{t+1}=x_j will occur with probability, P(Xt+1=xjXt=xi)P(X_{t+1}=x_j|X_t=x_i) that is independent of tt. Transition probabilities have the form of a matrix,

Pij=P(Xt+1=xjXt=xi). P_{ij} = P(X_{t+1}=x_j|X_t=x_i).

PP will be an N×NN\times N matrix where NN is determined by the number of possible states. Each row represents the Markov Chain transition probability from that state at time tt and the columns the values at t+1t+1. It follows that, j=1NPij=1Pij  0     (1). \begin{gathered} \sum_{j=1}^{N}P_{ij} = 1\\ P_{ij}\ \geq\ 0 \end{gathered} \ \ \ \ \ (1).

Equation (1)(1) is the definition of a Stochastic Matrix.

The transition probability for a single step in the Markov Process is defined by PP. The transition probability across two time steps can be obtained with use of the Law of Total Probability, P(Xt+2=xjXt=xi)=k=1NP(Xt+2=xjXt=xi,Xt+1=xk)P(Xt+1=xkXt=xi)=k=1NP(Xt+2=xjXt+1=xk)P(Xt+1=xkXt=xi)=k=1NPkjPik=k=1NPikPkj=(P2)ij, \begin{aligned} P(X_{t+2}=x_j|X_t=x_i) &= \sum_{k=1}^{N} P(X_{t+2}=x_j | X_{t}=x_i, X_{t+1}=x_k)P(X_{t+1}=x_k | X_{t}=x_i) \\ &= \sum_{k=1}^{N} P(X_{t+2}=x_j | X_{t+1}=x_k)P(X_{t+1}=x_k | X_{t}=x_i) \\ &= \sum_{k=1}^{N} P_{kj}P_{ik} \\ &= \sum_{k=1}^{N} P_{ik}P_{kj} \\ &= {(P^2)}_{ij}, \end{aligned}

where the last step follows from the definition of matrix multiplication. It is straight forward but tedious to use Mathematical Induction to extend the previous result to the case of an arbitrary time difference, τ\tau, P(Xt+τ=xjXt=xi)=(Pτ)ij     (2). P(X_{t+\tau}=x_j|X_t=x_i) = {(P^{\tau})}_{ij}\ \ \ \ \ (2).

It should be noted that since (Pτ)ij{(P^{\tau})}_{ij} is a transition probability it must satisfy,

j=1N(Pτ)ij = 1(Pτ)ij  0     (3). \begin{gathered} \sum_{j=1}^{N} {(P^{\tau})}_{ij}\ =\ 1 \\ {(P^{\tau})}_{ij}\ \geq\ 0 \end{gathered} \ \ \ \ \ (3).

To determine the equilibrium solution of the distribution of states, {x1, x2,, xN}\{x_1,\ x_2,\ldots,\ x_N\}, the distribution time variability must be determined. Begin by considering an arbitrary distribution at t=0t=0, which can be written as a column vector, π=(π1π2πN)=(P(X0=x1)P(X0=x2)P(X0=xN)), \pi = \begin{pmatrix} \pi_1 \\ \pi_2 \\ \vdots \\ \pi_N \end{pmatrix} = \begin{pmatrix} P(X_0=x_1) \\ P(X_0=x_2) \\ \vdots \\ P(X_0=x_N) \end{pmatrix},

since it is a probability distribution πi\pi_i must satisfy, i=1Nπi = 1πi  0     (4). \begin{gathered} \sum_{i=1}^{N} \pi_i\ =\ 1\\ \pi_i\ \geq \ 0 \end{gathered} \ \ \ \ \ (4).

The distribution after the first step is given by, P(X1=xj)=i=1NP(X1=xjX0=xi)P(X0=xi)=i=1NPijπi=i=1NπiPij=(πTP)j, \begin{aligned} P(X_1=x_j) &= \sum_{i=1}^{N} P(X_1=x_j|X_0=x_i)P(X_0=x_i) \\ &= \sum_{i=1}^{N} P_{ij}\pi_{i} \\ &= \sum_{i=1}^{N} \pi_{i}P_{ij} \\ &= {(\pi^{T}P)}_{j}, \end{aligned}

where πT\pi^T is the transpose of π\pi. Similarly, the distribution after the second step is, P(X2=xj)=i=1NP(X2=xjX1=xi)P(X1=xi)=i=1NPij(πTP)i=i=1NPijk=1NπkPki=k=1Nπki=1NPijPki=k=1Nπki=1NPkiPij=k=1Nπk(P2)kj=(πTP2)j, \begin{aligned} P(X_2=x_j) &= \sum_{i=1}^{N} P(X_2=x_j|X_1=x_i)P(X_1=x_i) \\ &= \sum_{i=1}^{N} P_{ij}{(\pi^{T}P)}_{i} \\ &= \sum_{i=1}^{N} P_{ij}\sum_{k=1}^{N} \pi_{k}P_{ki} \\ &= \sum_{k=1}^{N} \pi_{k} \sum_{i=1}^{N} P_{ij}P_{ki} \\ &= \sum_{k=1}^{N} \pi_{k} \sum_{i=1}^{N} P_{ki}P_{ij} \\ &= \sum_{k=1}^{N} \pi_{k} {(P^2)}_{kj} \\ &= {(\pi^{T}P^2)}_{j}, \end{aligned}

A pattern is clearly developing. Mathematical Induction can be used to prove the distribution at an arbitrary time tt is given by, P(Xt=xj)=(πTPt)j P(X_t=x_j) = {(\pi^{T}P^t)}_{j}

or as a column vector,

πtT=πTPt     (5). \pi_{t}^{T} = \pi^{T}P^t\ \ \ \ \ (5).

Where π\pi and πt\pi_t are the initial distribution and the distribution after tt steps respectively.

Equilibrium Transition Matrix

The probability of transitioning between two states xix_i and xjx_j in tt time steps was previously shown to be stochastic matrix PtP^t constrained by equation (3)(3). The equilibrium transition matrix is defined by, PE=limtPt. P^{E} = \lim_{t\to\infty}P^{t}. This limit can be determined using Matrix Diagonalization. The following sections will use diagonalization to construct a form of PtP^{t} that will easily allow evaluation equilibrium limit.

Eigenvectors and Eigenvalues of the Transition Matrix

Matrix Diagonalization requires evaluation of eigenvalues and eigenvectors, which are defined by the solutions to the equation, Pv=λv     (6), Pv = \lambda v\ \ \ \ \ (6), where vv is the eigenvector and λ\lambda eigenvalue. From equation (6)(6) it follows, Ptv=Pt1(Pv)=Pt1λv=Pt2(Pv)λ=Pt2λ2v=(Pv)λt1=λtv. \begin{aligned} P^{t}v &= P^{t-1}(Pv)\\ &=P^{t-1}\lambda v\\ &=P^{t-2}(Pv)\lambda\\ &=P^{t-2}\lambda^{2}v \\ &\vdots\\ &=(Pv)\lambda^{t-1}\\ &=\lambda^{t}v. \end{aligned}

Since PtP^t is a stochastic matrix it satisfies equation (3)(3). As a result of these constraints the limit tt\to\infty requires, limtPt=limtλtv  . \lim_{t\to\infty}P^{t}=\lim_{t\to\infty}\lambda^{t}v\ \leq\ \infty.

It follows that λ  1\lambda\ \leq\ 1 . Next, it will be shown that λ1=1\lambda_1=1 and that a column vector of 1s1's with NN rows, V1=(111)     (7), V_1 = \begin{pmatrix} 1 \\ 1 \\ \vdots \\ 1 \end{pmatrix}\ \ \ \ \ (7), are eigenvalue and eigenvector solutions of equation (6)(6), (P11P12P1NP21P22P2NPN1PN2PNN)(111)=(j=1NP1jj=1NP2jj=1NPNj)=(111)=λ1V1, \begin{pmatrix} P_{11} & P_{12} & \cdots & P_{1N} \\ P_{21} & P_{22} & \cdots & P_{2N} \\ \vdots & \vdots & \ddots & \vdots \\ P_{N1} & P_{N2} & \cdots & P_{NN} \end{pmatrix} \begin{pmatrix} 1 \\ 1 \\ \vdots \\ 1 \end{pmatrix} = \begin{pmatrix} \sum_{j=1}^{N}P_{1j} \\ \sum_{j=1}^{N}P_{2j} \\ \vdots \\ \sum_{j=1}^{N}P_{Nj} \end{pmatrix} = \begin{pmatrix} 1 \\ 1 \\ \vdots \\ 1 \end{pmatrix} =\lambda_1 V_1,

where use was made of the stochastic matrix condition from equation (1)(1), namely, j=1NPij=1\sum_{j=1}^{N}P_{ij}=1.

To go further a result from the Perron-Frobenius Theorem is needed. This theorem states that a stochastic matrix will have a largest eigenvalue with multiplicity 1. Here all eigenvalues will satisfy λ1=1 > λi,  1 < i  N\lambda_1=1 \ >\ \mid{\lambda_i}\mid,\ \forall\ 1\ <\ i\ \leq\ N.

Denote the eigenvector VjV_j by the column vector, Vj=(v1jv2jvNj), V_j = \begin{pmatrix} v_{1j} \\ v_{2j} \\ \vdots \\ v_{Nj} \end{pmatrix},

and let VV be the matrix with columns that are the eigenvectors of PP with V1V_1 from equation (7)(7) in the first column, V=(1v12v1N1v22v2N1vN2vNN). V= \begin{pmatrix} 1 & v_{12} & \cdots & v_{1N} \\ 1 & v_{22} & \cdots & v_{2N} \\ \vdots & \vdots & \ddots & \vdots \\ 1 & v_{N2} & \cdots & v_{NN} \end{pmatrix}.

Assume that VV is invertible and denote the inverse by,

V1=(v111v121v1N1v211v221v2N1vN11vN21vNN1)     (8). V^{-1}= \begin{pmatrix} v^{-1}_{11} & v^{-1}_{12} & \cdots & v^{-1}_{1N} \\ v^{-1}_{21} & v^{-1}_{22} & \cdots & v^{-1}_{2N} \\ \vdots & \vdots & \ddots & \vdots \\ v^{-1}_{N1} & v^{-1}_{N2} & \cdots & v^{-1}_{NN} \end{pmatrix}\ \ \ \ \ (8).

If the identity matrix is represented by II then VV1=IVV^{-1} = I. Let Λ\Lambda be a diagonal matrix constructed from the eigenvalues of PP using λ1=1\lambda_1=1,

Λ=(1000λ2000λN). \Lambda = \begin{pmatrix} 1 & 0 & \cdots & 0 \\ 0 & \lambda_2 & \cdots & 0 \\ \vdots & \vdots & \ddots & \vdots \\ 0 & 0 & \cdots & \lambda_N \end{pmatrix}.

Sufficient information about the eigenvalues and eigenvectors has been obtained to prove some very general results for Markov Chains. The following section will work through the equilibrium limit using the using these results to construct a diagonalized representation of the matrix.

Diagonalization of Transition Matrix

Using the results obtained in the previous section the diagonalized form of the transition matrix is given by,

P=VΛV1, P = V\Lambda V^{-1},

Using this representation of PP an expression for PtP^t is obtained, Pt=Pt1VΛV1=Pt2VΛV1VΛV1=Pt2VΛ2V1=PVΛt1V1=VΛtV1 \begin{aligned} P^{t} &= P^{t-1}V\Lambda V^{-1} \\ &= P^{t-2}V\Lambda V^{-1}V\Lambda V^{-1} \\ &= P^{t-2}V\Lambda^2 V^{-1}\\ &\vdots \\ &= PV\Lambda^{t-1} V^{-1} \\ &= V\Lambda^{t}V^{-1} \end{aligned}

Evaluation of Λt\Lambda^{t} is straight forward,

Λt=(1000λ2t000λNt). \Lambda^t = \begin{pmatrix} 1 & 0 & \cdots & 0 \\ 0 & \lambda_2^t & \cdots & 0 \\ \vdots & \vdots & \ddots & \vdots \\ 0 & 0 & \cdots & \lambda_N^t \end{pmatrix}.

Since λi < 1,  1 < i  N\mid{\lambda_i}\mid\ <\ 1,\ \forall\ 1\ <\ i\ \leq\ N in the limit tt\to\infty it is seen that, ΛE=limtΛt=limt(1000λ2t000λNt)=(100000000), \Lambda^{E} = \lim_{t\to\infty} \Lambda^t = \lim_{t\to\infty} \begin{pmatrix} 1 & 0 & \cdots & 0 \\ 0 & \lambda_2^t & \cdots & 0 \\ \vdots & \vdots & \ddots & \vdots \\ 0 & 0 & \cdots & \lambda_N^t \end{pmatrix} = \begin{pmatrix} 1 & 0 & \cdots & 0 \\ 0 & 0 & \cdots & 0 \\ \vdots & \vdots & \ddots & \vdots \\ 0 & 0 & \cdots & 0 \end{pmatrix},

so, PE=limtPt=limtVΛtV1=VΛEV1. P^{E} = \lim_{t\to\infty} P^{t} = \lim_{t\to\infty} V\Lambda^{t} V^{-1} = V\Lambda^{E}V^{-1}.

Evaluation of the first two terms on the righthand side gives,

VΛE=(1v12v1N1v22v2N1vN2vNN)(100000000)=(100100100). V\Lambda^{E} = \begin{pmatrix} 1 & v_{12} & \cdots & v_{1N} \\ 1 & v_{22} & \cdots & v_{2N} \\ \vdots & \vdots & \ddots & \vdots \\ 1 & v_{N2} & \cdots & v_{NN} \end{pmatrix} \begin{pmatrix} 1 & 0 & \cdots & 0 \\ 0 & 0 & \cdots & 0 \\ \vdots & \vdots & \ddots & \vdots \\ 0 & 0 & \cdots & 0 \end{pmatrix} = \begin{pmatrix} 1 & 0 & \cdots & 0 \\ 1 & 0 & \cdots & 0 \\ \vdots & \vdots & \ddots & \vdots \\ 1 & 0 & \cdots & 0 \end{pmatrix}.

It follows that, VΛEV1=(100100100)(v111v121v1N1v211v221v2N1vN11vN21vNN1)=(v111v121v1N1v111v121v1N1v111v121v1N1). V\Lambda^{E} V^{-1} = \begin{pmatrix} 1 & 0 & \cdots & 0 \\ 1 & 0 & \cdots & 0 \\ \vdots & \vdots & \ddots & \vdots \\ 1 & 0 & \cdots & 0 \end{pmatrix} \begin{pmatrix} v^{-1}_{11} & v^{-1}_{12} & \cdots & v^{-1}_{1N} \\ v^{-1}_{21} & v^{-1}_{22} & \cdots & v^{-1}_{2N} \\ \vdots & \vdots & \ddots & \vdots \\ v^{-1}_{N1} & v^{-1}_{N2} & \cdots & v^{-1}_{NN} \end{pmatrix} = \begin{pmatrix} v^{-1}_{11} & v^{-1}_{12} & \cdots & v^{-1}_{1N} \\ v^{-1}_{11} & v^{-1}_{12} & \cdots & v^{-1}_{1N} \\ \vdots & \vdots & \ddots & \vdots \\ v^{-1}_{11} & v^{-1}_{12} & \cdots & v^{-1}_{1N} \end{pmatrix}.

Finally, the equilibrium transition matrix is given by, PE=VΛEV1=(v111v121v1N1v111v121v1N1v111v121v1N1)     (9). P^{E} = V\Lambda^{E} V^{-1} = \begin{pmatrix} v^{-1}_{11} & v^{-1}_{12} & \cdots & v^{-1}_{1N} \\ v^{-1}_{11} & v^{-1}_{12} & \cdots & v^{-1}_{1N} \\ \vdots & \vdots & \ddots & \vdots \\ v^{-1}_{11} & v^{-1}_{12} & \cdots & v^{-1}_{1N} \end{pmatrix}\ \ \ \ \ (9).

The rows of PEP^{E} are identical and given by the first row of the inverse of the matrix of eigenvectors, V1V^{-1}, from equation (8)(8). This row is a consequence of the location of the λ=1\lambda=1 eigenvalue and eigenvector in Λ\Lambda and VV respectively. Since PEP^{E} is a transition matrix,

j=1Nvij1 = 1vij1  0. \begin{gathered} \sum_{j=1}^{N} v_{ij}^{-1}\ =\ 1\\ v_{ij}^{-1}\ \geq \ 0. \end{gathered}

Equilibrium Distribution

The equilibrium distribution is defined by a solution to equation (5)(5) that is independent of time.

πT=πTPt     (10). \pi^{T} = \pi^{T}P^t\ \ \ \ \ (10).

Consider a distribution πE\pi_{E} that satisfies, πET=πETP     (11). \pi_{E}^{T} = \pi_{E}^{T}P\ \ \ \ \ (11).

It is easy to show that πE\pi_{E} is an equilibrium solution by substituting it into equation (10)(10). πET=πETPt=(πETP)Pt1=πETPt1=πETPt2=πETP=πET. \begin{aligned} \pi_{E}^{T} &= \pi_{E}^{T}P^t \\ &= (\pi_{E}^{T}P)P^{t-1} \\ &= \pi_{E}^{T}P^{t-1} \\ &= \pi_{E}^{T}P^{t-2} \\ &\vdots \\ &= \pi_{E}^{T}P \\ &= \pi_{E}^{T}. \end{aligned}

Relationship Between Equilibrium Distribution and Transition Matrix

To determine the relationship between πE\pi_E and PEP^{E}, begin by considering an arbitrary initial distribution states with NN elements, π=(π1π2πN), \pi = \begin{pmatrix} \pi_{1} \\ \pi_{2} \\ \vdots \\ \pi_{N} \end{pmatrix},

where,

j=1Nπj=1πj  0. \begin{gathered} \sum_{j=1}^{N}\pi_{j} = 1\\ \pi_{j}\ \geq\ 0 \end{gathered}.

The distribution when the Markov Chain has had sufficient time to reach equilibrium will be given by, πTPE=(π1π2πN)(v111v121v1N1v111v121v1N1v111v121v1N1)=(v111j=1Nπjv121j=1Nπjv1N1j=1Nπj), \begin{aligned} \pi^{T}P^{E} &= \begin{pmatrix} \pi_{1} & \pi_{2} & \cdots & \pi_{N} \end{pmatrix} \begin{pmatrix} v^{-1}_{11} & v^{-1}_{12} & \cdots & v^{-1}_{1N} \\ v^{-1}_{11} & v^{-1}_{12} & \cdots & v^{-1}_{1N} \\ \vdots & \vdots & \ddots & \vdots \\ v^{-1}_{11} & v^{-1}_{12} & \cdots & v^{-1}_{1N} \end{pmatrix} \\ &= \begin{pmatrix} v^{-1}_{11}\sum_{j=1}^{N} \pi_{j} & v^{-1}_{12}\sum_{j=1}^{N} \pi_{j} & \cdots & v^{-1}_{1N}\sum_{j=1}^{N} \pi_{j} \end{pmatrix}, \end{aligned}

since, j=1Nπj=1\sum_{j=1}^{N} \pi_{j} = 1,

πTPE=(v111v121v1N1). \pi^{T}P^{E} = \begin{pmatrix} v^{-1}_{11} & v^{-1}_{12} & \cdots & v^{-1}_{1N} \end{pmatrix}.

Thus any initial distribution π\pi will after sufficient time approach the distribution above. It follows that it will be the solution of equation (11)(11) which defines the equilibrium distribution,

πE=(v111v121v1N1). \pi_E = \begin{pmatrix} v^{-1}_{11} \\ v^{-1}_{12} \\ \vdots \\ v^{-1}_{1N} \end{pmatrix}.

Solution of Equilibrium Equation

An equation for the equilibrium distribution, πE\pi_{E}, can be obtained from equation (11)(11), πET(PI)=0     (12), \pi^{T}_E\left(P - I\right) = 0\ \ \ \ \ (12), where II is the identity matrix. Equation (12)(12) alone is insufficient to obtain a unique solution since the system of linear equations it defines is Linearly Dependent. In a linearly dependent system of equations some equations are the result of linear operations on the others. It is straight forward to show that one of the equations defined by (12)(12) can be eliminated by summing the other equations and multiplying by 1-1. If the equations were linearly independent the only solution would be the trivial zero solution, (πET)i = 0,  i{\left( \pi^{T}_E \right)}_{i}\ =\ 0,\ \forall\ i. A unique solution to (12)(12) is obtained by including the normalization constraint, j=1N(πET)j=1. \sum_{j=1}^{N} {\left( \pi_{E}^{T} \right)}_{j} = 1. The resulting system of equations to be solved is given by, πET(P111P12P1N1P21P221P2N1PN1PN2PNN11)=(00001)     (13). \pi_{E}^{T} \begin{pmatrix} {P_{11} - 1} & P_{12} & \cdots & P_{1N} & 1 \\ P_{21} & {P_{22} -1} & \cdots & P_{2N} & 1 \\ \vdots & \vdots & \ddots & \vdots & \vdots\\ P_{N1} & P_{N2} & \cdots & {P_{NN} - 1} & 1 \\ \end{pmatrix} = \begin{pmatrix} 0 & 0 & 0 & 0 & 1 \end{pmatrix}\ \ \ \ \ (13).

Example

Consider the Markov Chain defined by the transition matrix, P=(0.00.90.10.00.80.10.00.10.00.50.30.20.10.00.00.9)     (14). P = \begin{pmatrix} 0.0 & 0.9 & 0.1 & 0.0 \\ 0.8 & 0.1 & 0.0 & 0.1 \\ 0.0 & 0.5 & 0.3 & 0.2 \\ 0.1 & 0.0 & 0.0 & 0.9 \end{pmatrix}\ \ \ \ \ (14). The state transition diagram below provides a graphical representation of PP.

Convergence to Equilibrium

Relaxation of both the transition matrix and distribution to their equilibrium values is easily demonstrated with the few lines of Python executed within ipython.

In [1]: import numpy
In [2]: t = [[0.0, 0.9, 0.1, 0.0],
   ...:      [0.8, 0.1, 0.0, 0.1],
   ...:      [0.0, 0.5, 0.3, 0.2],
   ...:      [0.1, 0.0, 0.0, 0.9]]
In [3]: p = numpy.matrix(t)
In [4]: p**100
Out[4]:
matrix([[0.27876106, 0.30088496, 0.03982301, 0.38053097],
        [0.27876106, 0.30088496, 0.03982301, 0.38053097],
        [0.27876106, 0.30088496, 0.03982301, 0.38053097],
        [0.27876106, 0.30088495, 0.03982301, 0.38053098]])

Here the transition matrix from the initial state to states 100100 time steps in the future is computed using equation (2)(2). The result obtained has identical rows as obtained in equation (9)(9). P100=(0.278761060.300884960.039823010.380530970.278761060.300884960.039823010.380530970.278761060.300884960.039823010.380530970.278761060.300884950.039823010.38053098)     (15). P^{100} = \begin{pmatrix} 0.27876106 & 0.30088496 & 0.03982301 & 0.38053097 \\ 0.27876106 & 0.30088496 & 0.03982301 & 0.38053097 \\ 0.27876106 & 0.30088496 & 0.03982301 & 0.38053097 \\ 0.27876106 & 0.30088495 & 0.03982301 & 0.38053098 \end{pmatrix}\ \ \ \ \ (15).

For an initial distribution π\pi the distribution after 100100 time steps is evaluated using,

In [5]: c = [[0.1],
   ...:      [0.5],
   ...:      [0.35],
   ...:      [0.05]]
In [6]: π = numpy.matrix(c)
In [8]: π.T*p**100
Out[8]: matrix([[0.27876106, 0.30088496, 0.03982301, 0.38053097]])

Here an initial distribution is constructed that satisfies i=03πi=1\sum_{i=0}^3 \pi_i = 1. Then equation (5)(5) is used to compute the distribution after 100100 time steps. The result is that expected from the previous analysis. In the equilibrium limit the distribution is the repeated row of the equilibrium transition matrix, namely,

π100=(0.278761060.300884960.039823010.38053097)     (16). \pi_{100} = \begin{pmatrix} 0.27876106 \\ 0.30088496 \\ 0.03982301 \\ 0.38053097 \end{pmatrix}\ \ \ \ \ (16).

The plot below illustrates the convergence of the distribution from the previous example. In the plot the components of πt\pi_t from equation (5)(5) are plotted for each time step. The convergence to the limiting value occurs rapidly. Within only 2020 steps πt\pi_t has reached limiting distribution.

Equilibrium Transition Matrix

In this section the equilibrium limit of the transition matrix is determined for the example Markov Chain shown in equation (14)(14). It was previously shown that this limit is given by equation (9)(9). To evaluate this equation the example transition matrix must be diagonalized. First, the transition matrix eigenvalues and eigenvectors are computed using the numpy linear algebra library.

In [9]: λ, v = numpy.linalg.eig(p)
In [10]: λ
Out[10]: array([-0.77413013,  0.24223905,  1.        ,  0.83189108])
In [11]: v
Out[11]:
matrix([[-0.70411894,  0.02102317,  0.5       , -0.4978592 ],
        [ 0.63959501,  0.11599428,  0.5       , -0.44431454],
        [-0.30555819, -0.99302222,  0.5       , -0.14281543],
        [ 0.04205879, -0.00319617,  0.5       ,  0.73097508]])

It is seen that λ = 1\lambda\ =\ 1 is indeed an eigenvalue, as previously proven and that other eigenvalues have magnitudes less than 11. This is in agreement with Perron-Frobenius Theorem. The numpy linear algebra library normalizes the eigenvectors and uses the same order for eigenvalues and eigenvector columns. The eigenvector corresponding to λ = 1\lambda\ =\ 1 is in the third column and has all components equal. Eigenvectors are only known to an arbitrary scalar, so the vector of 1s1's used in the previous analysis can be obtained by multiplying the third column by 22. After obtaining the eigenvalues and eigenvectors equation (9)(9) is evaluated 100100 after time steps and compared with the equilibrium limit.

In [12]: Λ = numpy.diag(λ)
In [13]: V = numpy.matrix(v)
In [14]: Vinv = numpy.linalg.inv(V)
In [15]: Λ_t = Λ**100
In [16]: Λ_t
Out[16]:
array([[7.61022278e-12, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00],
       [0.00000000e+00, 2.65714622e-62, 0.00000000e+00, 0.00000000e+00],
       [0.00000000e+00, 0.00000000e+00, 1.00000000e+00, 0.00000000e+00],
       [0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 1.01542303e-08]])
In [17]: V * Λ_t * Vinv
Out[17]:
matrix([[0.27876106, 0.30088496, 0.03982301, 0.38053097],
        [0.27876106, 0.30088496, 0.03982301, 0.38053097],
        [0.27876106, 0.30088496, 0.03982301, 0.38053097],
        [0.27876106, 0.30088495, 0.03982301, 0.38053098]])

First, the diagonal matrix of eigenvalues, Λ\Lambda, is created maintaining the order of λ\lambda. Next, the matrix VV is constructed with eigenvectors as columns while also maintaining the order of vectors in vv. The inverse of VV is then computed. Λt\Lambda^{t} can now be computed for 100100 time steps. The result is in agreement with the past effort where the limit tt\to\infty was evaluated giving a matrix that contained a 11 in the (1,1)(1,1) component corresponding to the position of the λ=1\lambda=1 component and zeros for all others. Here the eigenvectors are ordered differently but the only nonzero component has the λ=1\lambda=1 eigenvalue. Finally, equation (9)(9) is evaluated and all rows are identical and equal to πt\pi_t evaluated at t=100t=100, in agreement with the equilibrium limit determined previously and calculations performed in the last section shown in equations (15)(15) and (16)(16).

Equilibrium Distribution

The equilibrium distribution will now be calculated using the system of linear equations defined by equation (9)(9). Below the resulting system of equations for the example distribution in equation (14)(14) is shown.

πET(1.00.90.10.01.00.80.90.00.11.00.00.50.70.21.00.10.00.00.11.0)=(0.00.00.00.01.0) \pi_{E}^{T} \begin{pmatrix} -1.0 & 0.9 & 0.1 & 0.0 & 1.0 \\ 0.8 & -0.9 & 0.0 & 0.1 & 1.0 \\ 0.0 & 0.5 & -0.7 & 0.2 & 1.0 \\ 0.1 & 0.0 & 0.0 & -0.1 & 1.0 \end{pmatrix} = \begin{pmatrix} 0.0 & 0.0 & 0.0 & 0.0 & 1.0 \end{pmatrix}

This system of equations is solved using the least squares method provided by the numpy linear algebra library, which requires the use of the transpose of the above equation. The first line below computes it using equation (14)(14).

In [18]: E = numpy.concatenate((p.T - numpy.eye(4), [numpy.ones(4)]))
In [19]: E
Out[19]:
matrix([[-1. ,  0.8,  0. ,  0.1],
        [ 0.9, -0.9,  0.5,  0. ],
        [ 0.1,  0. , -0.7,  0. ],
        [ 0. ,  0.1,  0.2, -0.1],
        [ 1. ,  1. ,  1. ,  1. ]])
In [20]: πe, _, _, _ = numpy.linalg.lstsq(E, numpy.array([0.0, 0.0, 0.0, 0.0, 1.0]), rcond=None)

In [21]: πe
Out[21]: array([0.27876106, 0.30088496, 0.03982301, 0.38053097])

Next, the equilibrium distribution is evaluated using the least squares method. The result obtained is consistent with previous results shown in equation (16)(16).

Simulation

This section will use a direct simulation of equation (14)(14) to calculate the equilibrium distribution and compare the result to those previously obtained. Below a Python implementation of the calculation is shown.

import numpy

def sample_chain(t, x0, nsample):
    xt = numpy.zeros(nsample, dtype=int)
    xt[0] = x0
    up = numpy.random.rand(nsample)
    cdf = [numpy.cumsum(t[i]) for i in range(4)]
    for t in range(nsample - 1):
        xt[t] = numpy.flatnonzero(cdf[xt[t-1]] >= up[t])[0]
    return xt

# Simulation parameters
π_nsamples = 1000
nsamples = 10000
c = [[0.25],
     [0.25],
     [0.25],
     [0.25]]

# Generate π_nsamples initial state samples
π = numpy.matrix(c)
π_cdf = numpy.cumsum(c)
π_samples = [numpy.flatnonzero(π_cdf >= u)[0] for u in numpy.random.rand(π_nsamples)]

# Run sample_chain for nsamples for each of the initial state samples
chain_samples = numpy.array([])
for x0 in π_samples:
  chain_samples = numpy.append(chain_samples, sample_chain(t, x0, nsamples))

The function sample_chain performs the simulation and uses Inverse CDF Sampling on the discrete distribution obtained from the transition matrix defined by equation (14)(14). The transition matrix determines state at step t+1t+1 from the state at step tt. The following code uses sample_chain to generate and ensemble of simulations with the initial state also sampled from an assumed initial distribution. First, simulation parameters are defined and the initial distribution is assumed to be uniform. Second, π_nsamples of the initial state are generated using Inverse CDF sampling with the initial distribution. Finally, simulations of length nsamples are performed for each initial state. The ensemble of samples are collected in the variable chain_samples and plotted below. A comparison is made with the two other calculations performed. The first is πt\pi_t for t=100t=100 shown in equation (16)(16) and the second the solution to equation (9)(9). The different calculations are indistinguishable.

Conclusions

Markov Chain equilibrium for discrete state processes is a general theory of the time evolution of transition probabilities and state distributions. It has been shown that equilibrium is a consequence of assuming the transition matrix and distribution vector are both stochastic. Expressions were derived for the time evolution of any transition matrix and distribution and the equilibrium solutions were then obtained analytically by evaluating the limit tt\to\infty. A calculation was performed using the obtained equations for the equilibrium solutions and the numpy linear algebra libraries using an example transition matrix. These results were compared to ensemble simulations. The time to relax from an arbitrary state to the equilibrium distributions was shown to occur within O(10)O(10) time steps.