当前位置: 首页>>代码示例>>Python>>正文


Python HMM.forward方法代码示例

本文整理汇总了Python中hmm.HMM.forward方法的典型用法代码示例。如果您正苦于以下问题:Python HMM.forward方法的具体用法?Python HMM.forward怎么用?Python HMM.forward使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在hmm.HMM的用法示例。


在下文中一共展示了HMM.forward方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from hmm import HMM [as 别名]
# 或者: from hmm.HMM import forward [as 别名]
def main():
    hmm = HMM(3, ('up', 'down', 'unchanged'),
              initial_probability=[0.5, 0.2, 0.3],
              transition_probability=[[0.6, 0.2, 0.2],
                                      [0.5, 0.3, 0.2],
                                      [0.4, 0.1, 0.5]],
              observation_probability=[[0.7, 0.1, 0.2],
                                       [0.1, 0.6, 0.3],
                                       [0.3, 0.3, 0.4]])

    observation = ("up", "up", "unchanged", "down", "unchanged", "down", "up")
    ob_length = len(observation)
    p, _ = hmm.forward(observation, ob_length)
    path = hmm.decode(observation, ob_length)
    print("P{} = {:.13f}".format(tuple(observation), p))
    print("Observation sequence =", tuple(i+1 for i in path))
开发者ID:hane1818,项目名称:Simple-HMM,代码行数:18,代码来源:hw1.py

示例2: read_hmm

# 需要导入模块: from hmm import HMM [as 别名]
# 或者: from hmm.HMM import forward [as 别名]
import numpy as np

from hmm import HMM, read_hmm, read_sequence


hmmfile = "test.hmm"
seqfile = "test.seq"

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:"
开发者ID:CallMeXiaoChiZi,项目名称:UMDHMM-python,代码行数:33,代码来源:test_hmm.py


注:本文中的hmm.HMM.forward方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。