コード例 #1
0
 def test_get_assertion(self):
     self.assertTupleEqual(
         IndependenceAssertion('U', 'V', 'Z').get_assertion(),
         ({'U'}, {'V'}, {'Z'}))
     self.assertTupleEqual(
         IndependenceAssertion('U', 'V').get_assertion(),
         ({'U'}, {'V'}, set()))
コード例 #2
0
 def test_get_assertion(self):
     self.assertTupleEqual(
         IndependenceAssertion("U", "V", "Z").get_assertion(),
         ({"U"}, {"V"}, {"Z"}))
     self.assertTupleEqual(
         IndependenceAssertion("U", "V").get_assertion(),
         ({"U"}, {"V"}, set()))
コード例 #3
0
class TestIndependenceAssertion(unittest.TestCase):
    def setUp(self):
        self.assertion = IndependenceAssertion()

    def test_return_list_if_str(self):
        self.assertListEqual(self.assertion._return_list_if_str('U'), ['U'])
        self.assertListEqual(self.assertion._return_list_if_str(['U', 'V']), ['U', 'V'])

    def test_get_assertion(self):
        self.assertTupleEqual(IndependenceAssertion('U', 'V', 'Z').get_assertion(), ({'U'}, {'V'}, {'Z'}))
        self.assertTupleEqual(IndependenceAssertion('U', 'V').get_assertion(), ({'U'}, {'V'}, set()))

    def test_init(self):
        self.assertion1 = IndependenceAssertion('U', 'V', 'Z')
        self.assertSetEqual(self.assertion1.event1, {'U'})
        self.assertSetEqual(self.assertion1.event2, {'V'})
        self.assertSetEqual(self.assertion1.event3, {'Z'})
        self.assertion1 = IndependenceAssertion(['U', 'V'], ['Y', 'Z'], ['A', 'B'])
        self.assertSetEqual(self.assertion1.event1, {'U', 'V'})
        self.assertSetEqual(self.assertion1.event2, {'Y', 'Z'})
        self.assertSetEqual(self.assertion1.event3, {'A', 'B'})

    def test_init_exceptions(self):
        self.assertRaises(ValueError, IndependenceAssertion, event2=['U'], event3='V')
        self.assertRaises(ValueError, IndependenceAssertion, event2=['U'])
        self.assertRaises(ValueError, IndependenceAssertion, event3=['Z'])
        self.assertRaises(ValueError, IndependenceAssertion, event1=['U'])
        self.assertRaises(ValueError, IndependenceAssertion, event1=['U'], event3=['Z'])

    def tearDown(self):
        del self.assertion
コード例 #4
0
 def test_init(self):
     self.assertion1 = IndependenceAssertion("U", "V", "Z")
     self.assertSetEqual(self.assertion1.event1, {"U"})
     self.assertSetEqual(self.assertion1.event2, {"V"})
     self.assertSetEqual(self.assertion1.event3, {"Z"})
     self.assertion1 = IndependenceAssertion(["U", "V"], ["Y", "Z"],
                                             ["A", "B"])
     self.assertSetEqual(self.assertion1.event1, {"U", "V"})
     self.assertSetEqual(self.assertion1.event2, {"Y", "Z"})
     self.assertSetEqual(self.assertion1.event3, {"A", "B"})
コード例 #5
0
 def test_init(self):
     self.assertion1 = IndependenceAssertion('U', 'V', 'Z')
     self.assertSetEqual(self.assertion1.event1, {'U'})
     self.assertSetEqual(self.assertion1.event2, {'V'})
     self.assertSetEqual(self.assertion1.event3, {'Z'})
     self.assertion1 = IndependenceAssertion(['U', 'V'], ['Y', 'Z'],
                                             ['A', 'B'])
     self.assertSetEqual(self.assertion1.event1, {'U', 'V'})
     self.assertSetEqual(self.assertion1.event2, {'Y', 'Z'})
     self.assertSetEqual(self.assertion1.event3, {'A', 'B'})
コード例 #6
0
 def setUp(self):
     self.i1 = IndependenceAssertion('a', 'b', 'c')
     self.i2 = IndependenceAssertion('a', 'b')
     self.i3 = IndependenceAssertion('a', ['b', 'c', 'd'])
     self.i4 = IndependenceAssertion('a', ['b', 'c', 'd'], 'e')
     self.i5 = IndependenceAssertion('a', ['d', 'c', 'b'], 'e')
     self.i6 = IndependenceAssertion('a', ['d', 'c'], ['e', 'b'])
     self.i7 = IndependenceAssertion('a', ['c', 'd'], ['b', 'e'])
     self.i8 = IndependenceAssertion('a', ['f', 'd'], ['b', 'e'])
     self.i9 = IndependenceAssertion('a', ['d', 'k', 'b'], 'e')
     self.i10 = IndependenceAssertion(['k', 'b', 'd'], 'a', 'e')
コード例 #7
0
 def setUp(self):
     self.i1 = IndependenceAssertion("a", "b", "c")
     self.i2 = IndependenceAssertion("a", "b")
     self.i3 = IndependenceAssertion("a", ["b", "c", "d"])
     self.i4 = IndependenceAssertion("a", ["b", "c", "d"], "e")
     self.i5 = IndependenceAssertion("a", ["d", "c", "b"], "e")
     self.i6 = IndependenceAssertion("a", ["d", "c"], ["e", "b"])
     self.i7 = IndependenceAssertion("a", ["c", "d"], ["b", "e"])
     self.i8 = IndependenceAssertion("a", ["f", "d"], ["b", "e"])
     self.i9 = IndependenceAssertion("a", ["d", "k", "b"], "e")
     self.i10 = IndependenceAssertion(["k", "b", "d"], "a", "e")
