Left eigenvectors not giving correct (markov) stationary probability in scipy

流过昼夜 提交于 2019-12-06 06:16:02

问题


Given the following Markov Matrix:

import numpy, scipy.linalg
A = numpy.array([[0.9, 0.1],[0.15, 0.85]])

The stationary probability exists and is equal to [.6, .4]. This is easy to verify by taking a large power of the matrix:

B = A.copy()
for _ in xrange(10): B = numpy.dot(B,B)

Here B[0] = [0.6, 0.4]. So far, so good. According to wikipedia:

A stationary probability vector is defined as a vector that does not change under application of the transition matrix; that is, it is defined as a left eigenvector of the probability matrix, associated with eigenvalue 1:

So I should be able to calculate the left eigenvector of A with eigenvalue of 1, and this should also give me the stationary probability. Scipy's implementation of eig has a left keyword:

scipy.linalg.eig(A,left=True,right=False)

Gives:

(array([ 1.00+0.j,  0.75+0.j]), array([[ 0.83205029, -0.70710678],
   [ 0.5547002 ,  0.70710678]]))

Which says that the dominant left eigenvector is: [0.83205029, 0.5547002]. Am I reading this incorrectly? How do I get the [0.6, 0.4] using the eigenvalue decomposition?


回答1:


The [0.83205029, 0.5547002] is just [0.6, 0.4] multiplied by ~1.39.

Although from "physical" point of view you need eigenvector with sum of its components equal 1, scaling eigenvector by some factor does not change it's "eigenness":

If

, then obviously

So, to get [0.6, 0.4] you should do:

>>> v = scipy.linalg.eig(A,left=True,right=False)[1][:,0]
>>> v
array([ 0.83205029,  0.5547002 ])
>>> v / sum(v)
array([ 0.6,  0.4])



回答2:


the eig function returns unit vector as far as eigenvectors are concerned.

So, if we take v = [0.6, 0.4], its length is: l = np.sqrt(np.square(a).sum()) or l = np.linalg.norm(v), so the normalized vector (as returned from scipy.linalg.eig) is:

>>> v = np.array([.6, .4])
>>> l = np.sqrt(np.square(a).sum())
>>> v / l
array([0.83205029, 0.5547002 ])

So, if you need the vector to be a stochastic vector or probability vector as in Markov chain, simply scale it so it sums to 1.0



来源:https://stackoverflow.com/questions/10504158/left-eigenvectors-not-giving-correct-markov-stationary-probability-in-scipy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!