本文整理汇总了Python中pgmpy.models.BayesianModel.moral_graph方法的典型用法代码示例。如果您正苦于以下问题:Python BayesianModel.moral_graph方法的具体用法?Python BayesianModel.moral_graph怎么用?Python BayesianModel.moral_graph使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pgmpy.models.BayesianModel
的用法示例。
在下文中一共展示了BayesianModel.moral_graph方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_moral_graph_with_edge_present_over_parents
# 需要导入模块: from pgmpy.models import BayesianModel [as 别名]
# 或者: from pgmpy.models.BayesianModel import moral_graph [as 别名]
def test_moral_graph_with_edge_present_over_parents(self):
G = BayesianModel([('a', 'd'), ('d', 'e'), ('b', 'd'), ('b', 'c'), ('a', 'b')])
moral_graph = G.moral_graph()
self.assertListEqual(sorted(moral_graph.nodes()), ['a', 'b', 'c', 'd', 'e'])
for edge in moral_graph.edges():
self.assertTrue(edge in [('a', 'b'), ('c', 'b'), ('d', 'a'), ('d', 'b'), ('d', 'e')] or
(edge[1], edge[0]) in [('a', 'b'), ('c', 'b'), ('d', 'a'), ('d', 'b'), ('d', 'e')])
示例2: TestBayesianModelMethods
# 需要导入模块: from pgmpy.models import BayesianModel [as 别名]
# 或者: from pgmpy.models.BayesianModel import moral_graph [as 别名]
#.........这里部分代码省略.........
# self.assertListEqual(self.G.node['b']['_rule_for_states'], [0])
# self.G._update_rule_for_states('a', 5)
# self.assertListEqual(self.G.node['a']['_rule_for_states'],
# [0, 1, 2, 3, 4])
# self.G.node['a']['_rule_for_states'] = [1, 0, 2]
# self.G._update_rule_for_states('a', 5)
# self.assertListEqual(self.G.node['a']['_rule_for_states'],
# [1, 0, 2, 3, 4])
#
# def test_update_node_observed_status(self):
# self.G.set_states({'a': [1, 2, 3]})
# self.assertFalse(self.G.node['a']['_observed'])
# self.G.node['a']['_states'][0]['observed_status'] = True
# self.G._update_node_observed_status('a')
# self.assertTrue(self.G.node['a']['_observed'])
#
# def test_no_missing_states(self):
# self.G.set_states({'a': [1, 2, 3]})
# self.assertTrue(self.G._no_missing_states('a', [1, 2, 3]))
# self.assertRaises(ValueError,
# self.G._no_missing_states, 'a', [1, 2])
#
# def test_no_extra_states(self):
# self.G.set_states({'a': [1, 2, 3]})
# self.assertTrue(self.G._no_extra_states('a', [1, 2]))
# self.assertTrue(self.G._no_extra_states('a', [1, 2, 3]))
# self.assertRaises(ValueError,
# self.G._no_extra_states, 'a', [1, 2, 3, 4])
#
# def test_no_extra_parents(self):
# self.assertTrue(self.G._no_extra_parents('d', ['a', 'b']))
# self.assertRaises(ValueError,
# self.G._no_extra_parents, 'd', ['a', 'b', 'c'])
# self.assertTrue(self.G._no_extra_parents('d', ['a']))
#
# def test_no_missing_parents(self):
# self.assertTrue(self.G._no_missing_parents('d', ['a', 'b']))
# self.assertTrue(self.G._no_missing_parents('d', ['a', 'b', 'c']))
# self.assertRaises(ValueError,
# self.G._no_missing_parents, 'd', ['a'])
#
# def test_get_rule_for_states(self):
# self.G.set_states({'a': [1, 2, 3]})
# self.assertListEqual(self.G.get_rule_for_states('a'), [1, 2, 3])
#
# def test_set_rule_for_states(self):
# self.G.set_states({'a': [1, 2, 3]})
# self.G.set_rule_for_states('a', [3, 1, 2])
# self.assertListEqual(self.G.get_rule_for_states('a'), [3, 1, 2])
#
# def test_all_states_present_in_list(self):
# self.G.set_states({'a': [1, 2, 3]})
# self.assertTrue(self.G._all_states_present_in_list('a', [1, 2, 3]))
# self.assertTrue(self.G._all_states_present_in_list('a', [2, 1, 3]))
# self.assertFalse(self.G._all_states_present_in_list('a', [1, 2]))
#
# def test_is_node_parents_equal_parents_list(self):
# self.assertTrue(self.G._is_node_parents_equal_parents_list(
# 'd', ['a', 'b']))
# self.assertTrue(self.G._is_node_parents_equal_parents_list(
# 'd', ['b', 'a']))
# self.assertFalse(self.G._is_node_parents_equal_parents_list(
# 'd', ['a']))
#
# def test_get_rule_for_parents(self):
# self.assertListEqual(self.G.get_rule_for_parents('d'), ['a', 'b'])
# self.assertListEqual(self.G.get_rule_for_parents('a'), [])
#
# def test_set_rule_for_parents(self):
# self.G.set_rule_for_parents('d', ['b', 'a'])
# self.assertListEqual(self.G.node['d']['_rule_for_parents'], [1, 0])
# self.assertListEqual(self.G.get_rule_for_parents('d'), ['b', 'a'])
#
# def test_get_parents(self):
# self.assertListEqual(list(self.G.get_parents('d')), ['a', 'b'])
# self.G.set_rule_for_parents('d', ['b', 'a'])
# self.assertListEqual(list(self.G.get_parents('d')), ['b', 'a'])
#
# def test_get_parent_objects(self):
# self.assertListEqual(list(self.G._get_parent_objects('d')),
# [self.G.node['a'], self.G.node['b']])
# self.assertListEqual(list(self.G._get_parent_objects('a')), [])
def test_moral_graph(self):
moral_graph = self.G.moral_graph()
self.assertListEqual(sorted(moral_graph.nodes()), ['a', 'b', 'c', 'd', 'e'])
for edge in moral_graph.edges():
self.assertTrue(edge in [('a', 'b'), ('a', 'd'), ('b', 'c'), ('d', 'b'), ('e', 'd')] or
(edge[1], edge[0]) in [('a', 'b'), ('a', 'd'), ('b', 'c'), ('d', 'b'), ('e', 'd')])
def test_moral_graph_with_edge_present_over_parents(self):
G = BayesianModel([('a', 'd'), ('d', 'e'), ('b', 'd'), ('b', 'c'), ('a', 'b')])
moral_graph = G.moral_graph()
self.assertListEqual(sorted(moral_graph.nodes()), ['a', 'b', 'c', 'd', 'e'])
for edge in moral_graph.edges():
self.assertTrue(edge in [('a', 'b'), ('c', 'b'), ('d', 'a'), ('d', 'b'), ('d', 'e')] or
(edge[1], edge[0]) in [('a', 'b'), ('c', 'b'), ('d', 'a'), ('d', 'b'), ('d', 'e')])
def tearDown(self):
del self.G