コード例 #8
0
class TestIndependenceAssertion(unittest.TestCase):
    def setUp(self):
        self.assertion = IndependenceAssertion()

    def test_return_list_if_str(self):
        self.assertListEqual(self.assertion._return_list_if_str("U"), ["U"])
        self.assertListEqual(self.assertion._return_list_if_str(["U", "V"]),
                             ["U", "V"])

    def test_get_assertion(self):
        self.assertTupleEqual(
            IndependenceAssertion("U", "V", "Z").get_assertion(),
            ({"U"}, {"V"}, {"Z"}))
        self.assertTupleEqual(
            IndependenceAssertion("U", "V").get_assertion(),
            ({"U"}, {"V"}, set()))

    def test_init(self):
        self.assertion1 = IndependenceAssertion("U", "V", "Z")
        self.assertSetEqual(self.assertion1.event1, {"U"})
        self.assertSetEqual(self.assertion1.event2, {"V"})
        self.assertSetEqual(self.assertion1.event3, {"Z"})
        self.assertion1 = IndependenceAssertion(["U", "V"], ["Y", "Z"],
                                                ["A", "B"])
        self.assertSetEqual(self.assertion1.event1, {"U", "V"})
        self.assertSetEqual(self.assertion1.event2, {"Y", "Z"})
        self.assertSetEqual(self.assertion1.event3, {"A", "B"})

    def test_init_exceptions(self):
        self.assertRaises(ValueError,
                          IndependenceAssertion,
                          event2=["U"],
                          event3="V")
        self.assertRaises(ValueError, IndependenceAssertion, event2=["U"])
        self.assertRaises(ValueError, IndependenceAssertion, event3=["Z"])
        self.assertRaises(ValueError, IndependenceAssertion, event1=["U"])
        self.assertRaises(ValueError,
                          IndependenceAssertion,
                          event1=["U"],
                          event3=["Z"])

    def tearDown(self):
        del self.assertion
コード例 #9
0
class TestIndependenceAssertion(unittest.TestCase):
    def setUp(self):
        self.assertion = IndependenceAssertion()

    def test_return_list_if_str(self):
        self.assertListEqual(self.assertion._return_list_if_str('U'), ['U'])
        self.assertListEqual(self.assertion._return_list_if_str(['U', 'V']),
                             ['U', 'V'])

    def test_get_assertion(self):
        self.assertTupleEqual(
            IndependenceAssertion('U', 'V', 'Z').get_assertion(),
            ({'U'}, {'V'}, {'Z'}))
        self.assertTupleEqual(
            IndependenceAssertion('U', 'V').get_assertion(),
            ({'U'}, {'V'}, set()))

    def test_init(self):
        self.assertion1 = IndependenceAssertion('U', 'V', 'Z')
        self.assertSetEqual(self.assertion1.event1, {'U'})
        self.assertSetEqual(self.assertion1.event2, {'V'})
        self.assertSetEqual(self.assertion1.event3, {'Z'})
        self.assertion1 = IndependenceAssertion(['U', 'V'], ['Y', 'Z'],
                                                ['A', 'B'])
        self.assertSetEqual(self.assertion1.event1, {'U', 'V'})
        self.assertSetEqual(self.assertion1.event2, {'Y', 'Z'})
        self.assertSetEqual(self.assertion1.event3, {'A', 'B'})

    def test_init_exceptions(self):
        self.assertRaises(ValueError,
                          IndependenceAssertion,
                          event2=['U'],
                          event3='V')
        self.assertRaises(ValueError, IndependenceAssertion, event2=['U'])
        self.assertRaises(ValueError, IndependenceAssertion, event3=['Z'])
        self.assertRaises(ValueError, IndependenceAssertion, event1=['U'])
        self.assertRaises(ValueError,
                          IndependenceAssertion,
                          event1=['U'],
                          event3=['Z'])

    def tearDown(self):
        del self.assertion
コード例 #10
0
 def setUp(self):
     self.assertion = IndependenceAssertion()
コード例 #11
0
ファイル: PGM_All.py プロジェクト: bopopescu/datascience2015

'
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>
> "Bayesian Network Fundamental"
>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

-- Independence --
# -- Representing independencies using 'pgmpy'
# [1] Assertation (nodes)

from pgmpy.independencies import IndependenceAssertion

assertion1 = IndependenceAssertion('X', 'Y') 
" (X _|_ Y) "

assertion2 = IndependenceAssertion('X', 'Y', 'Z')
" (X _|_ Y|Z) "

assertion3 = IndependenceAssertion('X', ['Y','U','I'], ['Z','L','O'])
" (X _|_ Y,U,I|Z,L,O) "


# [2] A set of assertations (nodes)
from pgmpy.independencies import Independencies

independencies = Independencies() # empty object
independencies.get_assertations()
" [] "
コード例 #12
0
 def is_independent(X, Y, Zs):
     return IndependenceAssertion(X, Y, Zs) in independencies
コード例 #13
0
 def setUp(self):
     self.assertion = IndependenceAssertion()
コード例 #14
0
# Firstly we need to import IndependenceAssertion
from pgmpy.independencies import IndependenceAssertion
# Each assertion is in the form of [X, Y, Z] meaning X is
# independent of Y given Z.
assertion1 = IndependenceAssertion('X', 'Y')
assertion1