2012-04-16 45 views
0

的定义可能是错误的生成马尔可夫模型,所以请纠正我,如果是这样的话。我需要生成从以下类型的矩阵马尔可夫模型:从矩阵

four two "e"   
four two "e"   
three three "e"   
one three "e"   
zero six one zero "e" 
two two "e"   
two two "e"   
two two "e"   
two two "e"   
two two "e"   
four zero "e"   
two two "e"   
three one three "e"  
three "e"    
four one "e"   
three one "e"   
two one one zero two "e" 
two five "e"   
three four two "e"  
zero five "e"   
three "e"    
three three "e"   
three "e"    
one one "e"   
three two "e"   
one one "e"   
three two zero zero zero "e" 
three three "e"   
three one "e"   
three two "e"   

我需要输出如下所示:{“four”:[{2:“two”,3:“one”,2:“exit”},{...}],“three”:[{...} ]}

上面的数字基本都是多少次向特定状态的转变发生..

我使用python这一点。

回答常见问题“你有什么尝试?”:“我尝试了一些方法,但他们没有完成交付,所以我希望其中一个答案有助于澄清事情。”

非常感谢。

编辑,更新为显示完整矩阵。

+1

您能代表您的输入矩阵中的完整OP吗?你的解释不是很清楚 – Abhijit 2012-04-16 18:33:25

+0

增加了全矩阵 – Stpn 2012-04-16 18:59:51

+0

一条线的物理意义如何:'三四二'e“'?它是从底层马尔可夫链的特定实现,从状态“3-> 4-> 2”,然后结束? – Hooked 2012-04-16 19:05:34

回答

1

您没有给出转变的矩阵(这些将是概率),而是从一个潜在的马尔可夫模型导致观察到的转变的序列。

除非您拥有无数个这些观察值,否则您无法准确重构底层转换参数。但是,您可以选择这样的转换,以便您的可观测序列最可能是。如果我理解你的问题,你应该看看Hidden Markov Models的解决方案。一个免费可用的python模块GHMM可以在here找到。

+0

谢谢,看起来像GHMM可能实际上做的工作。 – Stpn 2012-04-16 19:24:25

0

这里有一个想法:与其 试图创建{"four":[{2:"two", 3:"one",2:"exit"},{...}],"three":[{...}]}(这是不是在蟒蛇完全合法),尝试创建{"four":[{"two":2, "one":3, "exit":2},{...}],"three":[{...}]}(请注意在内部字典顺序的变化)。

Iterate over the matrix, for each line: 
    if the first word isn't in the big dictionary, add it. 
    if the second word isn't in its sub-dictionary, add it, otherwise add 1 to its value.