Example #1
0
    def testIndependence(self):
        mn = gum.fastMN("A--B--C;C--D;E--F--G;B--E;D--G;X")

        self.assertTrue(mn.isIndependent("D", "X", {}))
        self.assertFalse(mn.isIndependent("D", "A", {"C"}))
        self.assertTrue(mn.isIndependent("D", "A", {"C", "G"}))
        self.assertFalse(mn.isIndependent("G", "A", {"C", "F"}))
        self.assertTrue(mn.isIndependent("G", "A", {"D", "E"}))
Example #2
0
    def testExistsEdge(self):
        mn = gum.fastMN("A--B--C;C--D;E--F--G")

        self.assertTrue(mn.existsEdge(0, 1))
        self.assertTrue(mn.existsEdge("A", "B"))
        self.assertTrue(mn.existsEdge(1, 0))
        self.assertTrue(mn.existsEdge("B", "A"))
        self.assertTrue(mn.existsEdge(0, 2))
        self.assertTrue(mn.existsEdge("A", "C"))
        self.assertFalse(mn.existsEdge(3, 7))
        self.assertFalse(mn.existsEdge("C", "G"))
Example #3
0
    def testMinimalCondSet(self):
        mn = gum.fastMN("A--B--C;C--D;E--F--G;B--E")

        self.assertEqual(mn.minimalCondSet(0, {1, 2, 3, 4, 5, 6}), {1, 2})
        self.assertEqual(mn.minimalCondSet({0, 6}, {1, 2, 3, 4, 5}),
                         {1, 2, 4, 5})
        self.assertEqual(mn.minimalCondSet(3, {0, 4, 5, 6}), {0, 4})

        self.assertEqual(
            mn.minimalCondSet("A", {"B", "C", "D", "E", "F", "G"}), {1, 2})
        self.assertEqual(
            mn.minimalCondSet({"A", "G"}, {"B", "C", "D", "E", "F"}),
            {1, 2, 4, 5})
        self.assertEqual(mn.minimalCondSet("D", {"A", "E", "F", "G"}), {0, 4})
Example #4
0
    def testOrderInsertion(self):
        mn = gum.fastMN("V0;V1;V2;V3")

        # V0 should be the first
        mn.addFactor(["V0", "V1"])
        self.assertEquals(mn.factor({"V0", "V1"}).variable(0).name(), "V0")
        self.assertEquals(mn.factor({"V1", "V0"}).variable(0).name(), "V0")

        # V2 should be the first
        mn.addFactor(["V2", "V1"])
        self.assertEquals(mn.factor({"V2", "V1"}).variable(0).name(), "V2")
        self.assertEquals(mn.factor({"V1", "V2"}).variable(0).name(), "V2")

        # 2 should be the first
        mn.addFactor({"V2", "V3"})
        self.assertEquals(mn.factor({"V3", "V2"}).variable(0).name(), "V2")

        # 1 should be the first
        mn.addFactor({"V2", "V0"})
        self.assertEquals(mn.factor({"V2", "V0"}).variable(0).name(), "V0")
Example #5
0
    def testOrderInsertionWithId(self):
        mn = gum.fastMN("V0;V1;V2;V3")

        # V0 should be the first
        mn.addFactor([0, 1])
        self.assertEquals(mn.factor({0, 1}).variable(0).name(), "V0")
        self.assertEquals(mn.factor({1, 0}).variable(0).name(), "V0")

        # V2 should be the first
        mn.addFactor([2, 1])
        self.assertEquals(mn.factor({2, 1}).variable(0).name(), "V2")
        self.assertEquals(mn.factor({1, 2}).variable(0).name(), "V2")

        # 2 should be the first
        mn.addFactor({2, 3})
        self.assertEquals(
            mn.factor({2, 3}).variable(0).name(),
            mn.variable(2).name())

        # 1 should be the first
        mn.addFactor({2, 0})
        self.assertEquals(
            mn.factor({2, 0}).variable(0).name(),
            mn.variable(0).name())
Example #6
0
 def testToDot(self):
     mn = gum.fastMN("A--B--C;B--D;C--E;D--E--F")
     s1 = mn.toDot()
     s2 = mn.toDotAsFactorGraph()