本文整理汇总了Python中hmm.HMM.baum_welch方法的典型用法代码示例。如果您正苦于以下问题:Python HMM.baum_welch方法的具体用法?Python HMM.baum_welch怎么用?Python HMM.baum_welch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hmm.HMM
的用法示例。
在下文中一共展示了HMM.baum_welch方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: read_hmm
# 需要导入模块: from hmm import HMM [as 别名]
# 或者: from hmm.HMM import baum_welch [as 别名]
M, N, pi, A, B = read_hmm(hmmfile)
T, obs = read_sequence(seqfile)
hmm_object = HMM(pi, A, B)
#test forward algorithm
prob, alpha = hmm_object.forward(obs)
print "forward probability is %f" % np.log(prob)
prob, alpha, scale = hmm_object.forward_with_scale(obs)
print "forward probability with scale is %f" % prob
# test backward algorithm
prob, beta = hmm_object.backward(obs)
print "backward probability is %f" % prob
beta = hmm_object.backward_with_scale(obs, scale)
# test baum-welch algorithm
logprobinit, logprobfinal = hmm_object.baum_welch(obs)
print "------------------------------------------------"
print "estimated parameters are: "
print "pi is:"
print hmm_object.pi
print "A is:"
print hmm_object.A
print "B is:"
print hmm_object.B
print "------------------------------------------------"
print "initial log probability is:"
print logprobinit
print "final log probability is:"
print logprobfinal
示例2: range
# 需要导入模块: from hmm import HMM [as 别名]
# 或者: from hmm.HMM import baum_welch [as 别名]
# for i in range(len(obs)):
# print str(obs[i])+' '+path[i]
# Learning Test
hmmLearn = HMM(a2, b2, pi2)
#Defines the influence that new observations have on previous probabilities
hmmLearn.influence = (3, 14)
# hmmLearn.generateMatrix(states, alphabet)
##Supervised Learning
# for x in range(50):
# hmmLearn.supertrain(hmm.generate(2000))
# print "-----"
# print hmmLearn.pi
# print hmmLearn.a
# print hmmLearn.b
##Unsupervised Learning (EM/Baum-Welch)
for x in range(100):
hmmLearn.baum_welch(hmm.generate(100, True))
print pi
print a
print b
print "---"
print hmmLearn.pi
print hmmLearn.a
print hmmLearn.b