本文整理汇总了Python中pyds.MassFunction.local_conflict方法的典型用法代码示例。如果您正苦于以下问题:Python MassFunction.local_conflict方法的具体用法?Python MassFunction.local_conflict怎么用?Python MassFunction.local_conflict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyds.MassFunction
的用法示例。
在下文中一共展示了MassFunction.local_conflict方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: print
# 需要导入模块: from pyds import MassFunction [as 别名]
# 或者: from pyds.MassFunction import local_conflict [as 别名]
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())
print('pignistic transformation of m_3 =', m3.pignistic())
print('\n=== local conflict uncertainty measure ===')
print('local conflict of m_1 =', m1.local_conflict())
print('entropy of the pignistic transformation of m_3 =', m3.pignistic().local_conflict())
print('\n=== sampling ===')
print('random samples drawn from m_1 =', m1.sample(5, quantization=False))
print('sample frequencies of m_1 =', m1.sample(1000, quantization=False, as_dict=True))
print('quantization of m_1 =', m1.sample(1000, as_dict=True))
print('\n=== map: vacuous extension and projection ===')
extended = m1.map(lambda h: product(h, {1, 2}))
print('vacuous extension of m_1 to {1, 2} =', extended)
projected = extended.map(lambda h: (t[0] for t in h))
print('project m_1 back to its original frame =', projected)
示例2: PyDSTest
# 需要导入模块: from pyds import MassFunction [as 别名]
# 或者: from pyds.MassFunction import local_conflict [as 别名]
#.........这里部分代码省略.........
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))
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))
def test_prune(self):
self.assertTrue('a' in self.m2)
pruned = self.m2.prune()
self.assertFalse('a' in pruned)
self._assert_equal_belief(self.m2, pruned, 10)
def test_sample(self):
sample_count = 1000
samples_ran = self.m1.sample(sample_count, quantization=False)
samples_ml = self.m1.sample(sample_count, quantization=True)
self.assertEqual(sample_count, len(samples_ran))
self.assertEqual(sample_count, len(samples_ml))
for h, v in self.m1.items():
self.assertAlmostEqual(v, float(samples_ran.count(h)) / sample_count, places=1)
self.assertAlmostEqual(v, float(samples_ml.count(h)) / sample_count, places=20)
示例3: PyDSTest
# 需要导入模块: from pyds import MassFunction [as 别名]
# 或者: from pyds.MassFunction import local_conflict [as 别名]
#.........这里部分代码省略.........
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))
def test_prune(self):
self.assertTrue('a' in self.m2)
pruned = self.m2.prune()
self.assertFalse('a' in pruned)
self._assert_equal_belief(self.m2, pruned, 10)
def test_sample(self):
sample_count = 1000
samples_ran = self.m1.sample(sample_count, quantization=False)
samples_ml = self.m1.sample(sample_count, quantization=True)
self.assertEqual(sample_count, len(samples_ran))
self.assertEqual(sample_count, len(samples_ml))
for h, v in self.m1.items():
self.assertAlmostEqual(v, float(samples_ran.count(h)) / sample_count, places=1)
self.assertAlmostEqual(v, float(samples_ml.count(h)) / sample_count, places=20)
self.assertEqual(0, len(MassFunction().sample(sample_count)))
def test_markov(self):