本文整理汇总了Python中pgmpy.models.MarkovModel.get_partition_function方法的典型用法代码示例。如果您正苦于以下问题:Python MarkovModel.get_partition_function方法的具体用法?Python MarkovModel.get_partition_function怎么用?Python MarkovModel.get_partition_function使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pgmpy.models.MarkovModel
的用法示例。
在下文中一共展示了MarkovModel.get_partition_function方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestUndirectedGraphFactorOperations
# 需要导入模块: from pgmpy.models import MarkovModel [as 别名]
# 或者: from pgmpy.models.MarkovModel import get_partition_function [as 别名]
class TestUndirectedGraphFactorOperations(unittest.TestCase):
def setUp(self):
self.graph = MarkovModel()
def test_add_factor_raises_error(self):
self.graph.add_edges_from([('Alice', 'Bob'), ('Bob', 'Charles'),
('Charles', 'Debbie'), ('Debbie', 'Alice')])
factor = Factor(['Alice', 'Bob', 'John'], [2, 2, 2], np.random.rand(8))
self.assertRaises(ValueError, self.graph.add_factors, factor)
def test_add_single_factor(self):
self.graph.add_nodes_from(['a', 'b', 'c'])
phi = Factor(['a', 'b'], [2, 2], range(4))
self.graph.add_factors(phi)
self.assertListEqual(self.graph.get_factors(), [phi])
def test_add_multiple_factors(self):
self.graph.add_nodes_from(['a', 'b', 'c'])
phi1 = Factor(['a', 'b'], [2, 2], range(4))
phi2 = Factor(['b', 'c'], [2, 2], range(4))
self.graph.add_factors(phi1, phi2)
self.assertListEqual(self.graph.get_factors(), [phi1, phi2])
def test_remove_single_factor(self):
self.graph.add_nodes_from(['a', 'b', 'c'])
phi1 = Factor(['a', 'b'], [2, 2], range(4))
phi2 = Factor(['b', 'c'], [2, 2], range(4))
self.graph.add_factors(phi1, phi2)
self.graph.remove_factors(phi1)
self.assertListEqual(self.graph.get_factors(), [phi2])
def test_remove_multiple_factors(self):
self.graph.add_nodes_from(['a', 'b', 'c'])
phi1 = Factor(['a', 'b'], [2, 2], range(4))
phi2 = Factor(['b', 'c'], [2, 2], range(4))
self.graph.add_factors(phi1, phi2)
self.graph.remove_factors(phi1, phi2)
self.assertListEqual(self.graph.get_factors(), [])
def test_partition_function(self):
self.graph.add_nodes_from(['a', 'b', 'c'])
phi1 = Factor(['a', 'b'], [2, 2], range(4))
phi2 = Factor(['b', 'c'], [2, 2], range(4))
self.graph.add_factors(phi1, phi2)
self.graph.add_edges_from([('a', 'b'), ('b', 'c')])
self.assertEqual(self.graph.get_partition_function(), 22.0)
def test_partition_function_raises_error(self):
self.graph.add_nodes_from(['a', 'b', 'c', 'd'])
phi1 = Factor(['a', 'b'], [2, 2], range(4))
phi2 = Factor(['b', 'c'], [2, 2], range(4))
self.graph.add_factors(phi1, phi2)
self.assertRaises(ValueError,
self.graph.get_partition_function)
def tearDown(self):
del self.graph