Exemple #1
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")