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


Python MassFunction.to_array方法代码示例

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


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

示例1: PyDSTest

# 需要导入模块: from pyds import MassFunction [as 别名]
# 或者: from pyds.MassFunction import to_array [as 别名]

#.........这里部分代码省略.........
        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_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'])
    
    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'])
    
    def test_to_array_index(self):
        self.assertEqual(0, MassFunction._to_array_index((), ('a', 'b', 'c')))
        self.assertEqual(1, MassFunction._to_array_index(('a',), ('a', 'b', 'c')))
        self.assertEqual(2, MassFunction._to_array_index(('b',), ('a', 'b', 'c')))
        self.assertEqual(4, MassFunction._to_array_index(('c',), ('a', 'b', 'c')))
        self.assertEqual(7, MassFunction._to_array_index(('a', 'b', 'c'), ('a', 'b', 'c')))
    
    def test_from_array_index(self):
        self.assertEqual(frozenset(), MassFunction._from_array_index(0, ('a', 'b', 'c')))
        self.assertEqual(frozenset(('a',)), MassFunction._from_array_index(1, ('a', 'b', 'c')))
        self.assertEqual(frozenset(('b',)), MassFunction._from_array_index(2, ('a', 'b', 'c')))
        self.assertEqual(frozenset(('c',)), MassFunction._from_array_index(4, ('a', 'b', 'c')))
        self.assertEqual(frozenset(('a', 'b', 'c')), MassFunction._from_array_index(7, ('a', 'b', 'c')))
    
    def test_to_array(self):
        self.assertListEqual([0, 0, 0.2, 0.3, 0.5, 0, 0, 0], list(self.m2.to_array()))
    
    def test_from_array(self):
        self._assert_equal_belief(self.m1, MassFunction.from_array(self.m1.to_array(), self.m1.frame()))
    
    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():
开发者ID:aginor,项目名称:pyds,代码行数:70,代码来源:pyds_test.py


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