Markov Chain

Markov Processes

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

不管是 discrete(

X(t),t=0,1,2,) or continuous parameter time(
X(t),t>0
) 的 Stochastic Process,只要滿足以下式子,即可稱為一個 Markov Process:

P(X(tn)xn|X(t1)=x1,...,X(tn1)=xn1)=P(X(tn)xn|X(tn1)=xn1)

a Stochastic Process is best defined as a family of random variables,

{X(t),tT}, defined over some index set or parameter space
T
. The set
T
is sometimes also called the time range, and
X(t)
denotes the state of the process at time t.

在日後的課程中我們會學到 Birth-Death Processes,而 Birth-Death Process 即具有 Markovian property,也就是滿足上式的定義。

而這個學期我們會學到的大部分 Queue 都是以 Birth-Death Process 為基礎,故在 Queueing Theory 中,我們可以使用 discrete-time Markov Chain 或者 continuous-time Markov Process 來分析 各種 Queue 的 long term behavior。

Long-tern Behavior of Markov Chain

定義名詞

以下說明不會著重在詳細數學證明,而是僅在邏輯層面上做整理,釐清各個 distribution (長期來說)的關係。

對 Markov Chian 來說,觀察 long-term behavior 有三種,第一是 stationary distribution,第二是 limiting distribution,第三是 ergodicity。

首先定義 Communicating Classes,我們說 state i & j communicate 代表雙方都一定可以經過 state transition 到達對方的 state,而若整個 Markov Chain 的 state 都互相 communicate,我們說這個 Markov Chain 是 irreducible

接著定義 Recurrence & Transience,Recurrence & Transience 代表一個 state 回到自己的可能性。定義如下:

let

fjj=n=1fjjn, where
fjjn
代表從 state j 開始經過 n 個 transitions 回到 state j 的機率。若
fjj=1
,我們說 j 是 recurrent state,若
jjj<1
,我們說 j 是 transient state

transient 簡單來說就是對 state j 而言,長期來說,從 state j 跑去別的 state 然後不回來是必然,Markov Chain 在跑的過程中經過 state j 的次數的期望值會是 finite。

反之 recurrent 代表長久來看是一定會回來的,經過 state j 的次數的期望值會是 infinite。

當 state i 的

fjj=1(recurrent state),即可定義
mjj=n=1nfjjn
mjj
代表state j 回到自己的平均 transitions 數,也稱為 mean recurrence time。

mjj<,我們說state j 為 positive recurrent,也就是我們會在一定數量的 transitions 內回到自己。若
mjj=
,我們說 state j 為 null recurrent,代表有機率回到自己這個 state,但是不知道需要多久。

而 period 為從state j 開始回到自己的 transition 數(可能有很多個)的最大公因數(GCD),若為1 稱為 aperiodic,反之稱為 periodic

我們說一組互相 communicate 的 state 為一個 Communicating Class,若這個Communicating Class 中的 state 都無法到達任何外界的 state(也就是說繞來繞去都在這個 Communicating Class 中),稱為 closed Communicating Class,反之稱為 open

若將這個 closed 概念類比到一個 state,則稱這個state 為 absorbing state,代表一旦 Markov Chain 進入這個state,就無法再出來了。(從 state diagram 來看,一個簡單的例子就是只有一個單向箭頭進入的 node)

一個 Markov Chain 可能會具有多個 Communicating Class,每個 class 中的 state 都互相communicate,但是不和其他 class communicate,而同一個 Communicating Class 當中的 state 以下幾項性質都會相同: period, transient / null recurrent / positive recurrent

因為同個 Communicating Class 中的 state 會有相同性質,所以我們藉由觀察其中一個 state,看這個 state 是否為 positive recurrent 還是 null recurrent 或 transient,就知道整個 Communicating Class 具有怎樣的性質。

Stationary Distribution

當一個 Communicating Class 是 positive recurrent,就有 unique 的 stationary probability distribution:

π=(π1,π2,π3,...,πn)=(1μ1,1μ2,...,1μn)

其中

μi 為 state i 的 expected return time。

