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


Python MassFunction.copy方法代码示例

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


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

示例1: PyDSTest

# 需要导入模块: from pyds import MassFunction [as 别名]
# 或者: from pyds.MassFunction import copy [as 别名]
class PyDSTest(unittest.TestCase):

    def setUp(self):
        self.m1 = MassFunction({'a':0.4, 'b':0.2, 'ad':0.1, 'abcd':0.3})
        self.m2 = MassFunction({'b':0.5, 'c':0.2, 'ac':0.3, 'a':0.0})
        self.m3 = MassFunction({():0.4, 'c':0.2, 'ac':0.3, 'ab':0.1}) # unnormalized mass function
        random.seed(0) # make tests deterministic
    
    def _assert_equal_belief(self, m1, m2, places=8):
        for h in m1.focal() | m2.focal():
            self.assertAlmostEqual(m1[h], m2[h], places)
    
    def test_init(self):
        """Test equivalence of different mass function initialization methods."""
        m1 = MassFunction([(('a',), 0.4), (('b',), 0.2), (('a', 'd'), 0.1), (('a', 'b', 'c', 'd'), 0.3)])
        self.assertEqual(self.m1, m1)
        m1 = MassFunction([('a', 0.4), ('b', 0.2), ('ad', 0.1), ('abcd', 0.3)])
        self.assertEqual(self.m1, m1)
    
    def test_items(self):
        self.assertEqual(0.0, self.m1['x'])
        self.m1['ad'] += 0.5
        self.assertEqual(0.6, self.m1['ad'])
    
    def test_copy(self):
        c = self.m1.copy()
        for k in self.m1.keys():
            self.assertEqual(self.m1.bel(k), c.bel(k))
        c['a'] = 0.3
        # assert that the original object remains unchanged
        self.assertEqual(0.4, self.m1['a'])
    
    def test_del(self):
        del self.m1['a']
        self.assertEqual(3, len(self.m1))
        self.assertEqual(0.0, self.m1['a'])
    
    def test_bel(self):
        # compute the belief of a single hypothesis
        self.assertEqual(0.4, self.m1.bel('a'))
        self.assertEqual(0.5, self.m1.bel('ad'))
        self.assertEqual(1, self.m1.bel('abcd'))
        self.assertEqual(0.0, self.m3.bel(''))
        self.assertEqual(0.0, self.m3.bel('a'))
        self.assertEqual(0.5, self.m3.bel('ac'))
        self.assertAlmostEqual(0.6, self.m3.bel('abc'))
        # compute the entire belief function
        bel2 = self.m2.bel()
        self.assertEqual(8, len(bel2))
        for h, v in bel2.items():
            self.assertEqual(self.m2.bel(h), v)
        bel3 = self.m3.bel()
        self.assertEqual(8, len(bel3))
        for h, v in bel3.items():
            self.assertEqual(self.m3.bel(h), v)
    
    def test_from_bel(self):
        self._assert_equal_belief(self.m1, MassFunction.from_bel(self.m1.bel()), 8)
        self._assert_equal_belief(self.m2, MassFunction.from_bel(self.m2.bel()), 8)
        self._assert_equal_belief(self.m3, MassFunction.from_bel(self.m3.bel()), 8)
    
    def test_pl(self):
        # compute the plausibility of a single hypothesis
        self.assertEqual(0.8, self.m1.pl('a'))
        self.assertEqual(0.5, self.m1.pl('b'))
        self.assertEqual(0.8, self.m1.pl('ad'))
        self.assertEqual(1, self.m1.pl('abcd'))
        self.assertEqual(0.0, self.m3.pl(''))
        self.assertAlmostEqual(0.1, self.m3.pl('b'))
        self.assertAlmostEqual(0.6, self.m3.pl('abc'))
        # compute the entire plausibility function
        pl2 = self.m2.pl()
        self.assertEqual(8, len(pl2))
        for h, v in pl2.items():
            self.assertEqual(self.m2.pl(h), v)
        pl3 = self.m3.pl()
        self.assertEqual(8, len(pl3))
        for h, v in pl3.items():
            self.assertEqual(self.m3.pl(h), v)
    
    def test_from_pl(self):
        self._assert_equal_belief(self.m1, MassFunction.from_pl(self.m1.pl()), 8)
        self._assert_equal_belief(self.m2, MassFunction.from_pl(self.m2.pl()), 8)
        self._assert_equal_belief(self.m3, MassFunction.from_pl(self.m3.pl()), 8)
    
    def test_q(self):
        # compute the commonality of a single hypothesis
        self.assertEqual(0.8, self.m1.q('a'))
        self.assertEqual(0.5, self.m1.q('b'))
        self.assertEqual(0.4, self.m1.q('ad'))
        self.assertEqual(0.3, self.m1.q('abcd'))
        self.assertEqual(0.0, self.m3.q(''))
        self.assertEqual(0.4, self.m3.q('a'))
        self.assertEqual(0.3, self.m3.q('ac'))
        # compute the entire commonality function
        q2 = self.m2.q()
        self.assertEqual(8, len(q2))
        for h, v in q2.items():
            self.assertEqual(self.m2.q(h), v)
        q3 = self.m3.q()
#.........这里部分代码省略.........
开发者ID:aginor,项目名称:pyds,代码行数:103,代码来源:pyds_test.py

