本文整理汇总了Python中pyds.MassFunction.condition方法的典型用法代码示例。如果您正苦于以下问题:Python MassFunction.condition方法的具体用法?Python MassFunction.condition怎么用?Python MassFunction.condition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyds.MassFunction
的用法示例。
在下文中一共展示了MassFunction.condition方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: print
# 需要导入模块: from pyds import MassFunction [as 别名]
# 或者: from pyds.MassFunction import condition [as 别名]
print('\n=== frame of discernment, focal sets, and core ===')
print('frame of discernment of m_1 =', m1.frame())
print('focal sets of m_1 =', m1.focal())
print('core of m_1 =', m1.core())
print('combined core of m_1 and m_3 =', m1.core(m3))
print('\n=== Dempster\'s combination rule, unnormalized conjunctive combination (exact and approximate) ===')
print('Dempster\'s combination rule for m_1 and m_2 =', m1 & m2)
print('Dempster\'s combination rule for m_1 and m_2 (Monte-Carlo, importance sampling) =', m1.combine_conjunctive(m2, sample_count=1000, importance_sampling=True))
print('Dempster\'s combination rule for m_1, m_2, and m_3 =', m1.combine_conjunctive(m2, m3))
print('unnormalized conjunctive combination of m_1 and m_2 =', m1.combine_conjunctive(m2, normalization=False))
print('unnormalized conjunctive combination of m_1 and m_2 (Monte-Carlo) =', m1.combine_conjunctive(m2, normalization=False, sample_count=1000))
print('unnormalized conjunctive combination of m_1, m_2, and m_3 =', m1.combine_conjunctive(m2, m3, normalization=False))
print('\n=== normalized and unnormalized conditioning ===')
print('normalized conditioning of m_1 with {a, b} =', m1.condition({'a', 'b'}))
print('unnormalized conditioning of m_1 with {b, c} =', m1.condition({'b', 'c'}, normalization=False))
print('\n=== disjunctive combination rule (exact and approximate) ===')
print('disjunctive combination of m_1 and m_2 =', m1 | m2)
print('disjunctive combination of m_1 and m_2 (Monte-Carlo) =', m1.combine_disjunctive(m2, sample_count=1000))
print('disjunctive combination of m_1, m_2, and m_3 =', m1.combine_disjunctive(m2, m3))
print('\n=== weight of conflict ===')
print('weight of conflict between m_1 and m_2 =', m1.conflict(m2))
print('weight of conflict between m_1 and m_2 (Monte-Carlo) =', m1.conflict(m2, sample_count=1000))
print('weight of conflict between m_1, m_2, and m_3 =', m1.conflict(m2, m3))
print('\n=== pignistic transformation ===')
print('pignistic transformation of m_1 =', m1.pignistic())
print('pignistic transformation of m_2 =', m2.pignistic())
示例2: PyDSTest
# 需要导入模块: from pyds import MassFunction [as 别名]
# 或者: from pyds.MassFunction import condition [as 别名]
#.........这里部分代码省略.........
self.assertEqual(8, len(pl3))
for h, v in pl3.items():
self.assertEqual(self.m3.pl(h), v)
def test_from_pl(self):
self._assert_equal_belief(self.m1, MassFunction.from_pl(self.m1.pl()), 8)
self._assert_equal_belief(self.m2, MassFunction.from_pl(self.m2.pl()), 8)
self._assert_equal_belief(self.m3, MassFunction.from_pl(self.m3.pl()), 8)
def test_q(self):
# compute the commonality of a single hypothesis
self.assertEqual(0.8, self.m1.q('a'))
self.assertEqual(0.5, self.m1.q('b'))
self.assertEqual(0.4, self.m1.q('ad'))
self.assertEqual(0.3, self.m1.q('abcd'))
self.assertEqual(0.0, self.m3.q(''))
self.assertEqual(0.4, self.m3.q('a'))
self.assertEqual(0.3, self.m3.q('ac'))
# compute the entire commonality function
q2 = self.m2.q()
self.assertEqual(8, len(q2))
for h, v in q2.items():
self.assertEqual(self.m2.q(h), v)
q3 = self.m3.q()
self.assertEqual(8, len(q3))
for h, v in q3.items():
self.assertEqual(self.m3.q(h), v)
def test_from_q(self):
self._assert_equal_belief(self.m1, MassFunction.from_q(self.m1.q()), 8)
self._assert_equal_belief(self.m2, MassFunction.from_q(self.m2.q()), 8)
self._assert_equal_belief(self.m3, MassFunction.from_q(self.m3.q()), 8)
def test_condition(self):
m1 = self.m1.condition('ad')
self.assertEqual(0.5, m1['a'])
self.assertEqual(0.5, m1['ad'])
m1_un = self.m1.condition('ad', normalization=False)
self.assertEqual(0.2, m1_un[''])
self.assertEqual(0.4, m1_un['a'])
self.assertEqual(0.4, m1_un['ad'])
m3 = self.m3.condition('ac')
self.assertEqual(0.5, m3['ac'])
self.assertAlmostEqual(1.0 / 3.0, m3['c'])
self.assertAlmostEqual(1.0 / 6.0, m3['a'])
m3_un = self.m3.condition('ab', normalization=False)
self.assertAlmostEqual(0.6, m3_un[set()])
self.assertEqual(0.3, m3_un['a'])
self.assertEqual(0.1, m3_un['ab'])
def test_combine_conjunctive(self):
def test(m, empty_mass, places=10):
self.assertAlmostEqual(empty_mass, m[set()], places)
norm = 0.55 + empty_mass
self.assertAlmostEqual(0.15 / norm, m['a'], places)
self.assertAlmostEqual(0.25 / norm, m['b'], places)
self.assertAlmostEqual(0.06 / norm, m['c'], places)
self.assertAlmostEqual(0.09 / norm, m['ac'], places)
# normalized
test(self.m1 & self.m2, 0.0)
test(self.m1.combine_conjunctive(self.m2, sample_count=10000), 0.0, 1)
test(self.m1.combine_conjunctive(self.m2, sample_count=1000, importance_sampling=True), 0.0)
# unnormalized
test(self.m1.combine_conjunctive(self.m2, normalization=False), 0.45)
test(self.m1.combine_conjunctive(self.m2, normalization=False, sample_count=10000), 0.45, 2)
test(self.m1.combine_conjunctive(self.m2, normalization=False, sample_count=1000, importance_sampling=True), 0.45, 2) # ImpSam should be ignored
示例3: PyDSTest
# 需要导入模块: from pyds import MassFunction [as 别名]
# 或者: from pyds.MassFunction import condition [as 别名]
#.........这里部分代码省略.........
self.assertEqual(8, len(pl3))
for h, v in pl3.items():
self.assertEqual(self.m3.pl(h), v)
def test_from_pl(self):
self._assert_equal_belief(self.m1, MassFunction.from_pl(self.m1.pl()), 8)
self._assert_equal_belief(self.m2, MassFunction.from_pl(self.m2.pl()), 8)
self._assert_equal_belief(self.m3, MassFunction.from_pl(self.m3.pl()), 8)
def test_q(self):
# compute the commonality of a single hypothesis
self.assertEqual(0.8, self.m1.q('a'))
self.assertEqual(0.5, self.m1.q('b'))
self.assertEqual(0.4, self.m1.q('ad'))
self.assertEqual(0.3, self.m1.q('abcd'))
self.assertEqual(0.0, self.m3.q(''))
self.assertEqual(0.4, self.m3.q('a'))
self.assertEqual(0.3, self.m3.q('ac'))
# compute the entire commonality function
q2 = self.m2.q()
self.assertEqual(8, len(q2))
for h, v in q2.items():
self.assertEqual(self.m2.q(h), v)
q3 = self.m3.q()
self.assertEqual(8, len(q3))
for h, v in q3.items():
self.assertEqual(self.m3.q(h), v)
def test_from_q(self):
self._assert_equal_belief(self.m1, MassFunction.from_q(self.m1.q()), 8)
self._assert_equal_belief(self.m2, MassFunction.from_q(self.m2.q()), 8)
self._assert_equal_belief(self.m3, MassFunction.from_q(self.m3.q()), 8)
def test_condition(self):
m1 = self.m1.condition('ad')
self.assertEqual(0.5, m1['a'])
self.assertEqual(0.5, m1['ad'])
m1_un = self.m1.condition('ad', normalization=False)
self.assertEqual(0.2, m1_un[''])
self.assertEqual(0.4, m1_un['a'])
self.assertEqual(0.4, m1_un['ad'])
m3 = self.m3.condition('ac')
self.assertEqual(0.5, m3['ac'])
self.assertAlmostEqual(1.0 / 3.0, m3['c'])
self.assertAlmostEqual(1.0 / 6.0, m3['a'])
m3_un = self.m3.condition('ab', normalization=False)
self.assertAlmostEqual(0.6, m3_un[set()])
self.assertEqual(0.3, m3_un['a'])
self.assertEqual(0.1, m3_un['ab'])
def test_combine_conjunctive(self):
def test(m, empty_mass, places=10):
self.assertAlmostEqual(empty_mass, m[set()], places)
norm = 0.55 + empty_mass
self.assertAlmostEqual(0.15 / norm, m['a'], places)
self.assertAlmostEqual(0.25 / norm, m['b'], places)
self.assertAlmostEqual(0.06 / norm, m['c'], places)
self.assertAlmostEqual(0.09 / norm, m['ac'], places)
# normalized
test(self.m1 & self.m2, 0.0)
test(self.m1.combine_conjunctive(self.m2, sample_count=10000), 0.0, 1)
test(self.m1.combine_conjunctive(self.m2, sample_count=1000, importance_sampling=True), 0.0)
# unnormalized
test(self.m1.combine_conjunctive(self.m2, normalization=False), 0.45)
test(self.m1.combine_conjunctive(self.m2, normalization=False, sample_count=10000), 0.45, 2)
test(self.m1.combine_conjunctive(self.m2, normalization=False, sample_count=1000, importance_sampling=True), 0.45, 2) # ImpSam should be ignored