Example #1
0
def build_net(cpts):
    states = dict()
    for name, cpt in cpts.items():
        states[name] = State(cpt, name=name)

    model = BayesianNetwork('Poker Game')
    model.add_states(*list(states.values()))

    for name, parents, _ in sheets:
        for parent in parents:
            print(states[parent])
            model.add_transition(states[parent], states[name])

    model.bake()
    return model
Example #2
0
def setup_huge_monty():
    # Build the huge monty hall huge_monty_network. This is an example I made
    # up with which may not exactly flow logically, but tests a varied type of
    # tables ensures heterogeneous types of data work together.
    global huge_monty_network, huge_monty_friend, huge_monty_guest, huge_monty
    global huge_monty_remaining, huge_monty_randomize, huge_monty_prize

    # Huge_Monty_Friend
    huge_monty_friend = DiscreteDistribution({True: 0.5, False: 0.5})

    # Huge_Monty_Guest emisisons are completely random
    huge_monty_guest = ConditionalProbabilityTable(
        [[True, 'A', 0.50],
         [True, 'B', 0.25],
         [True, 'C', 0.25],
         [False, 'A', 0.0],
         [False, 'B', 0.7],
         [False, 'C', 0.3]], [huge_monty_friend])

    # Number of huge_monty_remaining cars
    huge_monty_remaining = DiscreteDistribution({0: 0.1, 1: 0.7, 2: 0.2, })

    # Whether they huge_monty_randomize is dependent on the numnber of
    # huge_monty_remaining cars
    huge_monty_randomize = ConditionalProbabilityTable(
        [[0, True, 0.05],
         [0, False, 0.95],
         [1, True, 0.8],
         [1, False, 0.2],
         [2, True, 0.5],
         [2, False, 0.5]], [huge_monty_remaining])

    # Where the huge_monty_prize is depends on if they huge_monty_randomize or
    # not and also the huge_monty_guests huge_monty_friend
    huge_monty_prize = ConditionalProbabilityTable(
        [[True, True, 'A', 0.3],
         [True, True, 'B', 0.4],
         [True, True, 'C', 0.3],
         [True, False, 'A', 0.2],
         [True, False, 'B', 0.4],
         [True, False, 'C', 0.4],
         [False, True, 'A', 0.1],
         [False, True, 'B', 0.9],
         [False, True, 'C', 0.0],
         [False, False, 'A', 0.0],
         [False, False, 'B', 0.4],
         [False, False, 'C', 0.6]], [huge_monty_randomize, huge_monty_friend])

    # Monty is dependent on both the huge_monty_guest and the huge_monty_prize.
    huge_monty = ConditionalProbabilityTable(
        [['A', 'A', 'A', 0.0],
         ['A', 'A', 'B', 0.5],
         ['A', 'A', 'C', 0.5],
         ['A', 'B', 'A', 0.0],
         ['A', 'B', 'B', 0.0],
         ['A', 'B', 'C', 1.0],
         ['A', 'C', 'A', 0.0],
         ['A', 'C', 'B', 1.0],
         ['A', 'C', 'C', 0.0],
         ['B', 'A', 'A', 0.0],
         ['B', 'A', 'B', 0.0],
         ['B', 'A', 'C', 1.0],
         ['B', 'B', 'A', 0.5],
         ['B', 'B', 'B', 0.0],
         ['B', 'B', 'C', 0.5],
         ['B', 'C', 'A', 1.0],
         ['B', 'C', 'B', 0.0],
         ['B', 'C', 'C', 0.0],
         ['C', 'A', 'A', 0.0],
         ['C', 'A', 'B', 1.0],
         ['C', 'A', 'C', 0.0],
         ['C', 'B', 'A', 1.0],
         ['C', 'B', 'B', 0.0],
         ['C', 'B', 'C', 0.0],
         ['C', 'C', 'A', 0.5],
         ['C', 'C', 'B', 0.5],
         ['C', 'C', 'C', 0.0]], [huge_monty_guest, huge_monty_prize])

    # Make the states
    s0 = State(huge_monty_friend, name="huge_monty_friend")
    s1 = State(huge_monty_guest, name="huge_monty_guest")
    s2 = State(huge_monty_prize, name="huge_monty_prize")
    s3 = State(huge_monty, name="huge_monty")
    s4 = State(huge_monty_remaining, name="huge_monty_remaining")
    s5 = State(huge_monty_randomize, name="huge_monty_randomize")

    # Make the bayes net, add the states, and the conditional dependencies.
    huge_monty_network = BayesianNetwork("test")
    huge_monty_network.add_nodes(s0, s1, s2, s3, s4, s5)
    huge_monty_network.add_transition(s0, s1)
    huge_monty_network.add_transition(s1, s3)
    huge_monty_network.add_transition(s2, s3)
    huge_monty_network.add_transition(s4, s5)
    huge_monty_network.add_transition(s5, s2)
    huge_monty_network.add_transition(s0, s2)
    huge_monty_network.bake()
