本文整理汇总了Python中pyds.MassFunction.prune方法的典型用法代码示例。如果您正苦于以下问题:Python MassFunction.prune方法的具体用法?Python MassFunction.prune怎么用?Python MassFunction.prune使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyds.MassFunction
的用法示例。
在下文中一共展示了MassFunction.prune方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: PyDSTest
# 需要导入模块: from pyds import MassFunction [as 别名]
# 或者: from pyds.MassFunction import prune [as 别名]
#.........这里部分代码省略.........
# 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)
self.assertEqual(0, len(MassFunction().sample(sample_count)))
def test_markov(self):
def test(m, places):
self.assertAlmostEqual(0.4 * 0.8, m[(4, 6)], places)
self.assertAlmostEqual(0.4 * 0.2, m[(5,)], places)
self.assertAlmostEqual(0.6 * 0.2 * 0.2, m[(0, 1)], places)
self.assertAlmostEqual(0.6 * 0.2 * 0.8, m[(-1, 1)], places)
self.assertAlmostEqual(0.6 * 0.2 * 0.8, m[(0, 2)], places)
self.assertAlmostEqual(0.6 * 0.8 * 0.8, m[(-1, 0, 1, 2)], places)
m = MassFunction([((0, 1), 0.6), ((5,), 0.4)])
transition_model = lambda s: MassFunction([((s - 1, s + 1), 0.8), ((s,), 0.2)])
transition_model_mc = lambda s, n: transition_model(s).sample(n)
test(m.markov(transition_model), 10)
test(m.markov(transition_model_mc, sample_count=10000), 2)
def test_gbt(self):
def test(m, places):
示例2: PyDSTest
# 需要导入模块: from pyds import MassFunction [as 别名]
# 或者: from pyds.MassFunction import prune [as 别名]
#.........这里部分代码省略.........
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):
def test(m, places):
self.assertAlmostEqual(0.4 * 0.8, m[(4, 6)], places)
self.assertAlmostEqual(0.4 * 0.2, m[(5,)], places)
self.assertAlmostEqual(0.6 * 0.2 * 0.2, m[(0, 1)], places)
self.assertAlmostEqual(0.6 * 0.2 * 0.8, m[(-1, 1)], places)
self.assertAlmostEqual(0.6 * 0.2 * 0.8, m[(0, 2)], places)
self.assertAlmostEqual(0.6 * 0.8 * 0.8, m[(-1, 0, 1, 2)], places)
m = MassFunction([((0, 1), 0.6), ((5,), 0.4)])
transition_model = lambda s: MassFunction([((s - 1, s + 1), 0.8), ((s,), 0.2)])
transition_model_mc = lambda s, n: transition_model(s).sample(n)
test(m.markov(transition_model), 10)
test(m.markov(transition_model_mc, sample_count=10000), 2)
def test_gbt(self):
def test(m, places):