예제 #1
0
class DynamicBayesNetTest(unittest.TestCase):
    def setUp(self):
        self.dbn = DynamicBayesNet()

    def tearDown(self):
        self.dbn = None

    def test_add_node(self):
        self.dbn.clear()
        n = DiscreteNode("Some Node", [True, False])
        self.dbn.add_node(n)
        self.assertEqual(n, self.dbn.get_node("Some Node"))
        self.assertTrue(n in self.dbn.get_nodes(["Some Node"]))

    def test_temporal_edges(self):
        self.dbn.clear()
        n1 = DiscreteNode("1", [True, False])
        n2 = DiscreteNode("2", [False, False])
        self.dbn.add_node(n1)
        self.dbn.add_node(n2)
        self.assertTrue(self.dbn.is_valid())
        self.dbn.add_edge(n1, n1)
        self.assertFalse(self.dbn.is_valid())
        self.dbn.add_edge(n1, n1, True)
        self.assertTrue(self.dbn.is_valid())
예제 #2
0
from primo.core import DynamicBayesNet
from primo.reasoning import DiscreteNode

bn = DynamicBayesNet()
burglary = DiscreteNode("Burglary", ["Intruder", "Safe"])
alarm = DiscreteNode("Alarm", ["Ringing", "Silent", "Kaputt"])
earthquake = DiscreteNode("Earthquake", ["Shaking", "Calm"])
john_calls = DiscreteNode("John calls", ["Calling", "Not Calling"])
mary_calls = DiscreteNode("Mary calls", ["Calling", "Not Calling"])


bn.add_node(burglary)
bn.add_node(alarm)
bn.add_node(earthquake)
bn.add_node(john_calls)
bn.add_node(mary_calls)


bn.add_edge(burglary, alarm)
bn.add_edge(earthquake, alarm)
bn.add_edge(alarm, john_calls)
bn.add_edge(alarm, mary_calls)

bn.add_edge(alarm, alarm, True)


print(bn.is_valid())

bn.draw()