本文整理汇总了Python中pyds.MassFunction._confidence_intervals方法的典型用法代码示例。如果您正苦于以下问题:Python MassFunction._confidence_intervals方法的具体用法?Python MassFunction._confidence_intervals怎么用?Python MassFunction._confidence_intervals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyds.MassFunction
的用法示例。
在下文中一共展示了MassFunction._confidence_intervals方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_from_samples
# 需要导入模块: from pyds import MassFunction [as 别名]
# 或者: from pyds.MassFunction import _confidence_intervals [as 别名]
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,)])
示例2: test_confidence_intervals
# 需要导入模块: from pyds import MassFunction [as 别名]
# 或者: from pyds.MassFunction import _confidence_intervals [as 别名]
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)