我不确定 Jacobi 方法是否适用于马尔可夫转移矩阵。不过,还有其他更简单的技术可以找到平稳分布。首先通过求解您所描述的方程组:
import numpy as np
>>> M = np.array([[0.084, 0.1008, 0.168, 0.224, 0.224, 0.1494, 0.0498],
[0.084, 0.1008, 0.168, 0.224, 0.224, 0.1494, 0.0498],
[0.084, 0.1008, 0.168, 0.224, 0.224, 0.1494, 0.0498],
[0.5768, 0.224, 0.1494, 0.0498, 0.0, 0.0, 0.0],
[0.3528, 0.224, 0.224, 0.1494, 0.0498, 0.0, 0.0],
[0.1848, 0.168, 0.224, 0.224, 0.1494, 0.0498, 0.0],
[0.084, 0.1008, 0.168, 0.224, 0.224, 0.1494, 0.0498]])
>>>
>>> I = np.eye(len(M)) # identity matrix
>>>
>>> A = M.T - I # rearrange each "equation" in the system
>>>
>>> A = np.vstack([A, np.ones((1, len(A)))]) # add row of ones
>>>
>>> b = np.zeros(len(A)) # prepare solution vector
>>> b[-1] = 1.0 # add a one to the last entry
>>>
>>> np.linalg.solve(A.T @ A, A.T @ b) # solve the normal equation
array([0.22288974, 0.14776044, 0.1781388 , 0.181211 , 0.1504296 ,
0.09080838, 0.02876204])
您也可以反复乘以M
自身,直到它收敛:
>>> np.linalg.matrix_power(M, 25)[0]
array([0.22288974, 0.14776044, 0.1781388 , 0.181211 , 0.1504296 ,
0.09080838, 0.02876204])