若整個 Markov Chain 為 irreuducible,代表只有一個 Communicating Class,也就是說這個 Markov Chain具有唯一解的 Stationary Distribution。

若 Communicating Class 為 null recurrent 或者 transient,則沒有 stationary distribution。

我們說一個 process 是 stationary 代表 independent of time,但是若將 initial state(Markov Chain 的起始點)對 long-term behavior 的影響考慮進來,就是以下要介紹的limiting distribution。

補充:

下面定理可以幫助我們在已知為 irreducible, aperiodic 時判斷一個 Markov Chain 是否為 positive recurrent:

若一個 Markov Chain 為 irreducible, aperiodic,若存在一個 nonnegative solution 滿足

j=0pijxjxi1(i0) such that
j=0P0jxj<
,則這個 Markov Chain 為 positive recurrent。

Limiting Distribution

當一個 Communicating Class 為 positive recurrentaperiodic,我們說 limiting distribution exists,且會和 stationary distribution 相等。

代表 initial state 的影響 in the long run 來看已不存在,顯示了 lack of memory 的性質。

將沒有影響這件事寫成數學式:

limmPijm=πj,代表 in the long run,此 process 會在 state j 的機率,這個機率和 starting state i 沒有關係。矩陣
P
可寫成如下:

P=[π0π1π2πnπ0π1π2πnπ0π1π2πn]

where

πj=1μj

若為 null recurrent 或 transient,則

limmPijm=0

若一個 Markov Chain 有多個 Communicating Class,

P 的每個橫軸(index
i
)就對應state
i
所在的Communicating Class 的 limiting distribution。

Ergodicity

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Limiting distribution 觀察的是 state 在很久以後的一個時間點 n 的表現,而 Ergodicity 觀察的是在一段很長的時間裡面,state 的平均表現怎麼樣。

我們說一個 process 具有 Ergodicity ,代表對於所有 moment,都具有 Time Average = Ensemble Average 這個性質,也就是

0T(X0(t))nTdt=E[X(t)n], for all n

代表這個 process 的 moments are independent of time(但是不一定和 initial state 無關)。也代表 process 的 moments 都有極限(finite)。

當具有 ergodicity ,就具有以下性質,定義

Vj(n)= total number of visits to state j up to time n,給定一個 irreducible 的 Markov Chain:

若為 positive recurrent & irreducible 則

Vj(n)n=1μj(almost surely)

若為 null recurrent 或者 transient 則

Vj(n)n=0 (almost surely)

總結

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

當一個 Markov Chain 是 irreduciblepositive recurrent 時就會有 stationary distribution,如果今天再加上 all moments are finite 這個條件,就會是 ergodic,如果再加上是 aperiodic 就會具有 limiting distribution。

所以說,stationary, ergodic, limiting distribution 這三個條件的強度(需要的條件數量)為:limiting distribution > ergodic > stationary。

我們可以根據上述的定理以及性質,判斷 Markov Chain 具有哪些性質(irreducible / positive recurrent, ),即可知道 Limiting Distribution / stationary distribution 等等存不存在,接著即可用

π=πP,πQ=0,πe=1 來求解(看是 discrete / continuous)。

在本課程中探討的 Markovian Queue 幾乎都會是有解的(要不然你們就沒辦法算

L,W,...,考試就不用考了),不過了解上述分析,對於日後若研究有要用到 Markovian Queue 相關分析時會有幫助。

Discrete-time Markov Chain

若說

{Xn}若滿足:

P(X(tn)=xn|X(t1)=x1,...,X(tn1)=xn1)=P(X(tn)=xn|X(tn1)=xn1)

我們稱之為一個 discrete Markov Chain,

X(ti)=k 為此 Markov Chain 在
t=i
時的 state(
k
)。

pij 為從 state
i
跳到 state
j
的機率(transition probability):

pij=Pr(Xn+1=j|Xn=i)

假設一個 Markov Chain 的 state space

S={1,2,,n},將所有 transition probability 結合起來可以寫成一個矩陣
P
(transition probability matrix):

P=[p11p12p13p1np21p22p23p2npn1pn2pn3pnn]

