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

旧巷老猫 提交于 2019-12-04 10:10:48

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])

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

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