2012-04-16 62 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.