Pm 即代表此 Markov Chain 做
m
次 transition 的 probability matrix,其中
pijm
代表經過
m
step 後從 state
i
跳到 state
j
的機率:

pijm=P(Xn+m=j|Xn=i)=rpirmkprjk, for 0<k<m

Markov Chain 的 state 會隨著時間而變化,而長期來說,如果這個 Markov Chain long-term behavior 是穩定的,我們就可以求出其 steady state probability,也就是説讓這個 Markov Chain 跑一段時間後,我們對其經過的 state 的歷史進行觀察,可以看出其處於各個不同的 state 的機率分別是多少。

我們稱「處於各個不同的 state 的機率」為 Markov Chain 的 steady state probability。

令 steady state probability

π=(π1,π2,,πn),代表 Markov Chain 長期來說在 state
1
, state
2
,以此類推,的機率。

π 可由以下公式解聯立方程式求出:

{πP=ππe=1

where

e=(1,1,,1),其中第一式的意義為:steady state 的機率是穩定的,就算再多經過一次 transition 也不會改變。第二式的意義為機率合為
1

Continuous-time Markov Chain

在 Continuous-time Markov Process中,系統處於每一個 state 的時間都是一個 exponential random variable。

和 Discrete-time Markov Chain 類似,假設 state space

S=(1,2,3,,n),我們定義 transition matrix
Q
,我們稱
Q
為 generator matix:

Q=[q11q12q13q1nq21q22q23q2nqn1qn2qn3qnn]

其中

qijΔt 為此 Markov Process(Chain) 在
(t,t+Δt)
內從 state
i
跳到 state
j
的機率。

qii=qi=jiqij,代表
Q
matrix 的每一個 row 的 sum 都是
0
。關於
qii
的意義請見下方連立方程式的說明。

給定一個 state transition diagram,寫出

Q 的步驟就是先把非對角線的
qij
通通填完,最後利用 row sum
=0
將對角線填上。

令 steady state probability matrix

P=(p1,p2,,pn)
e=(1,1,1,,1)
,可由下式求出 steady state probability:

{PQ=0Pe=1

其中第一式代表的意義為:對於任一一個 state

i 而言,從自己跳出去到別的 state
ji
的機率的總和,會和其他人跳進來的機率總和相等(系統達到穩定、平衡的狀態),至於為何會相等,可以直觀來解釋:因為若不相等,跳進來的不等於跳出去的,那麼 state probability 就還會變動。

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

將跳出去等於跳進來這件事寫成數學式:

pi(qii)=pijiqij=jipjqji

其中

jiqij=qii 可解釋為何
Q
matrix 要如此定義(row sum = 0)。

Embedded Markov Chain

image source

若 Continuous-time Markov Chain 觀察的角度是錄影,那麼 Embedded Markov Chain 就是在照相(只是照很多張而已)。

If we observe the system state right after a state transition in continuous-time Markov Chain. Let

Xn be the
n
-th observed state, then
{Xn,n=1,2,3,}
is called embedded Markov Chain(a discrete-time Markov Chain).

在一個 continuous-parameter 的 Markov Chain 中,只觀察系統 state 變化的時刻(就是在照相),觀察的結果為一個 discrete-parameter 的 Markov Chain,我們稱之為 Embedded Markov Chain。

而我們在照相完之後,會有很多照片,分析這些照片代表的意義,就可以定義 transition probability

pij

pij 代表的意義為,從 state i 要跳到 state j 的機率,可寫成

qijkiqik

也就是從state i 跳到 j 的機率除以所有從 state i 出去(到除了 state j 以外的 state)的機率的總和。(這裡的

qij 和 continuous-time Markov Chain 裡的是一樣的定義)

每個 state 的 holding time 會是一個 exponential r.v.,其期望值(mean holding time)為

1kiqik=1qi

Birth-Death Processes 為例,其

pij 可表示成

pij={λiλi+μi, if j=i+1μiλi+μi, if j=i11, if i=0,j=10, else,

將所有

pij 綜合起來寫成矩陣
P
,即可用聯立方程式求解 steady state probability
π=(π1,π2,...,πn)

{πP=ππe=1

where

e=(1,1,...,1)

若一個 coninuous-time Markov Chain 的 Embedded Markov Chain 為 irreducible 且 positive recurrent,我們就說這個 continuous-time Markov Chain 也是 irreducible 且 positive recurrent。

至於要判斷是否具有 stationary solution, limiting distribution, ergodicity 的話,會需要知道是否為 aperiodic。

判斷 aperiodic 的方法為:判斷其 Embedded Markov Chain 的 mean holding time 是否為bounded,若是,就如同這個 Continuous-time Markov Chain 為 aperiodic 一樣。

Embedded Markov Chain & Continuous-time Markov Chain

在理解 Embedded Markov Chain & Continuous-time Markov Chain 各自的定義以及如何求解之後,我們來比較他們兩個之間的異同以及其關聯性。

Pi 是 Continuous-time Markov Chain 求出來的解,而
πi
是 Embedded Markov Chain 求出來的解,他們各自代表的意義如下:

πi : represents the ratio of visit state
i
among all state
Pi
: represents the time ratio that system stays at state
i
in a long term observation period.

Embedded Markov Chain 就像是在對系統進行拍照,而 Continuous-time Markov Chain就像是在對系統進行錄影,兩者所得出的結果

π,
P
的值理所當然會不一樣,因為觀察角度不同,至於要用哪個角度觀察,會因觀察的需求不同而定。

兩者之間的關係可以透過下式得到:

Pi=miπijmjπj

where

mi is the mean holding time at state i

因為

mi 代表是在 state
i
的平均停留時間,結合上面對於
πi
Pi
所代表的意義的說明,上式的意義就很直觀明瞭了(時間 x 比例 = 時間比例,time x ratio = time ratio

A Simple Example

Consider an

M/M/1/3 queue with arrival rate
λ
and service rate
μ
.

  1. Please write down the generator matrix

    Q for its continuous time Markov Chain, which represents its system size(the number of customers in the system). (4%)

    answer

    Q=(λλ00μ(λ+μ)λ00μ(λ+μ)λ00μμ)

  2. Please then solve its steady-state probability

    pn for
    n=0,1,2,3
    using the generator matrix obtained in 1. (6%)

    answer

    let

    P=(p0,p1,p2,p3),e=(1,1,1,1),ρ=λμ
    solve:

    {PQ=0Qe=1{p1=ρp0p2=ρ2p0p3=ρ3p0p0=(1+ρ+ρ2+ρ3)1

  3. Derive the embedded Markov chain of this

    M/M/1/3 queue and obtain its steady state probability
    πn
    for
    n=0,1,2,3
    . (6%)

    answer

    The transition matrix

    P=(0100μλ+μ0λλ+μ00μλ+μ0λλ+μ0010)

    let

    π=(π0,π1,π2,π3),e=(1,1,1,1),ρ=λμ
    solve:

    {πP=ππe=1{π0=μ22μ2+2λ2+2λμπ1=μ(λ+μ)2μ2+2λ2+2λμπ2=λ(λ+μ)2μ2+2λ2+2λμπ3=λ22μ2+2λ2+2λμ

  4. Please determine the mean holding time for state 0,1,2, and 3.(4%)

    answer

    let

    mi denote the mean holding time for state
    i
    .

    {m0=1λm1=1λ+μm2=1λ+μm3=1μ

  5. Use the results of

    πn in 3. and the mean holding time in 4. to derive the formula for the steady-state probability
    pn
    .(Hint: the results should be the same as in 2.)(6%)

    answer

    Use

    pi=miπii=04mjπj

    Compute

    p0=m0π0i=04mjπj=μ21λμ21λ+μ(λ+μ)1λ+μ+λ(λ+μ)1λ+μ+λ21μ=11+λμ+(λμ)2+(λμ)3=11+ρ+ρ2+ρ3

    then

    p1,p2,p3 可如法炮製,一場混戰之後會發現,結果和 2. 的結果相同。(NOTE: 同學在考試時不可以寫如法炮製,要實際算出來)

Reference