本文整理汇总了Python中pgmpy.models.MarkovModel.check_model方法的典型用法代码示例。如果您正苦于以下问题:Python MarkovModel.check_model方法的具体用法?Python MarkovModel.check_model怎么用?Python MarkovModel.check_model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pgmpy.models.MarkovModel
的用法示例。
在下文中一共展示了MarkovModel.check_model方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestMarkovModelMethods
# 需要导入模块: from pgmpy.models import MarkovModel [as 别名]
# 或者: from pgmpy.models.MarkovModel import check_model [as 别名]
class TestMarkovModelMethods(unittest.TestCase):
def setUp(self):
self.graph = MarkovModel()
def test_get_cardinality(self):
self.graph.add_edges_from([('a', 'b'), ('b', 'c'), ('c', 'd'),
('d', 'a')])
self.assertDictEqual(self.graph.get_cardinality(), {})
phi1 = Factor(['a', 'b'], [1, 2], np.random.rand(2))
self.graph.add_factors(phi1)
self.assertDictEqual(self.graph.get_cardinality(), {'a': 1, 'b': 2})
self.graph.remove_factors(phi1)
self.assertDictEqual(self.graph.get_cardinality(), {})
phi1 = Factor(['a', 'b'], [2, 2], np.random.rand(4))
phi2 = Factor(['c', 'd'], [1, 2], np.random.rand(2))
self.graph.add_factors(phi1, phi2)
self.assertDictEqual(self.graph.get_cardinality(), {'d': 2, 'a': 2, 'b': 2, 'c': 1})
phi3 = Factor(['d', 'a'], [1, 2], np.random.rand(2))
self.graph.add_factors(phi3)
self.assertDictEqual(self.graph.get_cardinality(), {'d': 1, 'c': 1, 'b': 2, 'a': 2})
self.graph.remove_factors(phi1, phi2, phi3)
self.assertDictEqual(self.graph.get_cardinality(), {})
def test_get_cardinality_check_cardinality(self):
self.graph.add_edges_from([('a', 'b'), ('b', 'c'), ('c', 'd'),
('d', 'a')])
phi1 = Factor(['a', 'b'], [1, 2], np.random.rand(2))
self.graph.add_factors(phi1)
self.assertRaises(ValueError, self.graph.get_cardinality, check_cardinality=True)
phi2 = Factor(['a', 'c'], [1, 2], np.random.rand(2))
self.graph.add_factors(phi2)
self.assertRaises(ValueError, self.graph.get_cardinality, check_cardinality=True)
phi3 = Factor(['c', 'd'], [2, 2], np.random.rand(4))
self.graph.add_factors(phi3)
self.assertDictEqual(self.graph.get_cardinality(check_cardinality=True), {'d': 2, 'c': 2, 'b': 2, 'a': 1})
def test_check_model(self):
self.graph.add_edges_from([('a', 'b'), ('b', 'c'), ('c', 'd'),
('d', 'a')])
phi1 = Factor(['a', 'b'], [1, 2], np.random.rand(2))
phi2 = Factor(['c', 'b'], [3, 2], np.random.rand(6))
phi3 = Factor(['c', 'd'], [3, 4], np.random.rand(12))
phi4 = Factor(['d', 'a'], [4, 1], np.random.rand(4))
self.graph.add_factors(phi1, phi2, phi3, phi4)
self.assertTrue(self.graph.check_model())
self.graph.remove_factors(phi1, phi4)
phi1 = Factor(['a', 'b'], [4, 2], np.random.rand(8))
self.graph.add_factors(phi1)
self.assertTrue(self.graph.check_model())
def test_check_model1(self):
self.graph.add_edges_from([('a', 'b'), ('b', 'c'), ('c', 'd'),
('d', 'a')])
phi1 = Factor(['a', 'b'], [1, 2], np.random.rand(2))
phi2 = Factor(['b', 'c'], [3, 3], np.random.rand(9))
self.graph.add_factors(phi1, phi2)
self.assertRaises(ValueError, self.graph.check_model)
self.graph.remove_factors(phi2)
phi3 = Factor(['c', 'a'], [4, 4], np.random.rand(16))
self.graph.add_factors(phi3)
self.assertRaises(ValueError, self.graph.check_model)
self.graph.remove_factors(phi3)
phi2 = Factor(['b', 'c'], [2, 3], np.random.rand(6))
phi3 = Factor(['c', 'd'], [3, 4], np.random.rand(12))
phi4 = Factor(['d', 'a'], [4, 3], np.random.rand(12))
self.graph.add_factors(phi2, phi3, phi4)
self.assertRaises(ValueError, self.graph.check_model)
self.graph.remove_factors(phi2, phi3, phi4)
phi2 = Factor(['a', 'b'], [1, 3], np.random.rand(3))
self.graph.add_factors(phi1, phi2)
self.assertRaises(ValueError, self.graph.check_model)
self.graph.remove_factors(phi2)
def test_check_model2(self):
self.graph.add_edges_from([('a', 'b'), ('b', 'c'), ('c', 'd'),
('d', 'a')])
phi1 = Factor(['a', 'c'], [1, 2], np.random.rand(2))
#.........这里部分代码省略.........