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


Python MassFunction.hartley_measure方法代码示例

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


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

示例1: PyDSTest

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

#.........这里部分代码省略.........
        md12 = md1 & md2
        self.assertAlmostEqual(0.2, md12[{('a', 1)}])
        self.assertAlmostEqual(0.8, md12[{('a', 1), ('b', 2)}])
    
    def test_map(self):
        # vacuous extension
        frame = {1, 2}
        extended = self.m3.map(lambda h: product(h, frame))
        result = MassFunction({():0.4, (('c', 1), ('c', 2)):0.2, (('a', 1), ('a', 2), ('c', 1), ('c', 2)):0.3, (('a', 1), ('a', 2), ('b', 1), ('b', 2)):0.1})
        self.assertEqual(result, extended)
        # projection
        projected = extended.map(lambda h: (t[0] for t in h))
        self.assertEqual(self.m3, projected)
    
    def test_pignistic(self):
        p1 = self.m1.pignistic()
        self.assertEqual(0.525, p1['a'])
        self.assertEqual(0.275, p1['b'])
        self.assertEqual(0.075, p1['c'])
        self.assertEqual(0.125, p1['d'])
        p3 = self.m3.pignistic()
        self.assertEqual(0.2 / 0.6, p3['a'])
        self.assertEqual(0.05 / 0.6, p3['b'])
        self.assertEqual(0.35 / 0.6, p3['c'])
    
    def test_local_conflict(self):
        c = 0.5 * log(1 / 0.5, 2) + 0.2 * log(1 / 0.2, 2) + 0.3 * log(2 / 0.3, 2)
        self.assertEqual(c, self.m2.local_conflict())
        self.assertTrue(isnan(self.m3.local_conflict()))
        # pignistic entropy
        h = -0.125 * log(0.125, 2) - 0.075 * log(0.075, 2) - 0.275 * log(0.275, 2) - 0.525 * log(0.525, 2)
        self.assertAlmostEqual(h, self.m1.pignistic().local_conflict())
    
    def test_hartley_measure(self):
        self.assertEqual(0.1 + 0.3 * log(4, 2), self.m1.hartley_measure())
    
    def test_norm(self):
        self.assertEqual(0, self.m1.norm(self.m1))
        self.assertEqual(0, self.m1.norm(self.m1, p = 1))
        m3 = MassFunction({'e':1.0})
        len_m1 = sum([v**2 for v in self.m1.values()])
        self.assertEqual((1 + len_m1)**0.5, self.m1.norm(m3))

    def test_prune(self):
        self.assertTrue('a' in self.m2)
        pruned = self.m2.prune()
        self.assertFalse('a' in pruned)
        self._assert_equal_belief(self.m2, pruned, 10)
    
    def test_sample(self):
        sample_count = 1000
        samples_ran = self.m1.sample(sample_count, quantization=False)
        samples_ml = self.m1.sample(sample_count, quantization=True)
        self.assertEqual(sample_count, len(samples_ran))
        self.assertEqual(sample_count, len(samples_ml))
        for h, v in self.m1.items():
            self.assertAlmostEqual(v, float(samples_ran.count(h)) / sample_count, places=1)
            self.assertAlmostEqual(v, float(samples_ml.count(h)) / sample_count, places=20)
        self.assertEqual(0, len(MassFunction().sample(sample_count)))
    
    def test_markov(self):
        def test(m, places):
            self.assertAlmostEqual(0.4 * 0.8, m[(4, 6)], places)
            self.assertAlmostEqual(0.4 * 0.2, m[(5,)], places)
            self.assertAlmostEqual(0.6 * 0.2 * 0.2, m[(0, 1)], places)
            self.assertAlmostEqual(0.6 * 0.2 * 0.8, m[(-1, 1)], places)
开发者ID:aginor,项目名称:pyds,代码行数:70,代码来源:pyds_test.py


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