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


Python MassFunction.sample方法代码示例

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


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

示例1: print

# 需要导入模块: from pyds import MassFunction [as 别名]
# 或者: from pyds.MassFunction import sample [as 别名]
print('\n=== disjunctive combination rule (exact and approximate) ===')
print('disjunctive combination of m_1 and m_2 =', m1 | m2)
print('disjunctive combination of m_1 and m_2 (Monte-Carlo) =', m1.combine_disjunctive(m2, sample_count=1000))
print('disjunctive combination of m_1, m_2, and m_3 =', m1.combine_disjunctive(m2, m3))

print('\n=== weight of conflict ===')
print('weight of conflict between m_1 and m_2 =', m1.conflict(m2))
print('weight of conflict between m_1 and m_2 (Monte-Carlo) =', m1.conflict(m2, sample_count=1000))
print('weight of conflict between m_1, m_2, and m_3 =', m1.conflict(m2, m3))

print('\n=== pignistic transformation ===')
print('pignistic transformation of m_1 =', m1.pignistic())
print('pignistic transformation of m_2 =', m2.pignistic())
print('pignistic transformation of m_3 =', m3.pignistic())

print('\n=== local conflict uncertainty measure ===')
print('local conflict of m_1 =', m1.local_conflict())
print('entropy of the pignistic transformation of m_3 =', m3.pignistic().local_conflict())

print('\n=== sampling ===')
print('random samples drawn from m_1 =', m1.sample(5, quantization=False))
print('sample frequencies of m_1 =', m1.sample(1000, quantization=False, as_dict=True))
print('quantization of m_1 =', m1.sample(1000, as_dict=True))

print('\n=== map: vacuous extension and projection ===')
extended = m1.map(lambda h: product(h, {1, 2}))
print('vacuous extension of m_1 to {1, 2} =', extended)
projected = extended.map(lambda h: (t[0] for t in h))
print('project m_1 back to its original frame =', projected)
开发者ID:aginor,项目名称:pyds,代码行数:31,代码来源:examples.py

示例2: PyDSTest

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

#.........这里部分代码省略.........
    
    def test_from_q(self):
        self._assert_equal_belief(self.m1, MassFunction.from_q(self.m1.q()), 8)
        self._assert_equal_belief(self.m2, MassFunction.from_q(self.m2.q()), 8)
        self._assert_equal_belief(self.m3, MassFunction.from_q(self.m3.q()), 8)
    
    def test_condition(self):
        m1 = self.m1.condition('ad')
        self.assertEqual(0.5, m1['a'])
        self.assertEqual(0.5, m1['ad'])
        m1_un = self.m1.condition('ad', normalization=False)
        self.assertEqual(0.2, m1_un[''])
        self.assertEqual(0.4, m1_un['a'])
        self.assertEqual(0.4, m1_un['ad'])
        m3 = self.m3.condition('ac')
        self.assertEqual(0.5, m3['ac'])
        self.assertAlmostEqual(1.0 / 3.0, m3['c'])
        self.assertAlmostEqual(1.0 / 6.0, m3['a'])
        m3_un = self.m3.condition('ab', normalization=False)
        self.assertAlmostEqual(0.6, m3_un[set()])
        self.assertEqual(0.3, m3_un['a'])
        self.assertEqual(0.1, m3_un['ab'])
    
    def test_combine_conjunctive(self):
        def test(m, empty_mass, places=10):
            self.assertAlmostEqual(empty_mass, m[set()], places)
            norm = 0.55 + empty_mass
            self.assertAlmostEqual(0.15 / norm, m['a'], places)
            self.assertAlmostEqual(0.25 / norm, m['b'], places)
            self.assertAlmostEqual(0.06 / norm, m['c'], places)
            self.assertAlmostEqual(0.09 / norm, m['ac'], places)
        # normalized
        test(self.m1 & self.m2, 0.0)
        test(self.m1.combine_conjunctive(self.m2, sample_count=10000), 0.0, 1)
        test(self.m1.combine_conjunctive(self.m2, sample_count=1000, importance_sampling=True), 0.0)
        # unnormalized
        test(self.m1.combine_conjunctive(self.m2, normalization=False), 0.45)
        test(self.m1.combine_conjunctive(self.m2, normalization=False, sample_count=10000), 0.45, 2)
        test(self.m1.combine_conjunctive(self.m2, normalization=False, sample_count=1000, importance_sampling=True), 0.45, 2) # ImpSam should be ignored
        # combine multiple mass functions
        m_single = self.m1.combine_conjunctive(self.m1).combine_conjunctive(self.m2)
        m_multi = self.m1.combine_conjunctive(self.m1, self.m2)
        self._assert_equal_belief(m_single, m_multi, 10)
        # combine incompatible mass function
        self.assertFalse(self.m1 & MassFunction({(0, 1):0.8, (0,):0.2}))
    
    def test_combine_disjunctive(self):
        def test(m, places):
            self.assertAlmostEqual(0.2, m['ab'], places)
            self.assertAlmostEqual(0.2, m['ac'], places)
            self.assertAlmostEqual(0.1, m['b'], places)
            self.assertAlmostEqual(0.04, m['bc'], places)
            self.assertAlmostEqual(0.06, m['abc'], places)
            self.assertAlmostEqual(0.05, m['abd'], places)
            self.assertAlmostEqual(0.05, m['acd'], places)
            self.assertAlmostEqual(0.3, m['abcd'], places)
        test(self.m1 | self.m2, 10)
        test(self.m1.combine_disjunctive(self.m2, sample_count=10000), 2)
        # combine multiple mass functions
        m_single = self.m1.combine_disjunctive(self.m1).combine_disjunctive(self.m2)
        m_multi = self.m1.combine_disjunctive(self.m1, self.m2)
        for h, v in m_single.items():
            self.assertAlmostEqual(v, m_multi[h])
    
    def test_conflict(self):
        self.assertEqual(-log(0.55, 2), self.m1.conflict(self.m2));
