示例#1
0
 def test_HMM_load(self):
     for mathType in self.mathTypes:
         hmm = HMM(mathType)
         hmm.load(self.inputHMMData[mathType])
         X = hmm.toJSON()
         Y = self.inputHMMData[mathType]
         for i in range(len(Y["states"])):
             Y["states"][i] = Y["states"][i].toJSON()
         X["transitions"] = sorted(X["transitions"])
         Y["transitions"] = sorted(Y["transitions"])
         self.assertDictEqual(X, Y, "HMM.load/toJSON() is broken: " + \
                              str(X) + " != " + str(Y)) 
示例#2
0
 def test_HMM_toposort(self):
     for mathType in self.mathTypes:
         hmm = HMM(mathType)
         hmm.load(self.inputHMMData[mathType])
         hmm.reorderStatesTopologically()
         Y = "Init"
         X = hmm.states[0].stateName
         self.assertEqual(X, Y, "Toposort does no sort states correctly." + \
                          " First state is " + X + " and should be " + Y)
         self.assertEqual(len(hmm.transitions[0]), 2, 
                          "Remapping of transitions does not work.")
         self.assertEqual(len(hmm.transitions[1]), 1, 
                          "Remapping of transitions does not work.")
         self.assertEqual(len(hmm.transitions[2]), 1, 
                          "Remapping of transitions does not work.")
         for i in [1,2]:
             if i not in hmm.transitions[i]:
                 self.fail("Remapping of transitions does not work.")
             self.assertAlmostEqual(float(hmm.transitions[i][i]), 1.0,
                                    delta="1e-7", msg=
                                    "Remapping of transitions does not work")