本文整理汇总了Python中pyds.MassFunction.frame方法的典型用法代码示例。如果您正苦于以下问题:Python MassFunction.frame方法的具体用法?Python MassFunction.frame怎么用?Python MassFunction.frame使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyds.MassFunction
的用法示例。
在下文中一共展示了MassFunction.frame方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: print
# 需要导入模块: from pyds import MassFunction [as 别名]
# 或者: from pyds.MassFunction import frame [as 别名]
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))
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))
示例2: PyDSTest
# 需要导入模块: from pyds import MassFunction [as 别名]
# 或者: from pyds.MassFunction import frame [as 别名]
#.........这里部分代码省略.........
self.assertAlmostEqual(0.05, m['acd'], places)
self.assertAlmostEqual(0.3, m['abcd'], places)
test(self.m1 | self.m2, 10)
test(self.m1.combine_disjunctive(self.m2, sample_count=10000), 2)
# combine multiple mass functions
m_single = self.m1.combine_disjunctive(self.m1).combine_disjunctive(self.m2)
m_multi = self.m1.combine_disjunctive(self.m1, self.m2)
for h, v in m_single.items():
self.assertAlmostEqual(v, m_multi[h])
def test_conflict(self):
self.assertEqual(-log(0.55, 2), self.m1.conflict(self.m2));
self.assertAlmostEqual(-log(0.55, 2), self.m1.conflict(self.m2, sample_count=1000), 1);
self.assertEqual(float('inf'), self.m1.conflict(MassFunction({'e': 1})));
def test_normalize(self):
v = self.m1['a']
del self.m1['a']
self.m1.normalize()
self.assertAlmostEqual(0.2 / (1 - v), self.m1['b'])
self.assertAlmostEqual(0.1 / (1 - v), self.m1['ad'])
self.assertAlmostEqual(0.3 / (1 - v), self.m1['abcd'])
self.assertEqual(0, len(MassFunction().normalize()))
def test_multiple_dimensions(self):
md1 = MassFunction({(('a', 1), ('b', 2)): 0.8, (('a', 1),):0.2})
md2 = MassFunction({(('a', 1), ('b', 2), ('c', 1)): 1.0})
md12 = md1 & md2
self.assertAlmostEqual(0.2, md12[{('a', 1)}])
self.assertAlmostEqual(0.8, md12[{('a', 1), ('b', 2)}])
def test_map(self):
# vacuous extension
frame = {1, 2}
extended = self.m3.map(lambda h: product(h, frame))
result = MassFunction({():0.4, (('c', 1), ('c', 2)):0.2, (('a', 1), ('a', 2), ('c', 1), ('c', 2)):0.3, (('a', 1), ('a', 2), ('b', 1), ('b', 2)):0.1})
self.assertEqual(result, extended)
# projection
projected = extended.map(lambda h: (t[0] for t in h))
self.assertEqual(self.m3, projected)
def test_pignistic(self):
p1 = self.m1.pignistic()
self.assertEqual(0.525, p1['a'])
self.assertEqual(0.275, p1['b'])
self.assertEqual(0.075, p1['c'])
self.assertEqual(0.125, p1['d'])
p3 = self.m3.pignistic()
self.assertEqual(0.2 / 0.6, p3['a'])
self.assertEqual(0.05 / 0.6, p3['b'])
self.assertEqual(0.35 / 0.6, p3['c'])
def test_local_conflict(self):
c = 0.5 * log(1 / 0.5, 2) + 0.2 * log(1 / 0.2, 2) + 0.3 * log(2 / 0.3, 2)
self.assertEqual(c, self.m2.local_conflict())
self.assertTrue(isnan(self.m3.local_conflict()))
# pignistic entropy
h = -0.125 * log(0.125, 2) - 0.075 * log(0.075, 2) - 0.275 * log(0.275, 2) - 0.525 * log(0.525, 2)
self.assertAlmostEqual(h, self.m1.pignistic().local_conflict())
def test_hartley_measure(self):
self.assertEqual(0.1 + 0.3 * log(4, 2), self.m1.hartley_measure())
def test_norm(self):
self.assertEqual(0, self.m1.norm(self.m1))
self.assertEqual(0, self.m1.norm(self.m1, p = 1))
示例3: PyDSTest
# 需要导入模块: from pyds import MassFunction [as 别名]
# 或者: from pyds.MassFunction import frame [as 别名]
#.........这里部分代码省略.........
self.assertAlmostEqual(0.05, m['acd'], places)
self.assertAlmostEqual(0.3, m['abcd'], places)
test(self.m1 | self.m2, 10)
test(self.m1.combine_disjunctive(self.m2, sample_count=10000), 2)
# combine multiple mass functions
m_single = self.m1.combine_disjunctive(self.m1).combine_disjunctive(self.m2)
m_multi = self.m1.combine_disjunctive(self.m1, self.m2)
for h, v in m_single.items():
self.assertAlmostEqual(v, m_multi[h])
def test_conflict(self):
self.assertEqual(-log(0.55, 2), self.m1.conflict(self.m2));
self.assertAlmostEqual(-log(0.55, 2), self.m1.conflict(self.m2, sample_count=1000), 1);
self.assertEqual(float('inf'), self.m1.conflict(MassFunction({'e': 1})));
def test_normalize(self):
v = self.m1['a']
del self.m1['a']
self.m1.normalize()
self.assertAlmostEqual(0.2 / (1 - v), self.m1['b'])
self.assertAlmostEqual(0.1 / (1 - v), self.m1['ad'])
self.assertAlmostEqual(0.3 / (1 - v), self.m1['abcd'])
self.assertEqual(0, len(MassFunction().normalize()))
def test_multiple_dimensions(self):
md1 = MassFunction({(('a', 1), ('b', 2)): 0.8, (('a', 1),):0.2})
md2 = MassFunction({(('a', 1), ('b', 2), ('c', 1)): 1.0})
md12 = md1 & md2
self.assertAlmostEqual(0.2, md12[{('a', 1)}])
self.assertAlmostEqual(0.8, md12[{('a', 1), ('b', 2)}])
def test_map(self):
# vacuous extension
frame = {1, 2}
extended = self.m3.map(lambda h: product(h, frame))
result = MassFunction({():0.4, (('c', 1), ('c', 2)):0.2, (('a', 1), ('a', 2), ('c', 1), ('c', 2)):0.3, (('a', 1), ('a', 2), ('b', 1), ('b', 2)):0.1})
self.assertEqual(result, extended)
# projection
projected = extended.map(lambda h: (t[0] for t in h))
self.assertEqual(self.m3, projected)
def test_pignistic(self):
p1 = self.m1.pignistic()
self.assertEqual(0.525, p1['a'])
self.assertEqual(0.275, p1['b'])
self.assertEqual(0.075, p1['c'])
self.assertEqual(0.125, p1['d'])
p3 = self.m3.pignistic()
self.assertEqual(0.2 / 0.6, p3['a'])
self.assertEqual(0.05 / 0.6, p3['b'])
self.assertEqual(0.35 / 0.6, p3['c'])
def test_local_conflict(self):
c = 0.5 * log(1 / 0.5, 2) + 0.2 * log(1 / 0.2, 2) + 0.3 * log(2 / 0.3, 2)
self.assertEqual(c, self.m2.local_conflict())
self.assertTrue(isnan(self.m3.local_conflict()))
# pignistic entropy
h = -0.125 * log(0.125, 2) - 0.075 * log(0.075, 2) - 0.275 * log(0.275, 2) - 0.525 * log(0.525, 2)
self.assertAlmostEqual(h, self.m1.pignistic().local_conflict())
def test_norm(self):
self.assertEqual(0, self.m1.norm(self.m1))
self.assertEqual(0, self.m1.norm(self.m1, p = 1))
m3 = MassFunction({'e':1.0})
len_m1 = sum([v**2 for v in self.m1.values()])
self.assertEqual((1 + len_m1)**0.5, self.m1.norm(m3))