当前位置: 首页>>代码示例>>Python>>正文


Python MassFunction.from_possibility方法代码示例

本文整理汇总了Python中pyds.MassFunction.from_possibility方法的典型用法代码示例。如果您正苦于以下问题:Python MassFunction.from_possibility方法的具体用法?Python MassFunction.from_possibility怎么用?Python MassFunction.from_possibility使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyds.MassFunction的用法示例。


在下文中一共展示了MassFunction.from_possibility方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_from_samples

# 需要导入模块: from pyds import MassFunction [as 别名]
# 或者: from pyds.MassFunction import from_possibility [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,)]) 
开发者ID:aginor,项目名称:pyds,代码行数:58,代码来源:pyds_test.py

示例2: test_from_possibility

# 需要导入模块: from pyds import MassFunction [as 别名]
# 或者: from pyds.MassFunction import from_possibility [as 别名]
 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'])
开发者ID:aginor,项目名称:pyds,代码行数:14,代码来源:pyds_test.py


注:本文中的pyds.MassFunction.from_possibility方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。