Exemplo n.º 1
0
    def test_get_variables_with_several_childs(self):
        root_node = BayesNetNode("root")
        child1 = BayesNetNode("child1")
        child2 = BayesNetNode("child2")
        child3 = BayesNetNode("child3")

        child1.influenced_by(root_node)
        child2.influenced_by(root_node)
        child3.influenced_by(root_node)

        bn = BayesNet([root_node])

        vars = bn.get_variables()
        self.assertSameElements(["root", "child1", "child2", "child3"], vars)
Exemplo n.º 2
0
    def test_get_variables_with_several_childs(self):
        root_node = BayesNetNode("root")
        child1 = BayesNetNode("child1")
        child2 = BayesNetNode("child2")
        child3 = BayesNetNode("child3")

        child1.influenced_by(root_node)
        child2.influenced_by(root_node)
        child3.influenced_by(root_node)

        bn = BayesNet([root_node])

        vars = bn.get_variables()
        self.assertSameElements(["root", "child1", "child2", "child3"], vars)
Exemplo n.º 3
0
def create_burglary_network():
    burglary = BayesNetNode("Burglary")
    earthQuake = BayesNetNode("EarthQuake")
    alarm = BayesNetNode("Alarm")
    johnCalls = BayesNetNode("JohnCalls")
    maryCalls = BayesNetNode("MaryCalls")

    alarm.influenced_by(burglary, earthQuake)
    johnCalls.influenced_by(alarm)
    maryCalls.influenced_by(alarm)

    burglary.set_probablity(0.001, [True])
    earthQuake.set_probablity(0.002, [True])

    alarm.set_probablity(0.95, [True, True])
    alarm.set_probablity(0.94, [True, False])
    alarm.set_probablity(0.29, [False, True])
    alarm.set_probablity(0.001, [False, False])

    johnCalls.set_probablity(0.9, [True])
    johnCalls.set_probablity(0.05, [False])

    maryCalls.set_probablity(0.7, [True])
    maryCalls.set_probablity(0.01, [False])

    return BayesNet((burglary, earthQuake))
Exemplo n.º 4
0
    def _create_wet_grass_network(self):
        cloudy_node = BayesNetNode("Cloudy")
        sprinkler_node = BayesNetNode("Sprinkler")
        rain_node = BayesNetNode("Rain")
        wet_grass_node = BayesNetNode("WetGrass")

        sprinkler_node.influenced_by(cloudy_node)
        rain_node.influenced_by(cloudy_node)
        wet_grass_node.influenced_by(rain_node, sprinkler_node)

        cloudy_node.set_probablity(0.5, [True])

        sprinkler_node.set_probablity(0.1, [True])
        sprinkler_node.set_probablity(0.5, [False])

        rain_node.set_probablity(0.8, [True])
        rain_node.set_probablity(0.2, [False])

        wet_grass_node.set_probablity(0.99, [True, True])
        wet_grass_node.set_probablity(0.9, [True, False])
        wet_grass_node.set_probablity(0.9, [False, True])
        wet_grass_node.set_probablity(0, [False, False])

        return BayesNet([cloudy_node])
Exemplo n.º 5
0
    def test_get_root_variable(self):
        root_node = BayesNetNode("root")
        bn = BayesNet([root_node])

        vars = bn.get_variables()
        self.assertSameElements(["root"], vars)
Exemplo n.º 6
0
    def test_get_root_variable(self):
        root_node = BayesNetNode("root")
        bn = BayesNet([root_node])

        vars = bn.get_variables()
        self.assertSameElements(["root"], vars)