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


Python MassFunction.is_probabilistic方法代码示例

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


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

示例1: PyDSTest

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

#.........这里部分代码省略.........
        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:
            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_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'])
开发者ID:aginor,项目名称:pyds,代码行数:70,代码来源:pyds_test.py

示例2: PyDSTest

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


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