在您的问题中,矩阵P
是转移概率。i
当前状态为下一个状态的概率j
为:
P[i, j] = Pr(k = j | k = i)
mpow(P, n)
计算转移矩阵的 n 次方. 例如,
> mpow(P, 3)
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] 0.000 0.030 0.105 0.250 0.280 0.335
[2,] 0.001 0.025 0.111 0.254 0.260 0.349
[3,] 0.006 0.032 0.113 0.266 0.224 0.359
[4,] 0.006 0.048 0.144 0.289 0.172 0.341
[5,] 0.000 0.024 0.156 0.400 0.248 0.172
[6,] 0.000 0.000 0.048 0.272 0.432 0.248
> mpow(P, 10)
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] 0.002603379 0.02615891 0.1174816 0.3118660 0.2703684 0.2715217
[2,] 0.002591038 0.02612154 0.1175283 0.3121341 0.2705060 0.2711190
[3,] 0.002565915 0.02600925 0.1174628 0.3124644 0.2710401 0.2704575
[4,] 0.002523007 0.02573033 0.1169686 0.3125272 0.2725643 0.2696866
[5,] 0.002560361 0.02545419 0.1150961 0.3094197 0.2749053 0.2725643
[6,] 0.002708774 0.02649409 0.1171436 0.3096530 0.2690952 0.2749053
> mpow(P,50)
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] 0.002590674 0.02590674 0.1165803 0.3108808 0.2720207 0.2720207
[2,] 0.002590674 0.02590674 0.1165803 0.3108808 0.2720207 0.2720207
[3,] 0.002590674 0.02590674 0.1165803 0.3108808 0.2720207 0.2720207
[4,] 0.002590674 0.02590674 0.1165803 0.3108808 0.2720207 0.2720207
[5,] 0.002590674 0.02590674 0.1165803 0.3108808 0.2720207 0.2720207
[6,] 0.002590674 0.02590674 0.1165803 0.3108808 0.2720207 0.2720207
如您所见,当n
很大时,您会达到平稳分布,其中所有行都相等。换句话说,无论初始状态如何,最终到达某个状态的概率都是相同的。
一旦达到这种收敛,这个矩阵的任何一行都是平稳分布。例如,您可以提取第一行:
> mpow(P,50)[1, ]
[1] 0.002590674 0.025906736 0.116580311 0.310880829 0.272020725 0.272020725