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_get_assertion(self): self.assertTupleEqual( IndependenceAssertion("U", "V", "Z").get_assertion(), ({"U"}, {"V"}, {"Z"})) self.assertTupleEqual( IndependenceAssertion("U", "V").get_assertion(), ({"U"}, {"V"}, set()))
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
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(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 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')
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")
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
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
def setUp(self): self.assertion = IndependenceAssertion()
' >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> > > "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() " [] "
def is_independent(X, Y, Zs): return IndependenceAssertion(X, Y, Zs) in independencies
# 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