本文整理汇总了Python中pyds.MassFunction.q方法的典型用法代码示例。如果您正苦于以下问题:Python MassFunction.q方法的具体用法?Python MassFunction.q怎么用?Python MassFunction.q使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyds.MassFunction
的用法示例。
在下文中一共展示了MassFunction.q方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: print
# 需要导入模块: from pyds import MassFunction [as 别名]
# 或者: from pyds.MassFunction import q [as 别名]
print('=== creating mass functions ===')
m1 = MassFunction({'ab':0.6, 'bc':0.3, 'a':0.1, 'ad':0.0}) # using a dictionary
print('m_1 =', m1)
m2 = MassFunction([({'a', 'b', 'c'}, 0.2), ({'a', 'c'}, 0.5), ({'c'}, 0.3)]) # using a list of tuples
print('m_2 =', m2)
m3 = MassFunction()
m3['bc'] = 0.8
m3[{}] = 0.2
print('m_3 =', m3, ('(unnormalized mass function)'))
print('\n=== belief, plausibility, and commonality ===')
print('bel_1({a, b}) =', m1.bel({'a', 'b'}))
print('pl_1({a, b}) =', m1.pl({'a', 'b'}))
print('q_1({a, b}) =', m1.q({'a', 'b'}))
print('bel_1 =', m1.bel()) # entire belief function
print('bel_3 =', m3.bel())
print('m_3 from bel_3 =', MassFunction.from_bel(m3.bel())) # construct a mass function from a belief function
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))
示例2: PyDSTest
# 需要导入模块: from pyds import MassFunction [as 别名]
# 或者: from pyds.MassFunction import q [as 别名]
class PyDSTest(unittest.TestCase):
def setUp(self):
self.m1 = MassFunction({'a':0.4, 'b':0.2, 'ad':0.1, 'abcd':0.3})
self.m2 = MassFunction({'b':0.5, 'c':0.2, 'ac':0.3, 'a':0.0})
self.m3 = MassFunction({():0.4, 'c':0.2, 'ac':0.3, 'ab':0.1}) # unnormalized mass function
random.seed(0) # make tests deterministic
def _assert_equal_belief(self, m1, m2, places=8):
for h in m1.focal() | m2.focal():
self.assertAlmostEqual(m1[h], m2[h], places)
def test_init(self):
"""Test equivalence of different mass function initialization methods."""
m1 = MassFunction([(('a',), 0.4), (('b',), 0.2), (('a', 'd'), 0.1), (('a', 'b', 'c', 'd'), 0.3)])
self.assertEqual(self.m1, m1)
m1 = MassFunction([('a', 0.4), ('b', 0.2), ('ad', 0.1), ('abcd', 0.3)])
self.assertEqual(self.m1, m1)
def test_items(self):
self.assertEqual(0.0, self.m1['x'])
self.m1['ad'] += 0.5
self.assertEqual(0.6, self.m1['ad'])
def test_copy(self):
c = self.m1.copy()
for k in self.m1.keys():
self.assertEqual(self.m1.bel(k), c.bel(k))
c['a'] = 0.3
# assert that the original object remains unchanged
self.assertEqual(0.4, self.m1['a'])
def test_del(self):
del self.m1['a']
self.assertEqual(3, len(self.m1))
self.assertEqual(0.0, self.m1['a'])
def test_bel(self):
# compute the belief of a single hypothesis
self.assertEqual(0.4, self.m1.bel('a'))
self.assertEqual(0.5, self.m1.bel('ad'))
self.assertEqual(1, self.m1.bel('abcd'))
self.assertEqual(0.0, self.m3.bel(''))
self.assertEqual(0.0, self.m3.bel('a'))
self.assertEqual(0.5, self.m3.bel('ac'))
self.assertAlmostEqual(0.6, self.m3.bel('abc'))
# compute the entire belief function
bel2 = self.m2.bel()
self.assertEqual(8, len(bel2))
for h, v in bel2.items():
self.assertEqual(self.m2.bel(h), v)
bel3 = self.m3.bel()
self.assertEqual(8, len(bel3))
for h, v in bel3.items():
self.assertEqual(self.m3.bel(h), v)
def test_from_bel(self):
self._assert_equal_belief(self.m1, MassFunction.from_bel(self.m1.bel()), 8)
self._assert_equal_belief(self.m2, MassFunction.from_bel(self.m2.bel()), 8)
self._assert_equal_belief(self.m3, MassFunction.from_bel(self.m3.bel()), 8)
def test_pl(self):
# compute the plausibility of a single hypothesis
self.assertEqual(0.8, self.m1.pl('a'))
self.assertEqual(0.5, self.m1.pl('b'))
self.assertEqual(0.8, self.m1.pl('ad'))
self.assertEqual(1, self.m1.pl('abcd'))
self.assertEqual(0.0, self.m3.pl(''))
self.assertAlmostEqual(0.1, self.m3.pl('b'))
self.assertAlmostEqual(0.6, self.m3.pl('abc'))
# compute the entire plausibility function
pl2 = self.m2.pl()
self.assertEqual(8, len(pl2))
for h, v in pl2.items():
self.assertEqual(self.m2.pl(h), v)
pl3 = self.m3.pl()
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()
#.........这里部分代码省略.........
示例3: PyDSTest
# 需要导入模块: from pyds import MassFunction [as 别名]
# 或者: from pyds.MassFunction import q [as 别名]
class PyDSTest(unittest.TestCase):
def setUp(self):
self.m1 = MassFunction({'a':0.4, 'b':0.2, 'ad':0.1, 'abcd':0.3})
self.m2 = MassFunction({'b':0.5, 'c':0.2, 'ac':0.3, 'a':0.0})
self.m3 = MassFunction({():0.4, 'c':0.2, 'ac':0.3, 'ab':0.1}) # unnormalized mass function
random.seed(0) # make tests deterministic
def _assert_equal_belief(self, m1, m2, places):
for h in m1.focal() | m2.focal():
self.assertAlmostEqual(m1[h], m2[h], places)
def test_init(self):
"""Test equivalence of different mass function initialization methods."""
m1 = MassFunction([(('a',), 0.4), (('b',), 0.2), (('a', 'd'), 0.1), (('a', 'b', 'c', 'd'), 0.3)])
self.assertEqual(self.m1, m1)
m1 = MassFunction([('a', 0.4), ('b', 0.2), ('ad', 0.1), ('abcd', 0.3)])
self.assertEqual(self.m1, m1)
def test_items(self):
self.assertEqual(0.0, self.m1['x'])
self.m1['ad'] += 0.5
self.assertEqual(0.6, self.m1['ad'])
def test_copy(self):
c = self.m1.copy()
for k in self.m1.keys():
self.assertEqual(self.m1.bel(k), c.bel(k))
c['a'] = 0.3
# assert that the original object remains unchanged
self.assertEqual(0.4, self.m1['a'])
def test_del(self):
del self.m1['a']
self.assertEqual(3, len(self.m1))
self.assertEqual(0.0, self.m1['a'])
def test_bel(self):
# compute the belief of a single hypothesis
self.assertEqual(0.4, self.m1.bel('a'))
self.assertEqual(0.5, self.m1.bel('ad'))
self.assertEqual(1, self.m1.bel('abcd'))
self.assertEqual(0.0, self.m3.bel(''))
self.assertEqual(0.0, self.m3.bel('a'))
self.assertEqual(0.5, self.m3.bel('ac'))
self.assertAlmostEqual(0.6, self.m3.bel('abc'))
# compute the entire belief function
bel2 = self.m2.bel()
self.assertEqual(8, len(bel2))
for h, v in bel2.items():
self.assertEqual(self.m2.bel(h), v)
bel3 = self.m3.bel()
self.assertEqual(8, len(bel3))
for h, v in bel3.items():
self.assertEqual(self.m3.bel(h), v)
def test_from_bel(self):
self._assert_equal_belief(self.m1, MassFunction.from_bel(self.m1.bel()), 8)
self._assert_equal_belief(self.m2, MassFunction.from_bel(self.m2.bel()), 8)
self._assert_equal_belief(self.m3, MassFunction.from_bel(self.m3.bel()), 8)
def test_pl(self):
# compute the plausibility of a single hypothesis
self.assertEqual(0.8, self.m1.pl('a'))
self.assertEqual(0.5, self.m1.pl('b'))
self.assertEqual(0.8, self.m1.pl('ad'))
self.assertEqual(1, self.m1.pl('abcd'))
self.assertEqual(0.0, self.m3.pl(''))
self.assertAlmostEqual(0.1, self.m3.pl('b'))
self.assertAlmostEqual(0.6, self.m3.pl('abc'))
# compute the entire plausibility function
pl2 = self.m2.pl()
self.assertEqual(8, len(pl2))
for h, v in pl2.items():
self.assertEqual(self.m2.pl(h), v)
pl3 = self.m3.pl()
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()
#.........这里部分代码省略.........