def test_set_start_state_list(self, check_state): model = MC(['b', 'a'], [1, 2]) check_state.return_value = True model.set_start_state([State('a', 0), State('b', 1)]) model_state = [State('b', 1), State('a', 0)] check_state.assert_called_once_with(model, model_state) self.assertEqual(model.state, model_state)
def test_copy(self): model = MC(['a', 'b'], [2, 2], [State('a', 0), State('b', 1)]) model.add_transition_model('a', {0: {0: 0.1, 1: 0.9}, 1: {0: 0.2, 1: 0.8}}) model.add_transition_model('b', {0: {0: 0.3, 1: 0.7}, 1: {0: 0.4, 1: 0.6}}) copy = model.copy() self.assertIsInstance(copy, MC) self.assertEqual(sorted(model.variables), sorted(copy.variables)) self.assertEqual(model.cardinalities, copy.cardinalities) self.assertEqual(model.transition_models, copy.transition_models) self.assertEqual(model.state, copy.state) model.add_variable('p', 1) model.set_start_state([State('a', 0), State('b', 1), State('p', 0)]) model.add_transition_model('p', {0: {0: 1}}) self.assertNotEqual(sorted(model.variables), sorted(copy.variables)) self.assertEqual(sorted(['a', 'b']), sorted(copy.variables)) self.assertNotEqual(model.cardinalities, copy.cardinalities) self.assertEqual({'a': 2, 'b': 2}, copy.cardinalities) self.assertNotEqual(model.state, copy.state) self.assertEqual([State('a', 0), State('b', 1)], copy.state) self.assertNotEqual(model.transition_models, copy.transition_models) self.assertEqual(len(copy.transition_models), 2) self.assertEqual(copy.transition_models['a'], {0: {0: 0.1, 1: 0.9}, 1: {0: 0.2, 1: 0.8}}) self.assertEqual(copy.transition_models['b'], {0: {0: 0.3, 1: 0.7}, 1: {0: 0.4, 1: 0.6}})
def test_is_stationarity_failure(self): model = MC(['intel', 'diff'], [2, 3]) model.set_start_state([State('intel', 0), State('diff', 2)]) intel_tm = {0: {0: 0.25, 1: 0.75}, 1: {0: 0.5, 1: 0.5}} model.add_transition_model('intel', intel_tm) diff_tm = {0: {0: 0.1, 1: 0.5, 2: 0.4}, 1: {0: 0.2, 1: 0.2, 2: 0.6}, 2: {0: 0.7, 1: 0.15, 2: 0.15}} model.add_transition_model('diff', diff_tm) self.assertFalse(model.is_stationarity(0.002, None))
def test_is_stationarity_failure(self): model = MC(['intel', 'diff'], [2, 3]) model.set_start_state([State('intel', 0), State('diff', 2)]) intel_tm = {0: {0: 0.25, 1: 0.75}, 1: {0: 0.5, 1: 0.5}} model.add_transition_model('intel', intel_tm) diff_tm = { 0: { 0: 0.1, 1: 0.5, 2: 0.4 }, 1: { 0: 0.2, 1: 0.2, 2: 0.6 }, 2: { 0: 0.7, 1: 0.15, 2: 0.15 } } model.add_transition_model('diff', diff_tm) self.assertFalse(model.is_stationarity(0.002, None))
def test_copy(self): model = MC(['a', 'b'], [2, 2], [State('a', 0), State('b', 1)]) model.add_transition_model('a', { 0: { 0: 0.1, 1: 0.9 }, 1: { 0: 0.2, 1: 0.8 } }) model.add_transition_model('b', { 0: { 0: 0.3, 1: 0.7 }, 1: { 0: 0.4, 1: 0.6 } }) copy = model.copy() self.assertIsInstance(copy, MC) self.assertEqual(sorted(model.variables), sorted(copy.variables)) self.assertEqual(model.cardinalities, copy.cardinalities) self.assertEqual(model.transition_models, copy.transition_models) self.assertEqual(model.state, copy.state) model.add_variable('p', 1) model.set_start_state([State('a', 0), State('b', 1), State('p', 0)]) model.add_transition_model('p', {0: {0: 1}}) self.assertNotEqual(sorted(model.variables), sorted(copy.variables)) self.assertEqual(sorted(['a', 'b']), sorted(copy.variables)) self.assertNotEqual(model.cardinalities, copy.cardinalities) self.assertEqual({'a': 2, 'b': 2}, copy.cardinalities) self.assertNotEqual(model.state, copy.state) self.assertEqual([State('a', 0), State('b', 1)], copy.state) self.assertNotEqual(model.transition_models, copy.transition_models) self.assertEqual(len(copy.transition_models), 2) self.assertEqual(copy.transition_models['a'], { 0: { 0: 0.1, 1: 0.9 }, 1: { 0: 0.2, 1: 0.8 } }) self.assertEqual(copy.transition_models['b'], { 0: { 0: 0.3, 1: 0.7 }, 1: { 0: 0.4, 1: 0.6 } })
def test_set_start_state_none(self): model = MC() model.state = 'state' model.set_start_state(None) self.assertIsNone(model.state)