def test_is_stochastic_matrix(self): m = [[1, 0], [0, 1]] self.assertTrue(is_stochastic_matrix(m)) m = [[1, 1e-20], [0, 1]] self.assertTrue(is_stochastic_matrix(m)) m = [[0.6, 0.4], [0.8, 0.2]] self.assertTrue(is_stochastic_matrix(m)) m = [[0.6, 0.6], [0.8, 0.2]] self.assertFalse(is_stochastic_matrix(m)) m = [[0.6, 0.4], [0.8, 1.2]] self.assertFalse(is_stochastic_matrix(m))
def test_malformed_params(self): # Test a malformed table t_C = [[1, 0.5], [0, 1]] self.assertFalse(is_stochastic_matrix(t_C)) t_C = [[1, 0], [0, 1]] t_D = [[0, 1], [1, 0]] p = [1, 0] hmm = SimpleHMM(t_C, t_C, p, 0) self.assertTrue(hmm.is_well_formed()) hmm = SimpleHMM(t_C, t_D, p, -1) self.assertFalse(hmm.is_well_formed()) t_C = [[1, -1], [0, 1]] t_D = [[0, 1], [1, 0]] p = [1, 0] hmm = SimpleHMM(t_C, t_D, p, 0) self.assertFalse(hmm.is_well_formed()) t_C = [[1, 0], [0, 1]] t_D = [[0, 2], [1, 0]] p = [1, 0] hmm = SimpleHMM(t_C, t_D, p, 0) self.assertFalse(hmm.is_well_formed()) t_C = [[1, 0], [0, 1]] t_D = [[0, 1], [1, 0]] p = [-1, 2] hmm = SimpleHMM(t_C, t_D, p, 0) self.assertFalse(hmm.is_well_formed())