Numpy 我对马克洛夫概率模型有问题
我在为流行病模拟生成一个包含所有可能状态的矩阵时遇到了麻烦。while循环应形成一个系统矩阵,其中包含系统达到每个人死亡或死亡状态的所有可能概率Numpy 我对马克洛夫概率模型有问题,numpy,linear-algebra,Numpy,Linear Algebra,我在为流行病模拟生成一个包含所有可能状态的矩阵时遇到了麻烦。while循环应形成一个系统矩阵,其中包含系统达到每个人死亡或死亡状态的所有可能概率 import numpy as np import math #simulating makrov chain model p = np.array([[.95, .05, 0, 0], [0, .65, .3, .05], [0,0,1,0],[0,0,0,1]]) # print(p) state = np.array([1,0,0
import numpy as np
import math
#simulating makrov chain model
p = np.array([[.95, .05, 0, 0], [0, .65, .3, .05], [0,0,1,0],[0,0,0,1]])
# print(p)
state = np.array([1,0,0,0])
#finding the number of transitions for 1 uninfected to become either deceased or dead
system_t = [state]
k=0
while math.isclose(state[0]+state[1],0):
state = p @ state
system_t.append(state)
k+=1
# print(system_t)
# import pandas as pd
history = np.array(system_t)
print(history)
我不确定我的错误在这里,并将感谢任何帮助。我只知道返回的历史矩阵和系统矩阵的大小不正确,只返回第一个状态[1,0,0,0]