示例2: PyDSTest

# 需要导入模块: from pyds import MassFunction [as 别名]
# 或者: from pyds.MassFunction import copy [as 别名]
class PyDSTest(unittest.TestCase):

    def setUp(self):
        self.m1 = MassFunction({'a':0.4, 'b':0.2, 'ad':0.1, 'abcd':0.3})
        self.m2 = MassFunction({'b':0.5, 'c':0.2, 'ac':0.3, 'a':0.0})
        self.m3 = MassFunction({():0.4, 'c':0.2, 'ac':0.3, 'ab':0.1}) # unnormalized mass function
        random.seed(0) # make tests deterministic
    
    def _assert_equal_belief(self, m1, m2, places):
        for h in m1.focal() | m2.focal():
            self.assertAlmostEqual(m1[h], m2[h], places)
    
    def test_init(self):
        """Test equivalence of different mass function initialization methods."""
        m1 = MassFunction([(('a',), 0.4), (('b',), 0.2), (('a', 'd'), 0.1), (('a', 'b', 'c', 'd'), 0.3)])
        self.assertEqual(self.m1, m1)
        m1 = MassFunction([('a', 0.4), ('b', 0.2), ('ad', 0.1), ('abcd', 0.3)])
        self.assertEqual(self.m1, m1)
    
    def test_items(self):
        self.assertEqual(0.0, self.m1['x'])
        self.m1['ad'] += 0.5
        self.assertEqual(0.6, self.m1['ad'])
    
    def test_copy(self):
        c = self.m1.copy()
        for k in self.m1.keys():
            self.assertEqual(self.m1.bel(k), c.bel(k))
        c['a'] = 0.3
        # assert that the original object remains unchanged
        self.assertEqual(0.4, self.m1['a'])
    
    def test_del(self):
        del self.m1['a']
        self.assertEqual(3, len(self.m1))
        self.assertEqual(0.0, self.m1['a'])
    
    def test_bel(self):
        # compute the belief of a single hypothesis
        self.assertEqual(0.4, self.m1.bel('a'))
        self.assertEqual(0.5, self.m1.bel('ad'))
        self.assertEqual(1, self.m1.bel('abcd'))
        self.assertEqual(0.0, self.m3.bel(''))
        self.assertEqual(0.0, self.m3.bel('a'))
        self.assertEqual(0.5, self.m3.bel('ac'))
        self.assertAlmostEqual(0.6, self.m3.bel('abc'))
        # compute the entire belief function
        bel2 = self.m2.bel()
        self.assertEqual(8, len(bel2))
        for h, v in bel2.items():
            self.assertEqual(self.m2.bel(h), v)
        bel3 = self.m3.bel()
        self.assertEqual(8, len(bel3))
        for h, v in bel3.items():
            self.assertEqual(self.m3.bel(h), v)
    
    def test_from_bel(self):
        self._assert_equal_belief(self.m1, MassFunction.from_bel(self.m1.bel()), 8)
        self._assert_equal_belief(self.m2, MassFunction.from_bel(self.m2.bel()), 8)
        self._assert_equal_belief(self.m3, MassFunction.from_bel(self.m3.bel()), 8)
    
    def test_pl(self):
        # compute the plausibility of a single hypothesis
        self.assertEqual(0.8, self.m1.pl('a'))
        self.assertEqual(0.5, self.m1.pl('b'))
        self.assertEqual(0.8, self.m1.pl('ad'))
        self.assertEqual(1, self.m1.pl('abcd'))
        self.assertEqual(0.0, self.m3.pl(''))
        self.assertAlmostEqual(0.1, self.m3.pl('b'))
        self.assertAlmostEqual(0.6, self.m3.pl('abc'))
        # compute the entire plausibility function
        pl2 = self.m2.pl()
        self.assertEqual(8, len(pl2))
        for h, v in pl2.items():
            self.assertEqual(self.m2.pl(h), v)
        pl3 = self.m3.pl()
        self.assertEqual(8, len(pl3))
        for h, v in pl3.items():
            self.assertEqual(self.m3.pl(h), v)
    
    def test_from_pl(self):
        self._assert_equal_belief(self.m1, MassFunction.from_pl(self.m1.pl()), 8)
        self._assert_equal_belief(self.m2, MassFunction.from_pl(self.m2.pl()), 8)
        self._assert_equal_belief(self.m3, MassFunction.from_pl(self.m3.pl()), 8)
    
    def test_q(self):
        # compute the commonality of a single hypothesis
        self.assertEqual(0.8, self.m1.q('a'))
        self.assertEqual(0.5, self.m1.q('b'))
        self.assertEqual(0.4, self.m1.q('ad'))
        self.assertEqual(0.3, self.m1.q('abcd'))
        self.assertEqual(0.0, self.m3.q(''))
        self.assertEqual(0.4, self.m3.q('a'))
        self.assertEqual(0.3, self.m3.q('ac'))
        # compute the entire commonality function
        q2 = self.m2.q()
        self.assertEqual(8, len(q2))
        for h, v in q2.items():
            self.assertEqual(self.m2.q(h), v)
        q3 = self.m3.q()
#.........这里部分代码省略.........
开发者ID:velniukas,项目名称:pyds,代码行数:103,代码来源:pyds_test.py


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