在 MATLAB 中使用大矩阵的特征向量获取马尔可夫链的平稳分布

Obtaining the stationary distribution for a Markov Chain using eigenvectors from large matrix in MATLAB

我正在尝试寻找马尔可夫链的平稳分布。我有一个转移概率矩阵 (TPM)。 这是代码:

[V, D] = eigs(double(TPM'),1); 
Py = abs(V)/sum(V);

我的问题是 sum(V) < 0 所以它在向量 Py 中给了我一些负值。我已经使用另一个概率矩阵测试了代码,它给出了 sum(V) > 0.

我不知道问题出在哪里,是 TPM 问题还是我使用的代码问题?

编辑:

这里有一个更"elaborated"版本的代码(包括"SecretAgentMan"的答案,见方法三):

function [Py1, Py2, Py3] = testStatDist(TPM)

% method 1
[V1, D1] = eigs(double(TPM'),1);

% method 2
[V2, D2] = iterator(TPM);

% method 3
V3 = null(eye(size(TPM))-TPM.'); 

if(abs(D1 - 1) > 1e-5)
    warning(0, 'testStatDist.m: Check Transition Matrix');
    exit;
end

if(abs(D2 - 1) > 1e-5)
    warning(0, 'testStatDist.m: Check Transition Matrix');
    exit;
end

% res 1
Py1 = abs(V1)/sum(V1);

% res 2
Py2 = abs(V2)/sum(V2);

% res 3
Py3 = abs(V3)/sum(V3);
end

这里是函数 "iterator":

function [V, D] = iterator(TPM)

pi(1:length(TPM)) = 1/length(TPM);
error = 1;
budget = 1000;
while(error >= 1e-10)
    pi2 = pi*TPM;
    error = sum((pi - pi2).^2);
    pi = pi2;
    budget = budget - 1;
    if(budget == 0)
        break;
    end
end
V = pi';
D = 1;

这是我正在使用的 TPM 之一:

TPM = [0.987665198237886    0.000220264317180617    0.000440528634361233    0.000660792951541850    0.0110132158590308  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0.000881057268722467    0.985682819383260   0.00110132158590308 0.00132158590308370 0   0.0110132158590308  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0.00154185022026432 0.00176211453744493 0.983700440528634   0.00198237885462555 0   0   0.0110132158590308  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0.988986784140969   0   0   0   0.0110132158590308  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0.00440528634361233 0   0   0   0.983259911894273   0.000220264317180617    0.000440528634361233    0.000660792951541850    0.0110132158590308  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0.00440528634361233 0   0   0.000881057268722467    0.981277533039648   0.00110132158590308 0.00132158590308370 0   0.0110132158590308  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0.00440528634361233 0   0.00154185022026432 0.00176211453744493 0.979295154185022   0.00198237885462555 0   0   0.0110132158590308  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0.00440528634361233 0   0   0   0.984581497797357   0   0   0   0.0110132158590308  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0.00881057268722467 0   0   0   0.978854625550661   0.000220264317180617    0.000440528634361233    0.000660792951541850    0.0110132158590308  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0.00881057268722467 0   0   0.000881057268722467    0.976872246696035   0.00110132158590308 0.00132158590308370 0   0.0110132158590308  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0.00881057268722467 0   0.00154185022026432 0.00176211453744493 0.974889867841410   0.00198237885462555 0   0   0.0110132158590308  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0.00881057268722467 0   0   0   0.980176211453745   0   0   0   0.0110132158590308  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0.0132158590308370  0   0   0   0.974449339207049   0.000220264317180617    0.000440528634361233    0.000660792951541850    0.0110132158590308  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0.0132158590308370  0   0   0.000881057268722467    0.972466960352423   0.00110132158590308 0.00132158590308370 0   0.0110132158590308  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0.0132158590308370  0   0.00154185022026432 0.00176211453744493 0.970484581497797   0.00198237885462555 0   0   0.0110132158590308  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0.0132158590308370  0   0   0   0.975770925110132   0   0   0   0.0110132158590308  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0.0176211453744493  0   0   0   0.970044052863436   0.000220264317180617    0.000440528634361233    0.000660792951541850    0.0110132158590308  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0.0176211453744493  0   0   0.000881057268722467    0.968061674008811   0.00110132158590308 0.00132158590308370 0   0.0110132158590308  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0.0176211453744493  0   0.00154185022026432 0.00176211453744493 0.966079295154185   0.00198237885462555 0   0   0.0110132158590308  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0.0176211453744493  0   0   0   0.971365638766520   0   0   0   0.0110132158590308  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0.0220264317180617  0   0   0   0.965638766519824   0.000220264317180617    0.000440528634361233    0.000660792951541850    0.0110132158590308  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0.0220264317180617  0   0   0.000881057268722467    0.963656387665198   0.00110132158590308 0.00132158590308370 0   0.0110132158590308  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0.0220264317180617  0   0.00154185022026432 0.00176211453744493 0.961674008810573   0.00198237885462555 0   0   0.0110132158590308  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0.0220264317180617  0   0   0   0.966960352422908   0   0   0   0.0110132158590308  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0.0264317180616740  0   0   0   0.961233480176212   0.000220264317180617    0.000440528634361233    0.000660792951541850    0.0110132158590308  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0.0264317180616740  0   0   0.000881057268722467    0.959251101321586   0.00110132158590308 0.00132158590308370 0   0.0110132158590308  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0.0264317180616740  0   0.00154185022026432 0.00176211453744493 0.957268722466960   0.00198237885462555 0   0   0.0110132158590308  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0.0264317180616740  0   0   0   0.962555066079295   0   0   0   0.0110132158590308  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0.0308370044052863  0   0   0   0.956828193832599   0.000220264317180617    0.000440528634361233    0.000660792951541850    0.0110132158590308  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0.0308370044052863  0   0   0.000881057268722467    0.954845814977974   0.00110132158590308 0.00132158590308370 0   0.0110132158590308  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0.0308370044052863  0   0.00154185022026432 0.00176211453744493 0.952863436123348   0.00198237885462555 0   0   0.0110132158590308  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0.0308370044052863  0   0   0   0.958149779735683   0   0   0   0.0110132158590308  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0.0352422907488987  0   0   0   0.952422907488987   0.000220264317180617    0.000440528634361233    0.000660792951541850    0.0110132158590308  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0.0352422907488987  0   0   0.000881057268722467    0.950440528634361   0.00110132158590308 0.00132158590308370 0   0.0110132158590308  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0.0352422907488987  0   0.00154185022026432 0.00176211453744493 0.948458149779736   0.00198237885462555 0   0   0.0110132158590308  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0.0352422907488987  0   0   0   0.953744493392071   0   0   0   0.0110132158590308  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0.0396475770925110  0   0   0   0.948017621145375   0.000220264317180617    0.000440528634361233    0.000660792951541850    0.0110132158590308  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0.0396475770925110  0   0   0.000881057268722467    0.946035242290749   0.00110132158590308 0.00132158590308370 0   0.0110132158590308  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0.0396475770925110  0   0.00154185022026432 0.00176211453744493 0.944052863436123   0.00198237885462555 0   0   0.0110132158590308  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0.0396475770925110  0   0   0   0.949339207048458   0   0   0   0.0110132158590308  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0.0440528634361234  0   0   0   0.943612334801762   0.000220264317180617    0.000440528634361233    0.000660792951541850    0.0110132158590308  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0.0440528634361234  0   0   0.000881057268722467    0.941629955947137   0.00110132158590308 0.00132158590308370 0   0.0110132158590308  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0.0440528634361234  0   0.00154185022026432 0.00176211453744493 0.939647577092511   0.00198237885462555 0   0   0.0110132158590308  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0.0440528634361234  0   0   0   0.944933920704846   0   0   0   0.0110132158590308  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0.0484581497797357  0   0   0   0.939207048458150   0.000220264317180617    0.000440528634361233    0.000660792951541850    0.0110132158590308  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0.0484581497797357  0   0   0.000881057268722467    0.937224669603524   0.00110132158590308 0.00132158590308370 0   0.0110132158590308  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0.0484581497797357  0   0.00154185022026432 0.00176211453744493 0.935242290748899   0.00198237885462555 0   0   0.0110132158590308  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0.0484581497797357  0   0   0   0.940528634361234   0   0   0   0.0110132158590308  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0.0528634361233480  0   0   0   0.934801762114538   0.000220264317180617    0.000440528634361233    0.000660792951541850    0.0110132158590308  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0.0528634361233480  0   0   0.000881057268722467    0.932819383259912   0.00110132158590308 0.00132158590308370 0   0.0110132158590308  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0.0528634361233480  0   0.00154185022026432 0.00176211453744493 0.930837004405286   0.00198237885462555 0   0   0.0110132158590308  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0.0528634361233480  0   0   0   0.936123348017621   0   0   0   0.0110132158590308  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0.0572687224669604  0   0   0   0.930396475770925   0.000220264317180617    0.000440528634361233    0.000660792951541850    0.0110132158590308  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0.0572687224669604  0   0   0.000881057268722467    0.928414096916300   0.00110132158590308 0.00132158590308370 0   0.0110132158590308  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0.0572687224669604  0   0.00154185022026432 0.00176211453744493 0.926431718061674   0.00198237885462555 0   0   0.0110132158590308  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0.0572687224669604  0   0   0   0.931718061674009   0   0   0   0.0110132158590308  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0.0616740088105727  0   0   0   0.925991189427313   0.000220264317180617    0.000440528634361233    0.000660792951541850    0.0110132158590308  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0.0616740088105727  0   0   0.000881057268722467    0.924008810572687   0.00110132158590308 0.00132158590308370 0   0.0110132158590308  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0.0616740088105727  0   0.00154185022026432 0.00176211453744493 0.922026431718062   0.00198237885462555 0   0   0.0110132158590308  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0.0616740088105727  0   0   0   0.927312775330397   0   0   0   0.0110132158590308  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0.0660792951541850  0   0   0   0.921585903083701   0.000220264317180617    0.000440528634361233    0.000660792951541850    0.0110132158590308  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0.0660792951541850  0   0   0.000881057268722467    0.919603524229075   0.00110132158590308 0.00132158590308370 0   0.0110132158590308  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0.0660792951541850  0   0.00154185022026432 0.00176211453744493 0.917621145374449   0.00198237885462555 0   0   0.0110132158590308  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0.0660792951541850  0   0   0   0.922907488986784   0   0   0   0.0110132158590308  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0.0704845814977974  0   0   0   0.917180616740088   0.000220264317180617    0.000440528634361233    0.000660792951541850    0.0110132158590308  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0.0704845814977974  0   0   0.000881057268722467    0.915198237885463   0.00110132158590308 0.00132158590308370 0   0.0110132158590308  0   0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0.0704845814977974  0   0.00154185022026432 0.00176211453744493 0.913215859030837   0.00198237885462555 0   0   0.0110132158590308  0   0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0.0704845814977974  0   0   0   0.918502202643172   0   0   0   0.0110132158590308  0   0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0.0748898678414097  0   0   0   0.912775330396476   0.000220264317180617    0.000440528634361233    0.000660792951541850    0.0110132158590308  0   0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0.0748898678414097  0   0   0.000881057268722467    0.910792951541850   0.00110132158590308 0.00132158590308370 0   0.0110132158590308  0   0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0.0748898678414097  0   0.00154185022026432 0.00176211453744493 0.908810572687225   0.00198237885462555 0   0   0.0110132158590308  0   0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0.0748898678414097  0   0   0   0.914096916299560   0   0   0   0.0110132158590308  0   0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0.0792951541850220  0   0   0   0.908370044052864   0.000220264317180617    0.000440528634361233    0.000660792951541850    0.0110132158590308  0   0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0.0792951541850220  0   0   0.000881057268722467    0.906387665198238   0.00110132158590308 0.00132158590308370 0   0.0110132158590308  0   0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0.0792951541850220  0   0.00154185022026432 0.00176211453744493 0.904405286343612   0.00198237885462555 0   0   0.0110132158590308  0   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0.0792951541850220  0   0   0   0.909691629955947   0   0   0   0.0110132158590308  0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0.0837004405286344  0   0   0   0.903964757709251   0.000220264317180617    0.000440528634361233    0.000660792951541850    0.0110132158590308  0   0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0.0837004405286344  0   0   0.000881057268722467    0.901982378854626   0.00110132158590308 0.00132158590308370 0   0.0110132158590308  0   0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0.0837004405286344  0   0.00154185022026432 0.00176211453744493 0.900000000000000   0.00198237885462555 0   0   0.0110132158590308  0
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0.0837004405286344  0   0   0   0.905286343612335   0   0   0   0.0110132158590308
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0.0881057268722467  0   0   0   0.910572687224670   0.000220264317180617    0.000440528634361233    0.000660792951541850
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0.0881057268722467  0   0   0.000881057268722467    0.908590308370044   0.00110132158590308 0.00132158590308370
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0.0881057268722467  0   0.00154185022026432 0.00176211453744493 0.906607929515419   0.00198237885462555
0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0.0881057268722467  0   0   0   0.911894273127753];

问题一:

这 3 种方法中的每一种都会产生不同的结果,我不确定该使用哪一种。 对于迭代器方法,我知道它是一个近似值,可以在大 TPM 的情况下使用。

为什么会有这么大的差异?

问题二:

为什么我在平稳分布中得到负值? 我使用了一个更大的 2600x2600 尺寸的 TPM,我没有得到任何负值,但是很难在这里放置 2600x2600 矩阵。

不需要工具箱:
我们知道稳态概率是以下离散时间马尔可夫链 (DTMC) 方程的唯一解。

您可以重写它以表明该分布必须位于转移概率矩阵的零空间中(见下文)。这允许使用 MATLAB 的 null().

归一化总和给出唯一解并满足另一个方程。

P = [.2 .3 .3 0 .2;
    .1 .2 .3 .4 0;
    0 .5 .4 .1 0;
    .2 .2 .2 .3 .1;
    .5 .2 .1 .1 .1];
ssp0 = null(eye(size(P))-P.');
SteadyStateProb = ssp0./sum(ssp0)          % [0.1263 0.3017 0.2969 0.2224 0.0528]

注意临时 ssp0 有负值,但最终答案 SteadyStateProb 是正确的,因为所有值都是有效概率并且所有概率总和为 1。


更新基于OP's edit:调节矩阵

您的转移概率矩阵(编辑中的 84×84 大小 TPM)的一个问题是行总和大于 1。您可以使用 find(sum(TPM,2) > 1) 验证这一点,以获取发生这种情况的行索引。此外,这个 "overage" 非常小:max(sum(TPM,2))-1 显示最大行总和超过 1 4.4409e-16,对我来说是 eps (2.2204e-16) 的两倍。

使用下面的技术含量很低的代码,我对每一行进行了标准化。

% Re-Normalize:  Divide the kth row by the sum of that row
TPM2 = TPM;
for k = 1:size(TPM2,1)
    TPM2(k,:) = TPM2(k,:)/sum(TPM2(k,:));   
end

这导致没有行总和超过一;您可以使用 find(sum(TPM2,2) > 1) 验证哪个 returns 一个 0×1 空双列向量。

在不进一步修改矩阵的情况下,我们可以获得稳态分布。

ssp0 = null(eye(size(TPM2))-TPM2.');
SteadyStateProb_TPM2 = ssp0./sum(ssp0);

请注意 min(SteadyStateProb_TPM2)-9.6502e-16(零!),总和基本上是 1 (abs(1-sum(SteadyStateProb_TPM2)))。

我现在只想强制非否定性。

SteadyStateProb_TPM2(SteadyStateProb_TPM2<0) = 0; 

与迭代近似比较:
我们知道 TPM2^n 收敛到 SteadyStateProb_TPM2 因为 n 变得足够大。让我们检查一下。

我们多次将转移矩阵乘以自身(这里我们得到了2500步的转移矩阵)。我们可以看到它似乎或多或少地集中在目标上。

Approx = TPM2^500;
Approx = Approx*Approx*Approx*Approx*Approx; 

ind = find(SteadyStateProb_TPM2 > 0.05); % find states with steady state prob > 0.05

SteadyStateProb_TPM2(ind).'
Approx(1:6,ind)

注意状态是 [4 8 12 16 20 24]

ans =

0.0821    0.2052    0.2565    0.2138    0.1336    0.0668

ans =

0.0727    0.1818    0.2273    0.1894    0.1184    0.0592
0.0760    0.1900    0.2374    0.1979    0.1237    0.0618
0.0763    0.1908    0.2385    0.1988    0.1242    0.0621
0.0821    0.2052    0.2565    0.2138    0.1336    0.0668
0.0727    0.1818    0.2273    0.1894    0.1184    0.0592
0.0760    0.1900    0.2374    0.1979    0.1237    0.0618

根据您的应用,您可能认为这种迭代方法足够好,但是当直接分析方法仍然可行时我不会使用它。我想一个 2600×2600 的矩阵在 MATLAB 中是可行的,如果你花时间确保它条件良好的话。

更新回复::特征值法怎么样?

它工作正常。

% Using the 5x5 P matrix from above
[V,D] = eigs(double(P.'),1);
Py = -abs(V)/sum(V)

或者,

Pyalt = V./sum(V)

您可以验证这也适用于 84x84:

[V2,D2] = eigs(double(TPM2'),1);
Py_TPM2 = -abs(V2)/sum(V2);
Py_TPM2alt = V2./sum(V2); 

% Evaluate to compare
SteadyStateProb_TPM2(ind).'         
Py_TPM2(ind).'
Py_TPM2alt(ind).'

给出以下内容。注意状态是 [4 8 12 16 20 24]

SteadyStateProb_TPM2(ind).' = 0.0821 0.2052 0.2565 0.2138 0.1336 0.0668
Py_TPM2(ind).' = 0.0821 0.2052 0.2565 0.2138 0.1336 0.0668
Py_TPM2alt(ind).' = 0.0821 0.2052 0.2565 0.2138 0.1336 0.0668