刚开始用matlab中的hmm函数的童鞋想必都对其参数或者返回值或多或少会有一些疑问,matlab官方文档 http://www.mathworks.cn/cn/help/stats/hidden-markov-models-hmm.html 对此的解释又是相当简洁,本文写了一些博主对这些函数的理解,如果有什么疑问或者指正的话欢迎提出O(∩_∩)O~
1. hmmdecode
1.1 matlab的运行
>> t = [.7, .3; .4, .6]
t = %transmission matrix
0.7000 0.3000
0.4000 0.6000
>> e = [.1, .1 .8; .8, .1, .1]
e = %emission matrix
0.1000 0.1000 0.8000
0.8000 0.1000 0.1000
>> s = [1, 2, 3] %sequence
s =
1 2 3
>> [p,logPseq,fs,bs,scale] = hmmdecode(s,t,e)
p = % calculates the posterior state probabilities of the sequence seq
0.2488 0.5771 0.9039
0.7512 0.4229 0.0961
logPseq = % the logarithm of the probability of sequence seq
-4.2114
fs = %fs and bs returns forward and backward probabilities of the sequence scaled by S .
1.0000 0.2258 0.4677 0.9039
0 0.7742 0.5323 0.0961
bs =
1.0000 1.1020 1.2337 1.0000
1.6445 0.9703 0.7946 1.0000
scale =
1.0000 0.3100 0.1000 0.4782
t = %transmission matrix
0.7000 0.3000
0.4000 0.6000
>> e = [.1, .1 .8; .8, .1, .1]
e = %emission matrix
0.1000 0.1000 0.8000
0.8000 0.1000 0.1000
>> s = [1, 2, 3] %sequence
s =
1 2 3
>> [p,logPseq,fs,bs,scale] = hmmdecode(s,t,e)
p = % calculates the posterior state probabilities of the sequence seq
0.2488 0.5771 0.9039
0.7512 0.4229 0.0961
logPseq = % the logarithm of the probability of sequence seq
-4.2114
fs = %fs and bs returns forward and backward probabilities of the sequence scaled by S .
1.0000 0.2258 0.4677 0.9039
0 0.7742 0.5323 0.0961
bs =
1.0000 1.1020 1.2337 1.0000
1.6445 0.9703 0.7946 1.0000
scale =
1.0000 0.3100 0.1000 0.4782
1.2 返回值验证
写程序对返回值进行验证,程序见文后附录。