// 测试维特比算法 public static void CheckViterbi() { // 状态转移矩阵 Double[,] A = { { 0.500, 0.250, 0.250 }, { 0.375, 0.125, 0.375 }, { 0.125, 0.675, 0.375 } }; // 混淆矩阵 Double[,] B = { { 0.60, 0.20, 0.15, 0.05 }, { 0.25, 0.25, 0.25, 0.25 }, { 0.05, 0.10, 0.35, 0.50 } }; // 初始概率向量 Double[] PI = { 0.63, 0.17, 0.20 }; // 观察序列 Int32[] OB = { (Int32)Seaweed.Dry, (Int32)Seaweed.Damp, (Int32)Seaweed.Soggy, (Int32)Seaweed.Dryish, (Int32)Seaweed.Dry }; // 初始化HMM模型 HMM hmm = new HMM(A.GetLength(0), B.GetLength(1)); hmm.A = A; hmm.B = B; hmm.PI = PI; // 找出最有可能的隐藏状态序列 Double Probability; Console.WriteLine("------------维特比算法:双精度运算-----------------"); Int32[] Q = hmm.Viterbi(OB, out Probability); Console.WriteLine("Probability =" + Probability.ToString("0.###E+0")); foreach (Int32 Value in Q) { Console.WriteLine(((Weather)Value).ToString()); } Console.WriteLine(); Console.WriteLine("------------维特比算法:对数运算-----------------"); Q = hmm.ViterbiLog(OB, out Probability); Console.WriteLine("Probability =" + Probability.ToString("0.###E+0")); foreach (Int32 Value in Q) { Console.WriteLine(((Weather)Value).ToString()); } }