本文整理汇总了Python中pyds.MassFunction类的典型用法代码示例。如果您正苦于以下问题:Python MassFunction类的具体用法?Python MassFunction怎么用?Python MassFunction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MassFunction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_gbt
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}
self._assert_equal_belief(MassFunction.gbt(pl), MassFunction.gbt(pl, sample_count=10000), 1)
示例2: test_markov
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)
示例3: test_combine_gbt
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)
示例4: test_combine_cautious
def test_combine_cautious(self):
"""
Examples from:
T. Denoeux (2008), "Conjunctive and disjunctive combination of belief functions induced by nondistinct bodies of evidence",
Artificial Intelligence 172, 234-264.
"""
m1 = MassFunction({'ab':0.3, 'bc':0.5, 'abc':0.2})
m2 = MassFunction({'b':0.3, 'bc':0.4, 'abc':0.3})
m = m1.combine_cautious(m2)
self.assertAlmostEqual(0.0, m[''])
self.assertAlmostEqual(0.0, m['a'])
self.assertAlmostEqual(0.6, m['b'])
self.assertAlmostEqual(0.12, m['ab'])
self.assertAlmostEqual(0.0, m['c'])
self.assertAlmostEqual(0.0, m['ac'])
self.assertAlmostEqual(0.2, m['bc'])
self.assertAlmostEqual(0.08, m['abc'])
示例5: test_from_samples
def test_from_samples(self):
"""
Example 1 (default) and example 7 (ordered) from:
T. Denoeux (2006), "Constructing belief functions from sample data using multinomial confidence regions",
International Journal of Approximate Reasoning 42, 228-252.
Example 6 (consonant) from:
A. Aregui, T. Denoeux (2008), "Constructing consonant belief functions from sample data using confidence sets of pignistic probabilities",
International Journal of Approximate Reasoning 49, 575-594.
"""
precipitation_data = {1:48, 2:17, 3:19, 4:11, 5:6, 6:9}
failure_mode_data = {1:5, 2:11, 3:19, 4:30, 5:58, 6:67, 7:92, 8:118, 9:173, 10:297}
psych_data = {1:91, 2:49, 3:37, 4:43}
# default
m = MassFunction.from_samples(psych_data, 0.05, mode='default')
p_lower, p_upper = MassFunction._confidence_intervals(psych_data, 0.05)
def p_lower_set(hs):
l = u = 0
for h in psych_data.keys():
if h in hs:
l += p_lower[h]
else:
u += p_upper[h]
return max(l, 1 - u)
bel_sum = 0
for h in m.all():
bel = m.bel(h)
bel_sum += bel
self.assertLessEqual(bel, p_lower_set(h)) # constraint (24)
self.assertEqual(1, sum(m.values())) # constraint (25)
self.assertGreaterEqual(min(m.values()), 0) # constraint (26)
self.assertGreaterEqual(bel_sum, 6.23) # optimization criterion
# ordered
m = MassFunction.from_samples(precipitation_data, 0.05, mode='ordered')
self.assertAlmostEqual(0.32, m[(1,)], 2)
self.assertAlmostEqual(0.085, m[(2,)], 3)
self.assertAlmostEqual(0.098, m[(3,)], 3)
self.assertAlmostEqual(0.047, m[(4,)], 3)
self.assertAlmostEqual(0.020, m[(5,)], 3)
self.assertAlmostEqual(0.035, m[(6,)], 3)
self.assertAlmostEqual(0.13, m[range(1, 5)], 2)
self.assertAlmostEqual(0.11, m[range(1, 6)], 2)
self.assertAlmostEqual(0.012, m[range(2, 6)], 2)
self.assertAlmostEqual(0.14, m[range(2, 7)], 2)
# consonant
poss = {1: 0.171, 2: 0.258, 3: 0.353, 4: 0.462, 5: 0.688, 6: 0.735, 7: 0.804, 8: 0.867, 9: 0.935, 10: 1.0} # 8: 0.873
m = MassFunction.from_samples(failure_mode_data, 0.1, mode='consonant')
self._assert_equal_belief(MassFunction.from_possibility(poss), m, 1)
# consonant-approximate
m = MassFunction.from_samples(failure_mode_data, 0.1, mode='consonant-approximate')
poss = {1: 0.171, 2: 0.258, 3: 0.353, 4: 0.462, 5: 0.688, 6: 0.747, 7: 0.875, 8: 0.973, 9: 1.0, 10: 1.0}
self._assert_equal_belief(MassFunction.from_possibility(poss), m, 2)
# bayesian
m = MassFunction.from_samples(precipitation_data, 0.05, mode='bayesian')
for e, n in precipitation_data.items():
self.assertEqual(n / sum(precipitation_data.values()), m[(e,)])
示例6: test_pignistic_inverse
def test_pignistic_inverse(self):
"""
Example 1 from:
A. Aregui, T. Denoeux (2008), "Constructing consonant belief functions from sample data using confidence sets of pignistic probabilities",
International Journal of Approximate Reasoning 49, 575-594.
"""
p = MassFunction({'a':0.7, 'b':0.2, 'c':0.1})
m = MassFunction.pignistic_inverse(p)
self.assertEqual(0.5, m['a'])
self.assertAlmostEqual(0.2, m['ab'])
self.assertAlmostEqual(0.3, m['abc'])
示例7: test_from_possibility
def test_from_possibility(self):
"""
Example 1 from:
D. Dubois, H. Prade, P. Smets (2008), "A definition of subjective possibility",
International Journal of Approximate Reasoning 48 (2), 352-364.
"""
x = 0.6
poss = {'a':1, 'b':x, 'c':1-x}
m = MassFunction.from_possibility(poss)
self.assertEqual(1 - x, m['a'])
self.assertEqual(2 * x - 1, m['ab'])
self.assertEqual(1 - x, m['abc'])
示例8: test_weight_function
def test_weight_function(self):
"""
Examples from:
T. Denoeux (2008), "Conjunctive and disjunctive combination of belief functions induced by nondistinct bodies of evidence",
Artificial Intelligence 172, 234-264.
"""
m1 = MassFunction({'ab':0.3, 'bc':0.5, 'abc':0.2})
w1 = m1.weight_function()
self.assertAlmostEqual(1.0, w1[frozenset('')])
self.assertAlmostEqual(1.0, w1[frozenset('a')])
self.assertAlmostEqual(7./4., w1[frozenset('b')])
self.assertAlmostEqual(2./5., w1[frozenset('ab')])
self.assertAlmostEqual(1.0, w1[frozenset('c')])
self.assertAlmostEqual(1.0, w1[frozenset('ac')])
self.assertAlmostEqual(2./7., w1[frozenset('bc')])
m2 = MassFunction({'b':0.3, 'bc':0.4, 'abc':0.3})
w2 = m2.weight_function()
self.assertAlmostEqual(1.0, w2[frozenset('')])
self.assertAlmostEqual(1.0, w2[frozenset('a')])
self.assertAlmostEqual(0.7, w2[frozenset('b')])
self.assertAlmostEqual(1.0, w2[frozenset('ab')])
self.assertAlmostEqual(1.0, w2[frozenset('c')])
self.assertAlmostEqual(1.0, w2[frozenset('ac')])
self.assertAlmostEqual(3./7., w2[frozenset('bc')])
示例9: test_confidence_intervals
def test_confidence_intervals(self):
"""
Numbers taken from:
W.L. May, W.D. Johnson, A SAS macro for constructing simultaneous confidence intervals for multinomial proportions,
Computer methods and Programs in Biomedicine 53 (1997) 153–162.
"""
hist = {1:91, 2:49, 3:37, 4:43}
lower, upper = MassFunction._confidence_intervals(hist, 0.05)
self.assertAlmostEqual(0.33, lower[1], places=2)
self.assertAlmostEqual(0.16, lower[2], places=2)
self.assertAlmostEqual(0.11, lower[3], places=2)
self.assertAlmostEqual(0.14, lower[4], places=2)
for h, p_u in upper.items():
p = hist[h] / sum(hist.values())
self.assertAlmostEqual(2 * p - lower[h], p_u, places=1)
示例10: error_combine_conjunctive_1000_dir
def error_combine_conjunctive_1000_dir():
m1 = MassFunction.gbt(random_likelihoods(6))
m2 = MassFunction.gbt(random_likelihoods(6))
return measure_error(m1 & m2, m1.combine_conjunctive, m2, sample_count=1000, importance_sampling=False)
示例11: error_gbt_1000
def error_gbt_1000():
lh = random_likelihoods(10)
return measure_error(MassFunction.gbt(lh), MassFunction.gbt, lh, sample_count=1000)
示例12: time_markov_1000
def time_markov_1000():
samples = MassFunction.gbt(random_likelihoods(4)).sample(1000)
return measure_time(MassFunction.gbt(random_likelihoods(4)).markov, lambda s, n: samples[:n], sample_count=1000)
示例13: time_markov
def time_markov():
m = MassFunction.gbt(random_likelihoods(4))
return measure_time(MassFunction.gbt(random_likelihoods(4)).markov, lambda s: m)
示例14: time_pignistic
def time_pignistic():
return measure_time(MassFunction.gbt(random_likelihoods(12)).pignistic)
示例15: time_combine_gbt_1000_imp
def time_combine_gbt_1000_imp():
return measure_time(MassFunction.gbt(random_likelihoods(6)).combine_gbt, random_likelihoods(6), sample_count=1000, importance_sampling=True)