Example #3
0
def setup_huge_monty():
    # Build the huge monty hall huge_monty_network. This is an example I made
    # up with which may not exactly flow logically, but tests a varied type of
    # tables ensures heterogeneous types of data work together.
    global huge_monty_network, huge_monty_friend, huge_monty_guest, huge_monty
    global huge_monty_remaining, huge_monty_randomize, huge_monty_prize

    # Huge_Monty_Friend
    huge_monty_friend = DiscreteDistribution({True: 0.5, False: 0.5})

    # Huge_Monty_Guest emisisons are completely random
    huge_monty_guest = ConditionalProbabilityTable(
        [[True, 'A', 0.50],
         [True, 'B', 0.25],
         [True, 'C', 0.25],
         [False, 'A', 0.0],
         [False, 'B', 0.7],
         [False, 'C', 0.3]], [huge_monty_friend])

    # Number of huge_monty_remaining cars
    huge_monty_remaining = DiscreteDistribution({0: 0.1, 1: 0.7, 2: 0.2, })

    # Whether they huge_monty_randomize is dependent on the numnber of
    # huge_monty_remaining cars
    huge_monty_randomize = ConditionalProbabilityTable(
        [[0, True, 0.05],
         [0, False, 0.95],
         [1, True, 0.8],
         [1, False, 0.2],
         [2, True, 0.5],
         [2, False, 0.5]], [huge_monty_remaining])

    # Where the huge_monty_prize is depends on if they huge_monty_randomize or
    # not and also the huge_monty_guests huge_monty_friend
    huge_monty_prize = ConditionalProbabilityTable(
        [[True, True, 'A', 0.3],
         [True, True, 'B', 0.4],
         [True, True, 'C', 0.3],
         [True, False, 'A', 0.2],
         [True, False, 'B', 0.4],
         [True, False, 'C', 0.4],
         [False, True, 'A', 0.1],
         [False, True, 'B', 0.9],
         [False, True, 'C', 0.0],
         [False, False, 'A', 0.0],
         [False, False, 'B', 0.4],
         [False, False, 'C', 0.6]], [huge_monty_randomize, huge_monty_friend])

    # Monty is dependent on both the huge_monty_guest and the huge_monty_prize.
    huge_monty = ConditionalProbabilityTable(
        [['A', 'A', 'A', 0.0],
         ['A', 'A', 'B', 0.5],
         ['A', 'A', 'C', 0.5],
         ['A', 'B', 'A', 0.0],
         ['A', 'B', 'B', 0.0],
         ['A', 'B', 'C', 1.0],
         ['A', 'C', 'A', 0.0],
         ['A', 'C', 'B', 1.0],
         ['A', 'C', 'C', 0.0],
         ['B', 'A', 'A', 0.0],
         ['B', 'A', 'B', 0.0],
         ['B', 'A', 'C', 1.0],
         ['B', 'B', 'A', 0.5],
         ['B', 'B', 'B', 0.0],
         ['B', 'B', 'C', 0.5],
         ['B', 'C', 'A', 1.0],
         ['B', 'C', 'B', 0.0],
         ['B', 'C', 'C', 0.0],
         ['C', 'A', 'A', 0.0],
         ['C', 'A', 'B', 1.0],
         ['C', 'A', 'C', 0.0],
         ['C', 'B', 'A', 1.0],
         ['C', 'B', 'B', 0.0],
         ['C', 'B', 'C', 0.0],
         ['C', 'C', 'A', 0.5],
         ['C', 'C', 'B', 0.5],
         ['C', 'C', 'C', 0.0]], [huge_monty_guest, huge_monty_prize])

    # Make the states
    s0 = State(huge_monty_friend, name="huge_monty_friend")
    s1 = State(huge_monty_guest, name="huge_monty_guest")
    s2 = State(huge_monty_prize, name="huge_monty_prize")
    s3 = State(huge_monty, name="huge_monty")
    s4 = State(huge_monty_remaining, name="huge_monty_remaining")
    s5 = State(huge_monty_randomize, name="huge_monty_randomize")

    # Make the bayes net, add the states, and the conditional dependencies.
    huge_monty_network = BayesianNetwork("test")
    huge_monty_network.add_nodes(s0, s1, s2, s3, s4, s5)
    huge_monty_network.add_transition(s0, s1)
    huge_monty_network.add_transition(s1, s3)
    huge_monty_network.add_transition(s2, s3)
    huge_monty_network.add_transition(s4, s5)
    huge_monty_network.add_transition(s5, s2)
    huge_monty_network.add_transition(s0, s2)
    huge_monty_network.bake()