Ejemplo n.º 1
0
 def setUp(self):
     self.dbn = DynamicBayesianNetwork()
Ejemplo n.º 2
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import random

import numpy

from primo.networks import BayesianNetwork
from primo.networks import DynamicBayesianNetwork
from primo.networks import TwoTBN
from primo.nodes import DiscreteNode
import primo.inference.particlefilter as pf
from primo.io import XMLBIF

# Construct a DynmaicBayesianNetwork
dbn = DynamicBayesianNetwork()
B0 = BayesianNetwork()
twoTBN = TwoTBN(XMLBIF.read("Robot_Localization.xmlbif"))

# Configure TwoTBN
x0 = twoTBN.get_node("x0")
x = twoTBN.get_node("x")
door = twoTBN.get_node("door")
twoTBN.set_initial_node(x0.name, x.name)

# Configure initial distribution
x0_init = DiscreteNode(
    x0.name, ["p0", "p1", "p2", "p3", "p4", "p5", "p6", "p7", "p8", "p9"])
B0.add_node(x0_init)
cpt_x0_init = numpy.array([.1, .1, .1, .1, .1, .1, .1, .1, .1, .1])
x0_init.set_probability_table(cpt_x0_init, [x0_init])
Ejemplo n.º 3
0
class DynamicBayesNetTest(unittest.TestCase):
    def setUp(self):
        self.dbn = DynamicBayesianNetwork()

    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.remove_edge(n1, n1)
        self.dbn.add_edge(n1, n2)
        self.assertTrue(self.dbn.is_valid())