本文整理汇总了Python中pyds.MassFunction.core方法的典型用法代码示例。如果您正苦于以下问题:Python MassFunction.core方法的具体用法?Python MassFunction.core怎么用?Python MassFunction.core使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyds.MassFunction
的用法示例。
在下文中一共展示了MassFunction.core方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: print
# 需要导入模块: from pyds import MassFunction [as 别名]
# 或者: from pyds.MassFunction import core [as 别名]
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))
print('\n=== disjunctive combination rule (exact and approximate) ===')
示例2: PyDSTest
# 需要导入模块: from pyds import MassFunction [as 别名]
# 或者: from pyds.MassFunction import core [as 别名]
#.........这里部分代码省略.........
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):
self.assertAlmostEqual(0.3 * 0.8 / (1 - 0.7 * 0.2), m['ab'], places)
self.assertAlmostEqual(0.3 * 0.2 / (1 - 0.7 * 0.2), m['a'], places)
self.assertAlmostEqual(0.7 * 0.8 / (1 - 0.7 * 0.2), m['b'], places)
pl = [('a', 0.3), ('b', 0.8), ('c', 0.0)]
test(MassFunction.gbt(pl), 10)
test(MassFunction.gbt(pl, sample_count=10000), 2)
#pl = [('a', 0.3), ('b', 0.8), ('c', 0.0), ('d', 1.0)]
pl = {'a':0.3, 'b':0.8, 'c':0.0, 'd':1.0}
self._assert_equal_belief(MassFunction.gbt(pl), MassFunction.gbt(pl, sample_count=10000), 2)
def test_frame(self):
self.assertEqual({'a', 'b', 'c', 'd'}, self.m1.frame())
self.assertEqual({'a', 'b', 'c'}, self.m2.frame())
self.assertEqual(set(), MassFunction().frame())
def test_singletons(self):
self.assertSetEqual({frozenset('a'), frozenset('b'), frozenset('c'), frozenset('d')}, self.m1.singletons())
def test_focal(self):
self.assertEqual(4, len(list(self.m1.focal())))
for f in self.m1.focal():
self.assertTrue(f in self.m1, f)
self.m1[{'b'}] = 0
self.assertEqual(3, len(self.m1.focal()))
self.assertFalse({'b'} in self.m1.focal())
def test_core(self):
self.assertEqual({'a', 'b', 'c', 'd'}, self.m1.core())
self.m1[{'a', 'b', 'c', 'd'}] = 0
self.assertEqual({'a', 'b', 'd'}, self.m1.core())
self.assertEqual(set(), MassFunction().core())
# test combined core
self.assertEqual({'a', 'b'}, self.m1.core(self.m2))
def test_all(self):
all = {frozenset(), frozenset('a'), frozenset('b'), frozenset('ab')}
self.assertSetEqual(all, set(MassFunction({'a':0.1, 'b':0}).all()))
def test_max_bel(self):
self.assertEqual(frozenset('a'), self.m1.max_bel())
self.assertEqual(frozenset('c'), self.m3.max_bel())
self.assertTrue(MassFunction({('ab'):1}).max_bel() in {frozenset('a'), frozenset('b')})
def test_max_pl(self):
self.assertEqual(frozenset('a'), self.m1.max_pl())
self.assertEqual(frozenset('c'), self.m3.max_pl())
self.assertTrue(MassFunction({('ab'):0.8, 'c':0.2}).max_pl() in {frozenset('a'), frozenset('b')})
def test_combine_gbt(self):
pl = [('b', 0.8), ('c', 0.5)]
correct = self.m1.combine_conjunctive(MassFunction.gbt(pl))
self._assert_equal_belief(correct, self.m1.combine_gbt(pl), 10)
self._assert_equal_belief(self.m1.combine_gbt(pl), self.m1.combine_gbt(pl, sample_count=10000), 1)
self._assert_equal_belief(self.m2.combine_gbt(pl), self.m2.combine_gbt(pl, sample_count=10000), 1)
# Bayesian special case
p_prior = self.m1.pignistic()
p_posterior = p_prior.combine_gbt(pl)
p_correct = MassFunction()
for s, l in pl:
示例3: PyDSTest
# 需要导入模块: from pyds import MassFunction [as 别名]
# 或者: from pyds.MassFunction import core [as 别名]
#.........这里部分代码省略.........
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):
self.assertAlmostEqual(0.3 * 0.8 / (1 - 0.7 * 0.2), m['ab'], places)
self.assertAlmostEqual(0.3 * 0.2 / (1 - 0.7 * 0.2), m['a'], places)
self.assertAlmostEqual(0.7 * 0.8 / (1 - 0.7 * 0.2), m['b'], places)
pl = [('a', 0.3), ('b', 0.8), ('c', 0.0)]
test(MassFunction.gbt(pl), 10)
test(MassFunction.gbt(pl, sample_count=10000), 2)
#pl = [('a', 0.3), ('b', 0.8), ('c', 0.0), ('d', 1.0)]
pl = {'a':0.3, 'b':0.8, 'c':0.0, 'd':1.0}
self._assert_equal_belief(MassFunction.gbt(pl), MassFunction.gbt(pl, sample_count=10000), 2)
def test_frame(self):
self.assertEqual({'a', 'b', 'c', 'd'}, self.m1.frame())
self.assertEqual({'a', 'b', 'c'}, self.m2.frame())
self.assertEqual(set(), MassFunction().frame())
def test_focal(self):
self.assertEqual(4, len(list(self.m1.focal())))
for f in self.m1.focal():
self.assertTrue(f in self.m1, f)
self.m1[{'b'}] = 0
self.assertEqual(3, len(self.m1.focal()))
self.assertFalse({'b'} in self.m1.focal())
def test_core(self):
self.assertEqual({'a', 'b', 'c', 'd'}, self.m1.core())
self.m1[{'a', 'b', 'c', 'd'}] = 0
self.assertEqual({'a', 'b', 'd'}, self.m1.core())
self.assertEqual(set(), MassFunction().core())
# test combined core
self.assertEqual({'a', 'b'}, self.m1.core(self.m2))
def test_combine_gbt(self):
pl = [('b', 0.8), ('c', 0.5)]
correct = self.m1.combine_conjunctive(MassFunction.gbt(pl))
self._assert_equal_belief(correct, self.m1.combine_gbt(pl), 10)
self._assert_equal_belief(self.m1.combine_gbt(pl), self.m1.combine_gbt(pl, sample_count=10000), 1)
self._assert_equal_belief(self.m2.combine_gbt(pl), self.m2.combine_gbt(pl, sample_count=10000), 1)
# Bayesian special case
p_prior = self.m1.pignistic()
p_posterior = p_prior.combine_gbt(pl)
p_correct = MassFunction()
for s, l in pl:
p_correct[(s,)] = l * p_prior[(s,)]
p_correct.normalize()
self._assert_equal_belief(p_correct, p_posterior, 10)
def test_is_probabilistic(self):
self.assertFalse(self.m1.is_probabilistic())
self.assertTrue(self.m1.pignistic().is_probabilistic())
for p in self.m1.sample_probability_distributions(100):
self.assertTrue(p.is_probabilistic())
def test_sample_probability_distributions(self):
for p in self.m1.sample_probability_distributions(100):
self.assertTrue(self.m1.is_compatible(p))
def test_powerset(self):
s = range(2)
p = set(powerset(s))
self.assertEqual(4, len(p))
self.assertTrue(set() in p)
self.assertTrue({0} in p)
self.assertTrue({1} in p)
self.assertTrue({0, 1} in p)
self.assertEqual(2**6, len(list(powerset(range(6)))))
def test_gbt_m(self):
likelihoods = [('a', 0.3), ('b', 0.8), ('c', 0.0), ('d', 0.5)] # likelihoods as a list
m = MassFunction.gbt(likelihoods)
for h, v in m.items():
self.assertAlmostEqual(v, gbt_m(h, likelihoods), 8)
def test_gbt_bel(self):
likelihoods = {'a':0.3, 'b':0.8, 'c':0.0, 'd':0.5}
m = MassFunction.gbt(likelihoods)
for h in m:
self.assertAlmostEqual(m.bel(h), gbt_bel(h, likelihoods), 8)
def test_gbt_pl(self):
likelihoods = {'a':0.3, 'b':0.8, 'c':0.0, 'd':0.5}
m = MassFunction.gbt(likelihoods)
for h in m:
self.assertAlmostEqual(m.pl(h), gbt_pl(h, likelihoods), 8)
def test_gbt_q(self):
likelihoods = {'a':0.3, 'b':0.8, 'c':0.0, 'd':0.5}
m = MassFunction.gbt(likelihoods)
for h in m:
self.assertAlmostEqual(m.q(h), gbt_q(h, likelihoods), 8)