# 状态转移矩阵标签:维特,0.3,0.2,0.5,0.4,算法,pi,append From: https://www.cnblogs.com/lld76/p/16843537.html
A = [[0.5, 0.2, 0.3],
[0.3, 0.5, 0.2],
[0.2, 0.3, 0.5]]
# 观测概率矩阵
B = [[0.5, 0.5],
[0.4, 0.6],
[0.7, 0.3]]
# 观测序列
pi = [0.2, 0.4, 0.4]
def a1():
t = 0
a = []
for i in range(len(pi)):
a.append(pi[i] * B[i][t])
return a
a = a1()
print(a)
def q(a, t):
b = []
for i in range(len(A)):
c = []
for j in range(len(A)):
c.append(A[j][i] * a[j])
b.append(max(c)*B[i][t])
print(b)
return b
d = q(a, 1)
d = q(d, 0)