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))
Exemplo n.º 3
0
 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))
Exemplo n.º 4
0
 def test_transition_model_dict_to_matrix(self):
     model = MC(['var'], [2])
     transition_model = {0: {0: 0.3, 1: 0.7}, 1: {0: 0.5, 1: 0.5}}
     transition_model_matrix = np.array([[0.3, 0.7], [0.5, 0.5]])
     model.add_transition_model('var', transition_model_matrix)
     self.assertDictEqual(model.transition_models['var'], transition_model)
Exemplo n.º 5
0
 def test_add_transition_model_success(self):
     model = MC(['var'], [2])
     transition_model = {0: {0: 0.3, 1: 0.7}, 1: {0: 0.5, 1: 0.5}}
     model.add_transition_model('var', transition_model)
     self.assertDictEqual(model.transition_models['var'], transition_model)
Exemplo n.º 6
0
    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_transition_model_dict_to_matrix(self):
     model = MC(['var'], [2])
     transition_model = {0: {0: 0.3, 1: 0.7}, 1: {0: 0.5, 1: 0.5}}
     transition_model_matrix = np.array([[0.3, 0.7], [0.5, 0.5]])
     model.add_transition_model('var', transition_model_matrix)
     self.assertDictEqual(model.transition_models['var'], transition_model)
 def test_add_transition_model_success(self):
     model = MC(['var'], [2])
     transition_model = {0: {0: 0.3, 1: 0.7}, 1: {0: 0.5, 1: 0.5}}
     model.add_transition_model('var', transition_model)
     self.assertDictEqual(model.transition_models['var'], transition_model)