开发者ID:aginor,项目名称:pyds,代码行数:70,代码来源:pyds_test.py

示例3: PyDSTest

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

#.........这里部分代码省略.........
    
    def test_from_q(self):
        self._assert_equal_belief(self.m1, MassFunction.from_q(self.m1.q()), 8)
        self._assert_equal_belief(self.m2, MassFunction.from_q(self.m2.q()), 8)
        self._assert_equal_belief(self.m3, MassFunction.from_q(self.m3.q()), 8)
    
    def test_condition(self):
        m1 = self.m1.condition('ad')
        self.assertEqual(0.5, m1['a'])
        self.assertEqual(0.5, m1['ad'])
        m1_un = self.m1.condition('ad', normalization=False)
        self.assertEqual(0.2, m1_un[''])
        self.assertEqual(0.4, m1_un['a'])
        self.assertEqual(0.4, m1_un['ad'])
        m3 = self.m3.condition('ac')
        self.assertEqual(0.5, m3['ac'])
        self.assertAlmostEqual(1.0 / 3.0, m3['c'])
        self.assertAlmostEqual(1.0 / 6.0, m3['a'])
        m3_un = self.m3.condition('ab', normalization=False)
        self.assertAlmostEqual(0.6, m3_un[set()])
        self.assertEqual(0.3, m3_un['a'])
        self.assertEqual(0.1, m3_un['ab'])
    
    def test_combine_conjunctive(self):
        def test(m, empty_mass, places=10):
            self.assertAlmostEqual(empty_mass, m[set()], places)
            norm = 0.55 + empty_mass
            self.assertAlmostEqual(0.15 / norm, m['a'], places)
            self.assertAlmostEqual(0.25 / norm, m['b'], places)
            self.assertAlmostEqual(0.06 / norm, m['c'], places)
            self.assertAlmostEqual(0.09 / norm, m['ac'], places)
        # normalized
        test(self.m1 & self.m2, 0.0)
        test(self.m1.combine_conjunctive(self.m2, sample_count=10000), 0.0, 1)
        test(self.m1.combine_conjunctive(self.m2, sample_count=1000, importance_sampling=True), 0.0)
        # unnormalized
        test(self.m1.combine_conjunctive(self.m2, normalization=False), 0.45)
        test(self.m1.combine_conjunctive(self.m2, normalization=False, sample_count=10000), 0.45, 2)
        test(self.m1.combine_conjunctive(self.m2, normalization=False, sample_count=1000, importance_sampling=True), 0.45, 2) # ImpSam should be ignored
        # combine multiple mass functions
        m_single = self.m1.combine_conjunctive(self.m1).combine_conjunctive(self.m2)
        m_multi = self.m1.combine_conjunctive(self.m1, self.m2)
        self._assert_equal_belief(m_single, m_multi, 10)
        # combine incompatible mass function
        self.assertFalse(self.m1 & MassFunction({(0, 1):0.8, (0,):0.2}))
    
    def test_combine_disjunctive(self):
        def test(m, places):
            self.assertAlmostEqual(0.2, m['ab'], places)
            self.assertAlmostEqual(0.2, m['ac'], places)
            self.assertAlmostEqual(0.1, m['b'], places)
            self.assertAlmostEqual(0.04, m['bc'], places)
            self.assertAlmostEqual(0.06, m['abc'], places)
            self.assertAlmostEqual(0.05, m['abd'], places)
            self.assertAlmostEqual(0.05, m['acd'], places)
            self.assertAlmostEqual(0.3, m['abcd'], places)
        test(self.m1 | self.m2, 10)
        test(self.m1.combine_disjunctive(self.m2, sample_count=10000), 2)
        # combine multiple mass functions
        m_single = self.m1.combine_disjunctive(self.m1).combine_disjunctive(self.m2)
        m_multi = self.m1.combine_disjunctive(self.m1, self.m2)
        for h, v in m_single.items():
            self.assertAlmostEqual(v, m_multi[h])
    
    def test_conflict(self):
        self.assertEqual(-log(0.55, 2), self.m1.conflict(self.m2));
开发者ID:velniukas,项目名称:pyds,代码行数:70,代码来源:pyds_test.py


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