Exemplo n.º 1
0
def get_game_network():
    """Create a Bayes Net representation
    of the game problem."""
    nodes = []
    # TODO: fill this out
    A_node = BayesNode(0, 4, name='A')
    B_node = BayesNode(1, 4, name='B')
    C_node = BayesNode(2, 4, name='C')
    AvB_node = BayesNode(3, 3, name='AvB')
    BvC_node = BayesNode(4, 3, name='BvC')
    CvA_node = BayesNode(5, 3, name='CvA')

    A_node.add_child(AvB_node)
    AvB_node.add_parent(A_node)

    B_node.add_child(AvB_node)
    AvB_node.add_parent(B_node)

    B_node.add_child(BvC_node)
    BvC_node.add_parent(B_node)

    C_node.add_child(BvC_node)
    BvC_node.add_parent(C_node)

    C_node.add_child(CvA_node)
    CvA_node.add_parent(C_node)

    A_node.add_child(CvA_node)
    CvA_node.add_parent(A_node)

    nodes.append(A_node)
    nodes.append(B_node)
    nodes.append(C_node)
    nodes.append(AvB_node)
    nodes.append(BvC_node)
    nodes.append(CvA_node)

    A_distribution = DiscreteDistribution(A_node)
    index = A_distribution.generate_index([], [])
    A_distribution[index] = [0.15, 0.45, 0.3, 0.1]
    A_node.set_dist(A_distribution)

    B_distribution = DiscreteDistribution(B_node)
    index = B_distribution.generate_index([], [])
    B_distribution[index] = [0.15, 0.45, 0.3, 0.1]
    B_node.set_dist(B_distribution)

    C_distribution = DiscreteDistribution(C_node)
    index = C_distribution.generate_index([], [])
    C_distribution[index] = [0.15, 0.45, 0.3, 0.1]
    C_node.set_dist(C_distribution)

    dist = zeros([A_node.size(), B_node.size(),
                  AvB_node.size()],
                 dtype=float32)
    dist[0, 0, :] = [0.1, 0.1, 0.8]
    dist[0, 1, :] = [0.2, 0.6, 0.2]
    dist[0, 2, :] = [0.15, 0.75, 0.1]
    dist[0, 3, :] = [0.05, 0.9, 0.05]

    dist[1, 0, :] = [0.6, 0.2, 0.2]
    dist[1, 1, :] = [0.1, 0.1, 0.8]
    dist[1, 2, :] = [0.2, 0.6, 0.2]
    dist[1, 3, :] = [0.15, 0.75, 0.1]

    dist[2, 0, :] = [0.75, 0.15, 0.1]
    dist[2, 1, :] = [0.6, 0.2, 0.2]
    dist[2, 2, :] = [0.1, 0.1, 0.8]
    dist[2, 3, :] = [0.2, 0.6, 0.2]

    dist[3, 0, :] = [0.9, 0.05, 0.05]
    dist[3, 1, :] = [0.75, 0.15, 0.1]
    dist[3, 2, :] = [0.6, 0.2, 0.2]
    dist[3, 3, :] = [0.1, 0.1, 0.8]

    AvB_distribution = ConditionalDiscreteDistribution(
        nodes=[A_node, B_node, AvB_node], table=dist)
    AvB_node.set_dist(AvB_distribution)

    BvC_distribution = ConditionalDiscreteDistribution(
        nodes=[B_node, C_node, BvC_node], table=dist)
    BvC_node.set_dist(BvC_distribution)

    CvA_distribution = ConditionalDiscreteDistribution(
        nodes=[C_node, A_node, CvA_node], table=dist)
    CvA_node.set_dist(CvA_distribution)

    print "Printing table"
    print type(AvB_node.dist.table)
    for i in range(3):
        print AvB_node.dist.table[0][0][i]

    return BayesNet(nodes)
Exemplo n.º 2
0
def get_game_network():
    """Create a Bayes Net representation of the game problem.
    Name the nodes as "A","B","C","AvB","BvC" and "CvA".  """
    nodes = []
    # TODO: fill this out

    # Create Nodes
    A = BayesNode(0, 4, name="A")
    B_node = BayesNode(1, 4, name="B")
    C_node = BayesNode(2, 4, name="C")
    AvB = BayesNode(3, 3, name="AvB")
    BvC_node = BayesNode(4, 3, name="BvC")
    CvA = BayesNode(5, 3, name="CvA")

    # A skill
    A.add_child(AvB)
    A.add_child(CvA)

    # B skill
    B_node.add_child(AvB)
    B_node.add_child(BvC_node)

    # C skill
    C_node.add_child(BvC_node)
    C_node.add_child(CvA)

    # AvB outcome
    AvB.add_parent(A)
    AvB.add_parent(B_node)

    # BvC outcome
    BvC_node.add_parent(B_node)
    BvC_node.add_parent(C_node)

    # CvA outcome
    CvA.add_parent(C_node)
    CvA.add_parent(A)

    # Set Probability Distributions
    # A, B, C team skill levels
    A_distribution = DiscreteDistribution(A)
    index = A_distribution.generate_index([], [])
    A_distribution[index] = [0.15, 0.45, 0.3, 0.1]
    A.set_dist(A_distribution)

    B_distribution = DiscreteDistribution(B_node)
    index = B_distribution.generate_index([], [])
    B_distribution[index] = [0.15, 0.45, 0.3, 0.1]
    B_node.set_dist(B_distribution)

    C_distribution = DiscreteDistribution(C_node)
    index = C_distribution.generate_index([], [])
    C_distribution[index] = [0.15, 0.45, 0.3, 0.1]
    C_node.set_dist(C_distribution)

    # AvB, BvC, CvA game outcomes
    dist = zeros([A.size(), B_node.size(), AvB.size()], dtype=float32)
    dist[0, 0, :] = [0.1, 0.1, 0.8]
    dist[0, 1, :] = [0.2, 0.6, 0.2]
    dist[0, 2, :] = [0.15, 0.75, 0.1]
    dist[0, 3, :] = [0.05, 0.9, 0.05]
    dist[1, 0, :] = [0.6, 0.2, 0.2]
    dist[1, 1, :] = [0.1, 0.1, 0.8]
    dist[1, 2, :] = [0.2, 0.6, 0.2]
    dist[1, 3, :] = [0.15, 0.75, 0.1]
    dist[2, 0, :] = [0.75, 0.15, 0.1]
    dist[2, 1, :] = [0.6, 0.2, 0.2]
    dist[2, 2, :] = [0.1, 0.1, 0.8]
    dist[2, 3, :] = [0.2, 0.6, 0.2]
    dist[3, 0, :] = [0.9, 0.05, 0.05]
    dist[3, 1, :] = [0.75, 0.15, 0.1]
    dist[3, 2, :] = [0.6, 0.2, 0.2]
    dist[3, 3, :] = [0.1, 0.1, 0.8]

    AvB_distribution = ConditionalDiscreteDistribution(nodes=[A, B_node, AvB],
                                                       table=dist)
    AvB.set_dist(AvB_distribution)
    BvC_distribution = ConditionalDiscreteDistribution(
        nodes=[B_node, C_node, BvC_node], table=dist)
    BvC_node.set_dist(BvC_distribution)
    CvA_distribution = ConditionalDiscreteDistribution(nodes=[C_node, A, CvA],
                                                       table=dist)
    CvA.set_dist(CvA_distribution)

    nodes = [A, B_node, C_node, AvB, BvC_node, CvA]

    return BayesNet(nodes)
Exemplo n.º 3
0
def get_game_network():
    """Create a Bayes Net representation of the game problem.
    Name the nodes as "A","B","C","AvB","BvC" and "CvA".  """

    nodenames = ["A", "B", "C", "AvB", "BvC", "CvA"]

    A_node = BayesNode(0, 4, name=nodenames[0])
    B_node = BayesNode(1, 4, name=nodenames[1])
    C_node = BayesNode(2, 4, name=nodenames[2])
    AvB_node = BayesNode(3, 3, name=nodenames[3])
    BvC_node = BayesNode(4, 3, name=nodenames[4])
    CvA_node = BayesNode(5, 3, name=nodenames[5])

    A_node.add_child(AvB_node)
    A_node.add_child(CvA_node)
    B_node.add_child(AvB_node)
    B_node.add_child(BvC_node)
    C_node.add_child(BvC_node)
    C_node.add_child(CvA_node)
    AvB_node.add_parent(A_node)
    AvB_node.add_parent(B_node)
    BvC_node.add_parent(B_node)
    BvC_node.add_parent(C_node)
    CvA_node.add_parent(C_node)
    CvA_node.add_parent(A_node)

    A_distribution = DiscreteDistribution(A_node)
    index = A_distribution.generate_index([], [])
    A_distribution[index] = [0.15, 0.45, 0.30, 0.10]
    A_node.set_dist(A_distribution)

    B_distribution = DiscreteDistribution(B_node)
    index = B_distribution.generate_index([], [])
    B_distribution[index] = [0.15, 0.45, 0.30, 0.10]
    B_node.set_dist(B_distribution)

    C_distribution = DiscreteDistribution(C_node)
    index = C_distribution.generate_index([], [])
    C_distribution[index] = [0.15, 0.45, 0.30, 0.10]
    C_node.set_dist(C_distribution)

    dist = zeros([A_node.size(), B_node.size(),
                  AvB_node.size()],
                 dtype=float32)
    dist[0, 0, :] = [0.10, 0.10, 0.80]
    dist[0, 1, :] = [0.20, 0.60, 0.20]
    dist[0, 2, :] = [0.15, 0.75, 0.10]
    dist[0, 3, :] = [0.05, 0.90, 0.05]

    dist[1, 0, :] = [0.60, 0.20, 0.20]
    dist[1, 1, :] = [0.10, 0.10, 0.80]
    dist[1, 2, :] = [0.20, 0.60, 0.20]
    dist[1, 3, :] = [0.15, 0.75, 0.10]

    dist[2, 0, :] = [0.75, 0.15, 0.10]
    dist[2, 1, :] = [0.60, 0.20, 0.20]
    dist[2, 2, :] = [0.10, 0.10, 0.80]
    dist[2, 3, :] = [0.20, 0.60, 0.20]

    dist[3, 0, :] = [0.90, 0.05, 0.05]
    dist[3, 1, :] = [0.75, 0.15, 0.10]
    dist[3, 2, :] = [0.60, 0.20, 0.20]
    dist[3, 3, :] = [0.10, 0.10, 0.80]
    AvB_distribution = ConditionalDiscreteDistribution(
        nodes=[A_node, B_node, AvB_node], table=dist)
    AvB_node.set_dist(AvB_distribution)

    dist = zeros([B_node.size(), C_node.size(),
                  BvC_node.size()],
                 dtype=float32)
    dist[0, 0, :] = [0.10, 0.10, 0.80]
    dist[0, 1, :] = [0.20, 0.60, 0.20]
    dist[0, 2, :] = [0.15, 0.75, 0.10]
    dist[0, 3, :] = [0.05, 0.90, 0.05]

    dist[1, 0, :] = [0.60, 0.20, 0.20]
    dist[1, 1, :] = [0.10, 0.10, 0.80]
    dist[1, 2, :] = [0.20, 0.60, 0.20]
    dist[1, 3, :] = [0.15, 0.75, 0.10]

    dist[2, 0, :] = [0.75, 0.15, 0.10]
    dist[2, 1, :] = [0.60, 0.20, 0.20]
    dist[2, 2, :] = [0.10, 0.10, 0.80]
    dist[2, 3, :] = [0.20, 0.60, 0.20]

    dist[3, 0, :] = [0.90, 0.05, 0.05]
    dist[3, 1, :] = [0.75, 0.15, 0.10]
    dist[3, 2, :] = [0.60, 0.20, 0.20]
    dist[3, 3, :] = [0.10, 0.10, 0.80]
    BvC_distribution = ConditionalDiscreteDistribution(
        nodes=[B_node, C_node, BvC_node], table=dist)
    BvC_node.set_dist(BvC_distribution)

    dist = zeros([C_node.size(), A_node.size(),
                  CvA_node.size()],
                 dtype=float32)
    dist[0, 0, :] = [0.10, 0.10, 0.80]
    dist[0, 1, :] = [0.20, 0.60, 0.20]
    dist[0, 2, :] = [0.15, 0.75, 0.10]
    dist[0, 3, :] = [0.05, 0.90, 0.05]

    dist[1, 0, :] = [0.60, 0.20, 0.20]
    dist[1, 1, :] = [0.10, 0.10, 0.80]
    dist[1, 2, :] = [0.20, 0.60, 0.20]
    dist[1, 3, :] = [0.15, 0.75, 0.10]

    dist[2, 0, :] = [0.75, 0.15, 0.10]
    dist[2, 1, :] = [0.60, 0.20, 0.20]
    dist[2, 2, :] = [0.10, 0.10, 0.80]
    dist[2, 3, :] = [0.20, 0.60, 0.20]

    dist[3, 0, :] = [0.90, 0.05, 0.05]
    dist[3, 1, :] = [0.75, 0.15, 0.10]
    dist[3, 2, :] = [0.60, 0.20, 0.20]
    dist[3, 3, :] = [0.10, 0.10, 0.80]
    CvA_distribution = ConditionalDiscreteDistribution(
        nodes=[C_node, A_node, CvA_node], table=dist)
    CvA_node.set_dist(CvA_distribution)

    nodes = [A_node, B_node, C_node, AvB_node, BvC_node, CvA_node]

    return BayesNet(nodes)

    # TODO: fill this out
    raise NotImplementedError
Exemplo n.º 4
0
def get_game_network():
    """A Bayes Net representation
    of the game problem."""
    nodes = []
    # TODO: fill this out
    A_node = BayesNode(0, 4, name='A')
    B_node = BayesNode(1, 4, name='B')
    C_node = BayesNode(2, 4, name='C')
    AvB_node = BayesNode(3, 3, name='A vs B')
    BvC_node = BayesNode(4, 3, name='B vs C')
    CvA_node = BayesNode(5, 3, name='C vs A')
    nodes = []
    
    A_node.add_child(AvB_node)
    AvB_node.add_parent(A_node)
    B_node.add_child(AvB_node)
    AvB_node.add_parent(B_node)
    
    B_node.add_child(BvC_node)
    BvC_node.add_parent(B_node)
    C_node.add_child(BvC_node)
    BvC_node.add_parent(C_node)
    
    C_node.add_child(CvA_node)
    CvA_node.add_parent(C_node)
    A_node.add_child(CvA_node)
    CvA_node.add_parent(A_node)
    
    nodes.append(A_node)
    nodes.append(B_node)
    nodes.append(C_node)
    nodes.append(AvB_node)    
    nodes.append(BvC_node)
    nodes.append(CvA_node)

    A_distribution = DiscreteDistribution(A_node)
    index = A_distribution.generate_index([],[])
    A_distribution[index] = [0.15,0.45,0.3,0.1]
    A_node.set_dist(A_distribution)
    
    B_distribution = DiscreteDistribution(B_node)
    index = B_distribution.generate_index([],[])
    B_distribution[index] = [0.15,0.45,0.3,0.1]
    B_node.set_dist(B_distribution)
   
    C_distribution = DiscreteDistribution(C_node)
    index = C_distribution.generate_index([],[])
    C_distribution[index] = [0.15,0.45,0.3,0.1]
    C_node.set_dist(C_distribution)
    
    dist = zeros([A_node.size(), B_node.size(), AvB_node.size()], dtype=float32)
    # T2-T1=0
    dist[0,0,:] = [0.10,0.10,0.80]
    dist[1,1,:] = [0.10,0.10,0.80]
    dist[2,2,:] = [0.10,0.10,0.80]
    dist[3,3,:] = [0.10,0.10,0.80]
    # T2-T1=1
    dist[0,1,:] = [0.20,0.60,0.20]
    dist[1,2,:] = [0.20,0.60,0.20]
    dist[2,3,:] = [0.20,0.60,0.20]
    dist[1,0,:] = [0.60,0.20,0.20]
    dist[2,1,:] = [0.60,0.20,0.20]
    dist[3,2,:] = [0.60,0.20,0.20]
    # T2-T1=2
    dist[0,2,:] = [0.15,0.75,0.10]
    dist[1,3,:] = [0.15,0.75,0.10]
    dist[2,0,:] = [0.75,0.15,0.10]
    dist[3,1,:] = [0.75,0.15,0.10]
    # T2-T1=3
    dist[0,3,:] = [0.05,0.90,0.05]
    dist[3,0,:] = [0.90,0.05,0.05]
    
    AvB_distribution = ConditionalDiscreteDistribution(nodes=[A_node, B_node, AvB_node], table=dist)
    AvB_node.set_dist(AvB_distribution)
    
    # P(BvC|B,C)
    dist = zeros([B_node.size(), C_node.size(), BvC_node.size()], dtype=float32)
    # T2-T1=0
    dist[0,0,:] = [0.10,0.10,0.80]
    dist[1,1,:] = [0.10,0.10,0.80]
    dist[2,2,:] = [0.10,0.10,0.80]
    dist[3,3,:] = [0.10,0.10,0.80]
    # T2-T1=1
    dist[0,1,:] = [0.20,0.60,0.20]
    dist[1,2,:] = [0.20,0.60,0.20]
    dist[2,3,:] = [0.20,0.60,0.20]
    dist[1,0,:] = [0.60,0.20,0.20]
    dist[2,1,:] = [0.60,0.20,0.20]
    dist[3,2,:] = [0.60,0.20,0.20]
    # T2-T1=2
    dist[0,2,:] = [0.15,0.75,0.10]
    dist[1,3,:] = [0.15,0.75,0.10]
    dist[2,0,:] = [0.75,0.15,0.10]
    dist[3,1,:] = [0.75,0.15,0.10]
    # T2-T1=3
    dist[0,3,:] = [0.05,0.90,0.05]
    dist[3,0,:] = [0.90,0.05,0.05]
    
    BvC_distribution = ConditionalDiscreteDistribution(nodes=[B_node, C_node, BvC_node], table=dist)
    BvC_node.set_dist(BvC_distribution)
    
    # P(CvA|C,A)
    dist = zeros([C_node.size(), A_node.size(), CvA_node.size()], dtype=float32)
    # T2-T1=0
    dist[0,0,:] = [0.10,0.10,0.80]
    dist[1,1,:] = [0.10,0.10,0.80]
    dist[2,2,:] = [0.10,0.10,0.80]
    dist[3,3,:] = [0.10,0.10,0.80]
    # T2-T1=1
    dist[0,1,:] = [0.20,0.60,0.20]
    dist[1,2,:] = [0.20,0.60,0.20]
    dist[2,3,:] = [0.20,0.60,0.20]
    dist[1,0,:] = [0.60,0.20,0.20]
    dist[2,1,:] = [0.60,0.20,0.20]
    dist[3,2,:] = [0.60,0.20,0.20]
    # T2-T1=2
    dist[0,2,:] = [0.15,0.75,0.10]
    dist[1,3,:] = [0.15,0.75,0.10]
    dist[2,0,:] = [0.75,0.15,0.10]
    dist[3,1,:] = [0.75,0.15,0.10]
    # T2-T1=3
    dist[0,3,:] = [0.05,0.90,0.05]
    dist[3,0,:] = [0.90,0.05,0.05]
    
    CvA_distribution = ConditionalDiscreteDistribution(nodes=[C_node, A_node, CvA_node], table=dist)
    CvA_node.set_dist(CvA_distribution)
   
    return BayesNet(nodes)
def get_game_network():
    """Create a Bayes Net representation of the game problem.
    Name the nodes as "A","B","C","AvB","BvC" and "CvA".  """

    # TODO: fill this out
    A = BayesNode(0, 4, name='A')
    B = BayesNode(1, 4, name='B')
    C = BayesNode(2, 4, name='C')
    AB = BayesNode(3, 3, name='AvB')
    BC = BayesNode(4, 3, name='BvC')
    CA = BayesNode(5, 3, name='CvA')
    A.add_child(AB)
    A.add_child(CA)
    B.add_child(AB)
    B.add_child(BC)
    C.add_child(BC)
    C.add_child(CA)
    AB.add_parent(A)
    AB.add_parent(B)
    BC.add_parent(B)
    BC.add_parent(C)
    CA.add_parent(A)
    CA.add_parent(C)

    # Set A distribution
    A_distribution = DiscreteDistribution(A)
    index = A_distribution.generate_index([], [])
    A_distribution[index] = [0.15, 0.45, 0.30, 0.10]
    A.set_dist(A_distribution)

    # Set B distribution
    B_distribution = DiscreteDistribution(B)
    index = B_distribution.generate_index([], [])
    B_distribution[index] = [0.15, 0.45, 0.30, 0.10]
    B.set_dist(B_distribution)

    # Set C distribution
    C_distribution = DiscreteDistribution(C)
    index = C_distribution.generate_index([], [])
    C_distribution[index] = [0.15, 0.45, 0.30, 0.10]
    C.set_dist(C_distribution)

    # Set distribution of AvB given A and B
    dist = zeros([A.size(), B.size(), AB.size()], dtype=float32)
    dist[0, 0, :] = [0.10, 0.10, 0.80]
    dist[0, 1, :] = [0.20, 0.60, 0.20]
    dist[0, 2, :] = [0.15, 0.75, 0.10]
    dist[0, 3, :] = [0.05, 0.90, 0.05]
    dist[1, 0, :] = [0.60, 0.20, 0.20]
    dist[1, 1, :] = [0.10, 0.10, 0.80]
    dist[1, 2, :] = [0.20, 0.60, 0.20]
    dist[1, 3, :] = [0.15, 0.75, 0.10]
    dist[2, 0, :] = [0.75, 0.15, 0.10]
    dist[2, 1, :] = [0.60, 0.20, 0.20]
    dist[2, 2, :] = [0.10, 0.10, 0.80]
    dist[2, 3, :] = [0.20, 0.60, 0.20]
    dist[3, 0, :] = [0.90, 0.05, 0.05]
    dist[3, 1, :] = [0.75, 0.15, 0.10]
    dist[3, 2, :] = [0.60, 0.20, 0.20]
    dist[3, 3, :] = [0.10, 0.10, 0.80]
    AB_distribution = ConditionalDiscreteDistribution(nodes=[A, B, AB],
                                                      table=dist)
    AB.set_dist(AB_distribution)

    # Set distribution of BvC given B and C
    dist = zeros([B.size(), C.size(), BC.size()], dtype=float32)
    dist[0, 0, :] = [0.10, 0.10, 0.80]
    dist[0, 1, :] = [0.20, 0.60, 0.20]
    dist[0, 2, :] = [0.15, 0.75, 0.10]
    dist[0, 3, :] = [0.05, 0.90, 0.05]
    dist[1, 0, :] = [0.60, 0.20, 0.20]
    dist[1, 1, :] = [0.10, 0.10, 0.80]
    dist[1, 2, :] = [0.20, 0.60, 0.20]
    dist[1, 3, :] = [0.15, 0.75, 0.10]
    dist[2, 0, :] = [0.75, 0.15, 0.10]
    dist[2, 1, :] = [0.60, 0.20, 0.20]
    dist[2, 2, :] = [0.10, 0.10, 0.80]
    dist[2, 3, :] = [0.20, 0.60, 0.20]
    dist[3, 0, :] = [0.90, 0.05, 0.05]
    dist[3, 1, :] = [0.75, 0.15, 0.10]
    dist[3, 2, :] = [0.60, 0.20, 0.20]
    dist[3, 3, :] = [0.10, 0.10, 0.80]
    BC_distribution = ConditionalDiscreteDistribution(nodes=[B, C, BC],
                                                      table=dist)
    BC.set_dist(BC_distribution)

    # Set distribution of CA giveen C and A
    dist = zeros([C.size(), A.size(), CA.size()], dtype=float32)
    dist[0, 0, :] = [0.10, 0.10, 0.80]
    dist[0, 1, :] = [0.20, 0.60, 0.20]
    dist[0, 2, :] = [0.15, 0.75, 0.10]
    dist[0, 3, :] = [0.05, 0.90, 0.05]
    dist[1, 0, :] = [0.60, 0.20, 0.20]
    dist[1, 1, :] = [0.10, 0.10, 0.80]
    dist[1, 2, :] = [0.20, 0.60, 0.20]
    dist[1, 3, :] = [0.15, 0.75, 0.10]
    dist[2, 0, :] = [0.75, 0.15, 0.10]
    dist[2, 1, :] = [0.60, 0.20, 0.20]
    dist[2, 2, :] = [0.10, 0.10, 0.80]
    dist[2, 3, :] = [0.20, 0.60, 0.20]
    dist[3, 0, :] = [0.90, 0.05, 0.05]
    dist[3, 1, :] = [0.75, 0.15, 0.10]
    dist[3, 2, :] = [0.60, 0.20, 0.20]
    dist[3, 3, :] = [0.10, 0.10, 0.80]
    CA_distribution = ConditionalDiscreteDistribution(nodes=[C, A, CA],
                                                      table=dist)
    CA.set_dist(CA_distribution)

    nodes = [A, B, C, AB, BC, CA]
    return BayesNet(nodes)
def make_final_net():
    A = BayesNode(0, 2, name='A')
    B = BayesNode(1, 2, name='B')
    C = BayesNode(2, 2, name='C')
    D = BayesNode(3, 2, name='D')
    E = BayesNode(4, 2, name='E')

    A.add_child(C)
    C.add_parent(A)
    B.add_child(C)
    C.add_parent(B)
    B.add_child(D)
    D.add_parent(B)
    C.add_child(E)
    E.add_parent(C)
    D.add_child(E)
    E.add_parent(D)

    nodes = [A, B, C, D, E]
    net = BayesNet(nodes)

    A = net.get_node_by_name('A')
    B = net.get_node_by_name('B')
    C = net.get_node_by_name('C')
    D = net.get_node_by_name('D')
    E = net.get_node_by_name('E')

    A_distribution = DiscreteDistribution(A)
    index = A_distribution.generate_index([], [])
    A_distribution[index] = [0.4, 0.6]
    A.set_dist(A_distribution)

    B_distribution = DiscreteDistribution(B)
    index = B_distribution.generate_index([], [])
    B_distribution[index] = [0.8, 0.2]
    B.set_dist(B_distribution)

    print B, D
    dist = zeros([B.size(), D.size()], dtype=float32)
    dist[0, :] = [0.87, 0.13]
    dist[1, :] = [0.24, 0.76]
    D_distribution = ConditionalDiscreteDistribution(nodes=[B, D], table=dist)
    D.set_dist(D_distribution)

    dist = zeros([A.size(), B.size(), C.size()], dtype=float32)
    dist[0, 0, :] = [0.85, 0.15]
    dist[0, 1, :] = [0.68, 0.32]
    dist[1, 0, :] = [0.16, 0.84]
    dist[1, 1, :] = [0.05, 0.95]
    C_distribution = ConditionalDiscreteDistribution(nodes=[A, B, C],
                                                     table=dist)
    C.set_dist(C_distribution)

    dist = zeros([C.size(), D.size(), E.size()], dtype=float32)
    dist[0, 0, :] = [0.8, 0.2]
    dist[0, 1, :] = [0.37, 0.63]
    dist[1, 0, :] = [0.08, 0.92]
    dist[1, 1, :] = [0.07, 0.93]
    E_distribution = ConditionalDiscreteDistribution(nodes=[C, D, E],
                                                     table=dist)
    E.set_dist(E_distribution)

    engine = EnumerationEngine(net)
    #    engine1.evidence[wear] = False
    #    engine1.evidence[weap] = True
    engine.evidence[A] = True
    engine.evidence[C] = True
    Q = engine.marginal(E)[0]
    index = Q.generate_index([True], range(Q.nDims))
    prob = Q[index]
    print prob
def get_game_network():
    """Create a Bayes Net representation
    of the game problem."""
    nodes = []
    # TODO: fill this out
    A_node = BayesNode(0,4,name='A')
    B_node = BayesNode(1,4,name='B')
    C_node = BayesNode(2,4,name='C')
    AvB_node = BayesNode(3,3,name='AvB')
    BvC_node = BayesNode(4,3,name='BvC')
    CvA_node = BayesNode(5,3,name='CvA')
    
    A_node.add_child(AvB_node)
    AvB_node.add_parent(A_node)
    
    B_node.add_child(AvB_node)
    AvB_node.add_parent(B_node)
    
    B_node.add_child(BvC_node)
    BvC_node.add_parent(B_node)
    
    C_node.add_child(BvC_node)
    BvC_node.add_parent(C_node)
    
    C_node.add_child(CvA_node)
    CvA_node.add_parent(C_node)
    
    A_node.add_child(CvA_node)
    CvA_node.add_parent(A_node)
    
    nodes.append(A_node)
    nodes.append(B_node)
    nodes.append(C_node)
    nodes.append(AvB_node)
    nodes.append(BvC_node)
    nodes.append(CvA_node)
    
    A_distribution = DiscreteDistribution(A_node)
    index = A_distribution.generate_index([],[])
    A_distribution[index] = [0.15,0.45,0.3,0.1]
    A_node.set_dist(A_distribution)
    
    B_distribution = DiscreteDistribution(B_node)
    index = B_distribution.generate_index([],[])
    B_distribution[index] = [0.15,0.45,0.3,0.1]
    B_node.set_dist(B_distribution)
    
    C_distribution = DiscreteDistribution(C_node)
    index = C_distribution.generate_index([],[])
    C_distribution[index] = [0.15,0.45,0.3,0.1]
    C_node.set_dist(C_distribution)
    
    dist = zeros([A_node.size(), B_node.size(), AvB_node.size()], dtype=float32)
    dist[0,0,:] = [0.1, 0.1, 0.8]
    dist[0,1,:] = [0.2, 0.6, 0.2]
    dist[0,2,:] = [0.15, 0.75, 0.1]
    dist[0,3,:] = [0.05, 0.9, 0.05]
    
    dist[1,0,:] = [0.6, 0.2, 0.2]
    dist[1,1,:] = [0.1, 0.1, 0.8]
    dist[1,2,:] = [0.2, 0.6, 0.2]
    dist[1,3,:] = [0.15, 0.75, 0.1]
    
    dist[2,0,:] = [0.75, 0.15, 0.1]
    dist[2,1,:] = [0.6, 0.2, 0.2]
    dist[2,2,:] = [0.1, 0.1, 0.8]
    dist[2,3,:] = [0.2, 0.6, 0.2]
    
    dist[3,0,:] = [0.9, 0.05, 0.05]
    dist[3,1,:] = [0.75, 0.15, 0.1]
    dist[3,2,:] = [0.6, 0.2, 0.2]
    dist[3,3,:] = [0.1, 0.1, 0.8]

    AvB_distribution = ConditionalDiscreteDistribution(nodes=[A_node, B_node, AvB_node], table=dist)
    AvB_node.set_dist(AvB_distribution)
    
    BvC_distribution = ConditionalDiscreteDistribution(nodes=[B_node, C_node, BvC_node], table=dist)
    BvC_node.set_dist(BvC_distribution)
    
    CvA_distribution = ConditionalDiscreteDistribution(nodes=[C_node, A_node, CvA_node], table=dist)
    CvA_node.set_dist(CvA_distribution)
    
    print "Printing table"
    print type(AvB_node.dist.table)
    for i in range(3):
        print AvB_node.dist.table[0][0][i]
    
    return BayesNet(nodes)
Exemplo n.º 8
0
def get_game_network():
    # intial setup for problem described above
    nodes = []
    numberOfNodes = 6
    A = 0
    B = 1
    C = 2
    AvB = 3
    BvC = 4
    CvA = 5

    # create the nodes
    A_node = BayesNode(0, 4, name='A')
    B_node = BayesNode(1, 4, name='B')
    C_node = BayesNode(2, 4, name='C')
    AvB_node = BayesNode(3, 3, name='AvB')
    BvC_node = BayesNode(4, 3, name='BvC')
    CvA_node = BayesNode(5, 3, name='CvA')

    # setup A Node prior distribution
    A_distribution = DiscreteDistribution(A_node)
    index = A_distribution.generate_index([], [])
    A_distribution[index] = [0.15, 0.45, 0.3, 0.1]
    A_node.set_dist(A_distribution)

    # setup B Node prior distribution
    B_distribution = DiscreteDistribution(B_node)
    index = B_distribution.generate_index([], [])
    B_distribution[index] = [0.15, 0.45, 0.3, 0.1]
    B_node.set_dist(B_distribution)

    # setup C Node prior distribution
    C_distribution = DiscreteDistribution(C_node)
    index = C_distribution.generate_index([], [])
    C_distribution[index] = [0.15, 0.45, 0.3, 0.1]
    C_node.set_dist(C_distribution)

    # Probabilty Table for Matchup of Two Teams based on Skill Difference
    # | skill difference (T2 - T1)      | T1 wins       | T2 wins       | Tie |
    # |0                                |0.10           |0.10           |0.80|
    # |1                                |0.20           |0.60           |0.20|
    # |2                                |0.15           |0.75           |0.10|
    # |3                                |0.05           |0.90           |0.05|
    # |-1                               |0.60           |0.20           |0.20|
    # |-2                               |0.75           |0.15           |0.10|
    # |-3                               |0.90           |0.05           |0.05|

    # setup AvB Node distribution
    AvB_distribution = DiscreteDistribution(AvB_node)
    dist = zeros([A_node.size(), B_node.size(),
                  AvB_node.size()],
                 dtype=float32)
    for a in range(A_node.size()):
        for b in range(B_node.size()):
            if (b - a) == -3:
                dist[a, b, :] = [0.90, 0.05, 0.05]
            elif (b - a) == -2:
                dist[a, b, :] = [0.75, 0.15, 0.10]
            elif (b - a) == -1:
                dist[a, b, :] = [0.60, 0.20, 0.20]
            elif (b - a) == 0:
                dist[a, b, :] = [0.10, 0.10, 0.80]
            elif (b - a) == 1:
                dist[a, b, :] = [0.20, 0.60, 0.20]
            elif (b - a) == 2:
                dist[a, b, :] = [0.15, 0.75, 0.10]
            elif (b - a) == 3:
                dist[a, b, :] = [0.05, 0.90, 0.05]
            else:
                print "ERROR in AvB node setup"
    AvB_distribution = ConditionalDiscreteDistribution(
        nodes=[A_node, B_node, AvB_node], table=dist)
    AvB_node.set_dist(AvB_distribution)

    # setup BvC Node distribution
    BvC_distribution = DiscreteDistribution(BvC_node)
    dist = zeros([B_node.size(), C_node.size(),
                  BvC_node.size()],
                 dtype=float32)
    for b in range(B_node.size()):
        for c in range(C_node.size()):
            if (c - b) == -3:
                dist[b, c, :] = [0.90, 0.05, 0.05]
            elif (c - b) == -2:
                dist[b, c, :] = [0.75, 0.15, 0.10]
            elif (c - b) == -1:
                dist[b, c, :] = [0.60, 0.20, 0.20]
            elif (c - b) == 0:
                dist[b, c, :] = [0.10, 0.10, 0.80]
            elif (c - b) == 1:
                dist[b, c, :] = [0.20, 0.60, 0.20]
            elif (c - b) == 2:
                dist[b, c, :] = [0.15, 0.75, 0.10]
            elif (c - b) == 3:
                dist[b, c, :] = [0.05, 0.90, 0.05]
            else:
                print "ERROR in BvC node setup"
    BvC_distribution = ConditionalDiscreteDistribution(
        nodes=[B_node, C_node, BvC_node], table=dist)
    BvC_node.set_dist(BvC_distribution)

    # setup CvA Node distribution
    CvA_distribution = DiscreteDistribution(CvA_node)
    dist = zeros([C_node.size(), A_node.size(),
                  CvA_node.size()],
                 dtype=float32)
    for c in range(C_node.size()):
        for a in range(A_node.size()):
            if (a - c) == -3:
                dist[c, a, :] = [0.90, 0.05, 0.05]
            elif (a - c) == -2:
                dist[c, a, :] = [0.75, 0.15, 0.10]
            elif (a - c) == -1:
                dist[c, a, :] = [0.60, 0.20, 0.20]
            elif (a - c) == 0:
                dist[c, a, :] = [0.10, 0.10, 0.80]
            elif (a - c) == 1:
                dist[c, a, :] = [0.20, 0.60, 0.20]
            elif (a - c) == 2:
                dist[c, a, :] = [0.15, 0.75, 0.10]
            elif (a - c) == 3:
                dist[c, a, :] = [0.05, 0.90, 0.05]
            else:
                print "ERROR in CvA node setup"
    CvA_distribution = ConditionalDiscreteDistribution(
        nodes=[C_node, A_node, CvA_node], table=dist)
    CvA_node.set_dist(CvA_distribution)

    # Setup Network (Parents & Children)
    # A
    A_node.add_child(AvB_node)
    A_node.add_child(CvA_node)

    # B
    B_node.add_child(AvB_node)
    B_node.add_child(BvC_node)

    # C
    C_node.add_child(BvC_node)
    C_node.add_child(CvA_node)

    # AvB
    AvB_node.add_parent(A_node)
    AvB_node.add_parent(B_node)

    # BvC
    BvC_node.add_parent(B_node)
    BvC_node.add_parent(C_node)

    # CvA
    CvA_node.add_parent(C_node)
    CvA_node.add_parent(A_node)

    # add the nodes for setting up network
    nodes = [A_node, B_node, C_node, AvB_node, BvC_node, CvA_node]
    return BayesNet(nodes)
Exemplo n.º 9
0
def make_exam_net():
    """Create a Bayes Net representation of the above power plant problem.
    Name the nodes as "alarm","faulty alarm", "gauge","faulty gauge", "temperature".
    """
    nodes = []
    # TODO: finish this function

    #create nodes ---> refer node.py
    MA = BayesNode(0, 2, name="main alarm")
    A1 = BayesNode(1, 2, name="alarm 2")
    A2 = BayesNode(2, 2, name="alarm 1")
    A3 = BayesNode(3, 2, name="alarm 3")
    G = BayesNode(4, 2, name="ghost")
    B = BayesNode(5, 2, name="burglar")

    MA.add_parent(G)
    MA.add_parent(B)


    dist = zeros([G.size(), B.size(), MA.size()], dtype=float32)
    dist[0,0,:] = [0.99, 0.01]
    dist[0,1,:] = [0.36, 0.64]
    dist[1,0,:] = [0.75, 0.25]
    dist[1,1,:] = [0.02, 0.98]

    MA_distribution = ConditionalDiscreteDistribution(nodes=[G, B, MA], table=dist)
    MA.set_dist(MA_distribution)


    G.add_child(MA)
    G.add_child(A2)
    G.add_child(A1)

    G_distribution = DiscreteDistribution(G)
    index = G_distribution.generate_index([],[])
    G_distribution[index] = [0.6,0.4]
    G.set_dist(G_distribution)

    B.add_child(MA)
    B.add_child(A2)
    B.add_child(A3)

    B_distribution = DiscreteDistribution(B)
    index = B_distribution.generate_index([],[])
    B_distribution[index] = [0.68,0.32]
    B.set_dist(B_distribution)

    A1.add_parent(G)

    A1_distribution = DiscreteDistribution(A1)
    dist = zeros([G.size(), A1.size()], dtype=float32)   #Note the order of G_node, A_node
    dist[0,:] = [0.91, 0.09]
    dist[1,:] = [0.18, 0.82]
    A1_distribution = ConditionalDiscreteDistribution(nodes=[G,A1], table=dist)
    A1.set_dist(A1_distribution)


    A2.add_parent(G)
    A2.add_parent(B)

    dist = zeros([G.size(), B.size(), A2.size()], dtype=float32)
    dist[0,0,:] = [0.95, 0.05]
    dist[0,1,:] = [0.37, 0.63]
    dist[1,0,:] = [0.69, 0.31]
    dist[1,1,:] = [0.13, 0.87]

    A2_distribution = ConditionalDiscreteDistribution(nodes=[G, B, A2], table=dist)
    A2.set_dist(A2_distribution)

    A3.add_parent(B)

    A3_distribution = DiscreteDistribution(A3)
    dist = zeros([B.size(), A3.size()], dtype=float32)   #Note the order of G_node, A_node
    dist[0,:] = [0.28, 0.72]
    dist[1,:] = [0.81, 0.19]
    A3_distribution = ConditionalDiscreteDistribution(nodes=[B,A3], table=dist)
    A3.set_dist(A3_distribution)

    nodes = [MA,A1,A2,A3,G,B]

    return BayesNet(nodes)
Exemplo n.º 10
0
def get_game_network():
    """Create a Bayes Net representation of the game problem.
    Name the nodes as "A","B","C","AvB","BvC" and "CvA".  """

    teama_node = BayesNode(0,4,name='A')
    teamb_node = BayesNode(1,4,name='B')
    teamc_node = BayesNode(2,4,name='C')
    matchAvB_node = BayesNode(3,3,name='AvB')
    matchBvC_node = BayesNode(4,3,name='BvC')
    matchCvA_node = BayesNode(5,3,name='CvA')


    teama_node.add_child(matchAvB_node)
    matchAvB_node.add_parent(teama_node)

    teama_node.add_child(matchCvA_node)
    matchCvA_node.add_parent(teama_node)

    teamb_node.add_child(matchAvB_node)
    matchAvB_node.add_parent(teamb_node)

    teamb_node.add_child(matchBvC_node)
    matchBvC_node.add_parent(teamb_node)

    teamc_node.add_child(matchBvC_node)
    matchBvC_node.add_parent(teamc_node)

    teamc_node.add_child(matchCvA_node)
    matchCvA_node.add_parent(teamc_node)

    skill_dist = [0.15,0.45,0.30,0.10]

    teama_distribution = DiscreteDistribution(teama_node)
    index = teama_distribution.generate_index([],[])
    teama_distribution[index] = skill_dist
    teama_node.set_dist(teama_distribution)

    teamb_distribution = DiscreteDistribution(teamb_node)
    index = teamb_distribution.generate_index([],[])
    teamb_distribution[index] = skill_dist
    teamb_node.set_dist(teamb_distribution)

    teamc_distribution = DiscreteDistribution(teamc_node)
    index = teamc_distribution.generate_index([],[])
    teamc_distribution[index] = skill_dist
    teamc_node.set_dist(teamc_distribution)

    match_dist = zeros([teama_node.size(), teamb_node.size(), matchAvB_node.size()], dtype=float32)
    match_dist[0,0,:] = [0.10, 0.10, 0.80]
    match_dist[0,1,:] = [0.20, 0.60, 0.20]
    match_dist[0,2,:] = [0.15, 0.75, 0.10]
    match_dist[0,3,:] = [0.05, 0.90, 0.05]

    match_dist[1,0,:] = [0.60, 0.20, 0.20]
    match_dist[1,1,:] = [0.10, 0.10, 0.80]
    match_dist[1,2,:] = [0.20, 0.60, 0.20]
    match_dist[1,3,:] = [0.15, 0.75, 0.10]

    match_dist[2,0,:] = [0.75, 0.15, 0.10]
    match_dist[2,1,:] = [0.60, 0.20, 0.20]
    match_dist[2,2,:] = [0.10, 0.10, 0.80]
    match_dist[2,3,:] = [0.20, 0.60, 0.20]

    match_dist[3,0,:] = [0.90, 0.05, 0.05]
    match_dist[3,1,:] = [0.75, 0.15, 0.10]
    match_dist[3,2,:] = [0.60, 0.20, 0.20]
    match_dist[3,3,:] = [0.10, 0.10, 0.80]

    matchAvB_distribution = ConditionalDiscreteDistribution(nodes=[teama_node, teamb_node, matchAvB_node], table=match_dist)
    matchBvC_distribution = ConditionalDiscreteDistribution(nodes=[teamb_node, teamc_node, matchBvC_node], table=match_dist)
    matchCvA_distribution = ConditionalDiscreteDistribution(nodes=[teamc_node, teama_node, matchCvA_node], table=match_dist)

    matchAvB_node.set_dist(matchAvB_distribution)
    matchBvC_node.set_dist(matchBvC_distribution)
    matchCvA_node.set_dist(matchCvA_distribution)

    nodes = [teama_node,teamb_node,teamc_node,matchAvB_node,matchBvC_node,matchCvA_node]

    return BayesNet(nodes)
Exemplo n.º 11
0
def get_game_network():
    """Create a Bayes Net representation of the game problem.
    Name the nodes as "A","B","C","AvB","BvC" and "CvA".  """
    nodes = []
    # TODO: fill this out
    A_node = BayesNode(0, 4, name='A')
    B_node = BayesNode(1, 4, name='B')
    C_node = BayesNode(2, 4, name='C')
    AvB_node = BayesNode(3, 3, name='AvB')
    BvC_node = BayesNode(4, 3, name='BvC')
    CvA_node = BayesNode(5, 3, name='CvA')
    # Match A v B
    AvB_node.add_parent(A_node)
    AvB_node.add_parent(B_node)
    A_node.add_child(AvB_node)
    B_node.add_child(AvB_node)
    # Match B v C
    BvC_node.add_parent(B_node)
    BvC_node.add_parent(C_node)
    B_node.add_child(BvC_node)
    C_node.add_child(BvC_node)
    # Match C v A
    CvA_node.add_parent(C_node)
    CvA_node.add_parent(A_node)
    C_node.add_child(CvA_node)
    A_node.add_child(CvA_node)
    
    nodes = [A_node, B_node, C_node, AvB_node, BvC_node, CvA_node]
    
    prior_skill_dist = [0.15, 0.45, 0.3, 0.1]
    
    A_skill_dist = DiscreteDistribution(A_node)
    index = A_skill_dist.generate_index([], [])
    A_skill_dist[index] = prior_skill_dist
    A_node.set_dist(A_skill_dist)
    
    B_skill_dist = DiscreteDistribution(B_node)
    index = B_skill_dist.generate_index([], [])
    B_skill_dist[index] = prior_skill_dist
    B_node.set_dist(B_skill_dist)
    
    C_skill_dist = DiscreteDistribution(C_node)
    index = C_skill_dist.generate_index([], [])
    C_skill_dist[index] = prior_skill_dist
    C_node.set_dist(C_skill_dist)
    # Match Prob Distribution
    # P(T1vT2 | T1, T2)
    # T1 | T2 | T1   | T2   | Tie
    # 0  | 0  | 0.1  | 0.1  | 0.8
    # 0  | 1  | 0.2  | 0.6  | 0.2
    # 0  | 2  | 0.15 | 0.75 | 0.1
    # 0  | 3  | 0.05 | 0.9  | 0.05
    # 1  | 0  | 0.6  | 0.2  | 0.2
    # 1  | 1  | 0.1  | 0.1  | 0.8
    # 1  | 2  | 0.2  | 0.6  | 0.2
    # 1  | 3  | 0.15 | 0.75 | 0.1
    # 2  | 0  | 0.75 | 0.15 | 0.1
    # 2  | 1  | 0.6  | 0.2  | 0.2
    # 2  | 2  | 0.1  | 0.1  | 0.8
    # 2  | 3  | 0.2  | 0.6  | 0.2
    # 3  | 0  | 0.9  | 0.05 | 0.05
    # 3  | 1  | 0.75 | 0.15 | 0.1
    # 3  | 2  | 0.6  | 0.2  | 0.2
    # 3  | 3  | 0.1  | 0.1  | 0.8
    match_dist = zeros([A_node.size(), B_node.size(), AvB_node.size()], dtype=float32)
    match_dist[0, 0,:] = [0.1, 0.1, 0.8]
    match_dist[0, 1,:] = [0.2, 0.6, 0.2]
    match_dist[0, 2,:] = [0.15, 0.75, 0.1]
    match_dist[0, 3,:] = [0.05, 0.9, 0.05]
    match_dist[1, 0,:] = [0.6, 0.2, 0.2]
    match_dist[1, 1,:] = [0.1, 0.1, 0.8]
    match_dist[1, 2,:] = [0.2, 0.6, 0.2]
    match_dist[1, 3,:] = [0.15, 0.75, 0.1]
    match_dist[2, 0,:] = [0.75, 0.15, 0.1]
    match_dist[2, 1,:] = [0.6, 0.2, 0.2]
    match_dist[2, 2,:] = [0.1, 0.1, 0.8]
    match_dist[2, 3,:] = [0.2, 0.6, 0.2]
    match_dist[3, 0,:] = [0.9, 0.05, 0.05]
    match_dist[3, 1,:] = [0.75, 0.15, 0.1]
    match_dist[3, 2,:] = [0.6, 0.2, 0.2]
    match_dist[3, 3,:] = [0.1, 0.1, 0.8]
                                             
    AvB_distribution = ConditionalDiscreteDistribution(nodes=[A_node, B_node, AvB_node],
                                                    table=match_dist)
    AvB_node.set_dist(AvB_distribution)
    
    BvC_distribution = ConditionalDiscreteDistribution(nodes=[B_node, C_node, BvC_node],
                                                      table=match_dist)
    BvC_node.set_dist(BvC_distribution)
    
    CvA_distribution = ConditionalDiscreteDistribution(nodes=[C_node, A_node, CvA_node],
                                                      table=match_dist)
    CvA_node.set_dist(CvA_distribution)
                        
    return BayesNet(nodes)
def get_test_game_network():
    """Create a Bayes Net representation of the game problem.
    Name the nodes as "A","B","C","AvB","BvC" and "CvA".  """
    nodes = []
    # TODO: fill this out

    # Create Nodes
    A_node = BayesNode(0, 4, name="A")
    B_node = BayesNode(1, 4, name="B")
    C_node = BayesNode(2, 4, name="C")
    D_node = BayesNode(3, 4, name="D")
    E_node = BayesNode(4, 4, name="E")
    AvB_node = BayesNode(5, 3, name="AvB")
    BvC_node = BayesNode(6, 3, name="BvC")
    CvD_node = BayesNode(7, 3, name="CvD")
    DvE_node = BayesNode(8, 3, name="DvE")
    EvA_node = BayesNode(9, 3, name="EvA")

    # A skill
    A_node.add_child(AvB_node)
    A_node.add_child(EvA_node)

    # B skill
    B_node.add_child(AvB_node)
    B_node.add_child(BvC_node)

    # C skill
    C_node.add_child(BvC_node)
    C_node.add_child(CvD_node)

    # D skill
    B_node.add_child(CvD_node)
    B_node.add_child(DvE_node)

    # E skill
    C_node.add_child(DvE_node)
    C_node.add_child(EvA_node)

    # AvB outcome
    AvB_node.add_parent(A_node)
    AvB_node.add_parent(B_node)

    # BvC outcome
    BvC_node.add_parent(B_node)
    BvC_node.add_parent(C_node)

    # CvD outcome
    CvD_node.add_parent(C_node)
    CvD_node.add_parent(D_node)

    # DvE outcome
    DvE_node.add_parent(D_node)
    DvE_node.add_parent(E_node)

    # EvA outcome
    EvA_node.add_parent(E_node)
    EvA_node.add_parent(A_node)

    # Set Probability Distributions
    # A, B, C team skill levels
    A_distribution = DiscreteDistribution(A_node)
    index = A_distribution.generate_index([], [])
    A_distribution[index] = [0.15, 0.45, 0.3, 0.1]
    A_node.set_dist(A_distribution)
    # B_node.set_dist(A_distribution)
    # C_node.set_dist(A_distribution)

    B_distribution = DiscreteDistribution(B_node)
    index = B_distribution.generate_index([], [])
    B_distribution[index] = [0.15, 0.45, 0.3, 0.1]
    B_node.set_dist(B_distribution)

    C_distribution = DiscreteDistribution(C_node)
    index = C_distribution.generate_index([], [])
    C_distribution[index] = [0.15, 0.45, 0.3, 0.1]
    C_node.set_dist(C_distribution)

    D_distribution = DiscreteDistribution(D_node)
    index = D_distribution.generate_index([], [])
    D_distribution[index] = [0.15, 0.45, 0.3, 0.1]
    D_node.set_dist(D_distribution)

    E_distribution = DiscreteDistribution(E_node)
    index = E_distribution.generate_index([], [])
    E_distribution[index] = [0.15, 0.45, 0.3, 0.1]
    E_node.set_dist(E_distribution)

    # AvB, BvC, CvA game outcomes
    dist = zeros([A_node.size(), B_node.size(), AvB_node.size()], dtype=float32)
    dist[0, 0, :] = [0.1, 0.1, 0.8]
    dist[0, 1, :] = [0.2, 0.6, 0.2]
    dist[0, 2, :] = [0.15, 0.75, 0.1]
    dist[0, 3, :] = [0.05, 0.9, 0.05]
    dist[1, 0, :] = [0.6, 0.2, 0.2]
    dist[1, 1, :] = [0.1, 0.1, 0.8]
    dist[1, 2, :] = [0.2, 0.6, 0.2]
    dist[1, 3, :] = [0.15, 0.75, 0.1]
    dist[2, 0, :] = [0.75, 0.15, 0.1]
    dist[2, 1, :] = [0.6, 0.2, 0.2]
    dist[2, 2, :] = [0.1, 0.1, 0.8]
    dist[2, 3, :] = [0.2, 0.6, 0.2]
    dist[3, 0, :] = [0.9, 0.05, 0.05]
    dist[3, 1, :] = [0.75, 0.15, 0.1]
    dist[3, 2, :] = [0.6, 0.2, 0.2]
    dist[3, 3, :] = [0.1, 0.1, 0.8]

    AvB_distribution = ConditionalDiscreteDistribution(nodes=[A_node, B_node, AvB_node], table=dist)
    AvB_node.set_dist(AvB_distribution)
    BvC_distribution = ConditionalDiscreteDistribution(nodes=[B_node, C_node, BvC_node], table=dist)
    BvC_node.set_dist(BvC_distribution)
    CvD_distribution = ConditionalDiscreteDistribution(nodes=[C_node, D_node, CvD_node], table=dist)
    CvD_node.set_dist(CvD_distribution)
    DvE_distribution = ConditionalDiscreteDistribution(nodes=[D_node, E_node, DvE_node], table=dist)
    DvE_node.set_dist(DvE_distribution)
    EvA_distribution = ConditionalDiscreteDistribution(nodes=[E_node, A_node, EvA_node], table=dist)
    EvA_node.set_dist(EvA_distribution)

    nodes = [A_node, B_node, C_node, D_node, E_node, AvB_node, BvC_node, CvD_node, DvE_node, EvA_node]

    return BayesNet(nodes)
def get_game_network():
    """Create a Bayes Net representation of the game problem.
    Name the nodes as "A","B","C","AvB","BvC" and "CvA".  """
    nodes = []
    # TODO: fill this out

    # Create Nodes
    A = BayesNode(0, 4, name="A")
    B_node = BayesNode(1, 4, name="B")
    C_node = BayesNode(2, 4, name="C")
    AvB = BayesNode(3, 3, name="AvB")
    BvC_node = BayesNode(4, 3, name="BvC")
    CvA = BayesNode(5, 3, name="CvA")

    # A skill
    A.add_child(AvB)
    A.add_child(CvA)

    # B skill
    B_node.add_child(AvB)
    B_node.add_child(BvC_node)

    # C skill
    C_node.add_child(BvC_node)
    C_node.add_child(CvA)

    # AvB outcome
    AvB.add_parent(A)
    AvB.add_parent(B_node)

    # BvC outcome
    BvC_node.add_parent(B_node)
    BvC_node.add_parent(C_node)

    # CvA outcome
    CvA.add_parent(C_node)
    CvA.add_parent(A)


    # Set Probability Distributions
    # A, B, C team skill levels
    A_distribution = DiscreteDistribution(A)
    index = A_distribution.generate_index([],[])
    A_distribution[index]=[0.15, 0.45, 0.3, 0.1]
    A.set_dist(A_distribution)

    B_distribution = DiscreteDistribution(B_node)
    index = B_distribution.generate_index([],[])
    B_distribution[index]=[0.15, 0.45, 0.3, 0.1]
    B_node.set_dist(B_distribution)

    C_distribution = DiscreteDistribution(C_node)
    index = C_distribution.generate_index([],[])
    C_distribution[index]=[0.15, 0.45, 0.3, 0.1]
    C_node.set_dist(C_distribution)

    # AvB, BvC, CvA game outcomes
    dist = zeros([A.size(), B_node.size(), AvB.size()], dtype=float32)
    dist[0,0,:] = [0.1, 0.1, 0.8]
    dist[0,1,:] = [0.2, 0.6, 0.2]
    dist[0,2,:] = [0.15, 0.75, 0.1]
    dist[0,3,:] = [0.05, 0.9, 0.05]
    dist[1,0,:] = [0.6, 0.2, 0.2]
    dist[1,1,:] = [0.1, 0.1, 0.8]
    dist[1,2,:] = [0.2, 0.6, 0.2]
    dist[1,3,:] = [0.15, 0.75, 0.1]
    dist[2,0,:] = [0.75, 0.15, 0.1]
    dist[2,1,:] = [0.6, 0.2, 0.2]
    dist[2,2,:] = [0.1, 0.1, 0.8]
    dist[2,3,:] = [0.2, 0.6, 0.2]
    dist[3,0,:] = [0.9, 0.05, 0.05]
    dist[3,1,:] = [0.75, 0.15, 0.1]
    dist[3,2,:] = [0.6, 0.2, 0.2]
    dist[3,3,:] = [0.1, 0.1, 0.8]

    AvB_distribution = ConditionalDiscreteDistribution(nodes=[A, B_node, AvB], table=dist)
    AvB.set_dist(AvB_distribution)
    BvC_distribution = ConditionalDiscreteDistribution(nodes=[B_node, C_node, BvC_node], table=dist)
    BvC_node.set_dist(BvC_distribution)
    CvA_distribution = ConditionalDiscreteDistribution(nodes=[C_node, A, CvA], table=dist)
    CvA.set_dist(CvA_distribution)

    nodes = [A, B_node, C_node, AvB, BvC_node, CvA]

    return BayesNet(nodes)
Exemplo n.º 14
0
def get_game_network():
    """Create a Bayes Net representation of the game problem.
    Name the nodes as "A","B","C","AvB","BvC" and "CvA".  """
    nodes = []
    A_node = BayesNode(0, 4, name='A')
    B_node = BayesNode(1, 4, name='B')
    C_node = BayesNode(2, 4, name='C')
    AvB_node = BayesNode(3, 3, name='AvB')
    BvC_node = BayesNode(4, 3, name='BvC')
    CvA_node = BayesNode(5, 3, name='CvA')

    # Skill level of A and B affects AvB
    AvB_node.add_parent(A_node)
    AvB_node.add_parent(B_node)
    A_node.add_child(AvB_node)
    B_node.add_child(AvB_node)

    # Skill level of B and C affects BvC
    BvC_node.add_parent(B_node)
    BvC_node.add_parent(C_node)
    B_node.add_child(BvC_node)
    C_node.add_child(BvC_node)

    # Skill level of C and A affects BvC
    CvA_node.add_parent(A_node)
    CvA_node.add_parent(C_node)
    A_node.add_child(CvA_node)
    C_node.add_child(CvA_node)

    A_dist = DiscreteDistribution(A_node)
    index = A_dist.generate_index([], [])
    A_dist[index] = [0.15, 0.45, 0.30, 0.10]
    A_node.set_dist(A_dist)

    B_dist = DiscreteDistribution(B_node)
    index = B_dist.generate_index([], [])
    B_dist[index] = [0.15, 0.45, 0.30, 0.10]
    B_node.set_dist(B_dist)

    C_dist = DiscreteDistribution(C_node)
    index = C_dist.generate_index([], [])
    C_dist[index] = [0.15, 0.45, 0.30, 0.10]
    C_node.set_dist(C_dist)

    dist = zeros([A_node.size(), B_node.size(),
                  AvB_node.size()],
                 dtype=float32)
    dist[0, 0, :] = [0.1, 0.1, 0.8]
    dist[0, 1, :] = [0.2, 0.6, 0.2]
    dist[0, 2, :] = [0.15, 0.75, 0.1]
    dist[0, 3, :] = [0.05, 0.9, 0.05]

    dist[1, 0, :] = [0.6, 0.2, 0.2]
    dist[1, 1, :] = [0.1, 0.1, 0.8]
    dist[1, 2, :] = [0.2, 0.6, 0.2]
    dist[1, 3, :] = [0.15, 0.75, 0.1]

    dist[2, 0, :] = [0.75, 0.15, 0.1]
    dist[2, 1, :] = [0.6, 0.2, 0.2]
    dist[2, 2, :] = [0.1, 0.1, 0.8]
    dist[2, 3, :] = [0.2, 0.6, 0.2]

    dist[3, 0, :] = [0.9, 0.05, 0.05]
    dist[3, 1, :] = [0.75, 0.15, 0.1]
    dist[3, 2, :] = [0.6, 0.2, 0.2]
    dist[3, 3, :] = [0.1, 0.1, 0.8]
    AvB_dist = ConditionalDiscreteDistribution(
        nodes=[A_node, B_node, AvB_node], table=dist)
    AvB_node.set_dist(AvB_dist)
    # The same distribution AvB applies for BvC and CvA
    BvC_dist = ConditionalDiscreteDistribution(
        nodes=[B_node, C_node, BvC_node], table=dist)
    BvC_node.set_dist(BvC_dist)
    CvA_dist = ConditionalDiscreteDistribution(
        nodes=[C_node, A_node, CvA_node], table=dist)
    CvA_node.set_dist(CvA_dist)

    nodes = [A_node, B_node, C_node, AvB_node, BvC_node, CvA_node]

    return BayesNet(nodes)
def make_exam_net():
    H = BayesNode(0, 2, name='H')
    G = BayesNode(1, 2, name='G')
    B = BayesNode(2, 2, name='B')
    O = BayesNode(3, 2, name='O')
    D = BayesNode(4, 2, name='D')
    C = BayesNode(5, 2, name='C')

    H.add_child(B)
    B.add_parent(H)
    B.add_parent(G)
    G.add_child(B)
    G.add_child(O)
    O.add_parent(G)
    O.add_child(D)
    O.add_child(C)
    D.add_parent(O)
    C.add_parent(O)
    B.add_child(D)
    D.add_parent(B)

    nodes = [B, C, D, G, H, O]
    net = BayesNet(nodes)

    sci = BayesNode(0, 2, name='sci')
    inf = BayesNode(1, 2, name='inf')
    weap = BayesNode(2, 2, name='weap')
    car = BayesNode(3, 2, name='car')
    wear = BayesNode(4, 2, name='wear')

    sci.add_child(weap)
    weap.add_parent(sci)
    inf.add_child(weap)
    weap.add_parent(inf)
    weap.add_child(car)
    car.add_parent(weap)
    weap.add_child(wear)
    wear.add_parent(weap)

    nodes1 = [sci, weap, wear, inf, car]
    net1 = BayesNet(nodes1)

    B = net.get_node_by_name('B')
    C = net.get_node_by_name('C')
    D = net.get_node_by_name('D')
    G = net.get_node_by_name('G')
    H = net.get_node_by_name('H')
    O = net.get_node_by_name('O')

    H_distribution = DiscreteDistribution(H)
    index = H_distribution.generate_index([], [])
    H_distribution[index] = [0.6, 0.4]
    H.set_dist(H_distribution)

    G_distribution = DiscreteDistribution(G)
    index = G_distribution.generate_index([], [])
    G_distribution[index] = [0.75, 0.25]
    G.set_dist(G_distribution)

    dist = zeros([O.size(), C.size()], dtype=float32)
    dist[0, :] = [0.55, 0.45]
    dist[1, :] = [0.75, 0.25]
    C_distribution = ConditionalDiscreteDistribution(nodes=[O, C], table=dist)
    C.set_dist(C_distribution)

    dist = zeros([G.size(), O.size()], dtype=float32)
    dist[0, :] = [0.55, 0.45]
    dist[1, :] = [0.45, 0.55]
    O_distribution = ConditionalDiscreteDistribution(nodes=[G, O], table=dist)
    O.set_dist(O_distribution)

    dist = zeros([B.size(), O.size(), D.size()], dtype=float32)
    dist[0, 0, :] = [0.72, 0.28]
    dist[0, 1, :] = [0.38, 0.62]
    dist[1, 0, :] = [0.85, 0.15]
    dist[1, 1, :] = [0.65, 0.35]
    D_distribution = ConditionalDiscreteDistribution(nodes=[B, O, D],
                                                     table=dist)
    D.set_dist(D_distribution)

    dist = zeros([H.size(), G.size(), B.size()], dtype=float32)
    dist[0, 0, :] = [0.92, 0.08]
    dist[0, 1, :] = [0.75, 0.25]
    dist[1, 0, :] = [0.55, 0.45]
    dist[1, 1, :] = [0.35, 0.65]
    B_distribution = ConditionalDiscreteDistribution(nodes=[H, G, B],
                                                     table=dist)
    B.set_dist(B_distribution)

    sci = net1.get_node_by_name('sci')
    weap = net1.get_node_by_name('weap')
    wear = net1.get_node_by_name('wear')
    inf = net1.get_node_by_name('inf')
    car = net1.get_node_by_name('car')

    sci_distribution = DiscreteDistribution(sci)
    index = sci_distribution.generate_index([], [])
    sci_distribution[index] = [0.2, 0.8]
    sci.set_dist(sci_distribution)

    inf_distribution = DiscreteDistribution(inf)
    index = inf_distribution.generate_index([], [])
    inf_distribution[index] = [0.4, 0.6]
    inf.set_dist(inf_distribution)

    dist = zeros([sci.size(), inf.size(), weap.size()], dtype=float32)
    dist[0, 0, :] = [0.6, 0.4]
    dist[0, 1, :] = [0.8, 0.2]
    dist[1, 0, :] = [0.1, 0.9]
    dist[1, 1, :] = [0.3, 0.7]
    weap_distribution = ConditionalDiscreteDistribution(nodes=[sci, inf, weap],
                                                        table=dist)
    weap.set_dist(weap_distribution)

    dist = zeros([weap.size(), wear.size()], dtype=float32)
    dist[0, :] = [0.88, 0.12]
    dist[1, :] = [0.15, 0.85]
    wear_distribution = ConditionalDiscreteDistribution(nodes=[weap, wear],
                                                        table=dist)
    wear.set_dist(wear_distribution)

    dist = zeros([weap.size(), car.size()], dtype=float32)
    dist[0, :] = [0.75, 0.25]
    dist[1, :] = [0.55, 0.45]
    car_distribution = ConditionalDiscreteDistribution(nodes=[weap, car],
                                                       table=dist)
    car.set_dist(car_distribution)

    ##    engine = JunctionTreeEngine(net)
    #    engine = EnumerationEngine(net)
    ##    engine.evidence[B] = True
    #    Q = engine.marginal(C)[0]
    #    index = Q.generate_index([True], range(Q.nDims))
    #    prob = Q[index]
    #    print "Thr ptob of O = T given B = T is  ", prob

    engine1 = EnumerationEngine(net1)
    engine1.evidence[wear] = False
    engine1.evidence[weap] = True
    #   engine1.evidence[sci] = False
    Q = engine1.marginal(car)[0]
    index = Q.generate_index([True], range(Q.nDims))
    prob = Q[index]
    print prob
Exemplo n.º 16
0
def water():
    """ This is an example of how to implement the basic water network (4 nodes, cloudy, sprinkler, rain, and wetgrass.
    sprinkler and rain are children of cloudy, and wetgrass is a child of both sprinkler and rain).
    """

    #testing basic bayes net class implementation
    numberOfNodes = 4
    #name the nodes
    cloudy = 0
    sprinkler = 1
    rain = 2
    wetgrass = 3

    #create nodes ---> refer Node.py
    cNode = BayesNode(0, 2, name="cloudy")
    sNode = BayesNode(1, 2, name="sprinkler")
    rNode = BayesNode(2, 2, name="rain")
    wNode = BayesNode(3, 2, name="wetgrass")

    #cloudy
    cNode.add_child(sNode)
    cNode.add_child(rNode)

    #sprinkler
    sNode.add_parent(cNode)
    sNode.add_child(wNode)

    #rain
    rNode.add_parent(cNode)
    rNode.add_child(wNode)

    #wetgrass
    wNode.add_parent(sNode)
    wNode.add_parent(rNode)

    nodes = [cNode, sNode, rNode, wNode]

    #create distributions ---> refer Distribution.py

    #cloudy distribution
    cDistribution = DiscreteDistribution(cNode)
    index = cDistribution.generate_index([], [])
    cDistribution[index] = 0.5
    cNode.set_dist(cDistribution)

    #sprinkler
    dist = zeros([cNode.size(), sNode.size()], dtype=float32)
    dist[0, ] = 0.5
    dist[1, ] = [0.9, 0.1]
    sDistribution = ConditionalDiscreteDistribution(nodes=[cNode, sNode],
                                                    table=dist)
    sNode.set_dist(sDistribution)

    #rain
    dist = zeros([cNode.size(), rNode.size()], dtype=float32)
    dist[0, ] = [0.8, 0.2]
    dist[1, ] = [0.2, 0.8]
    rDistribution = ConditionalDiscreteDistribution(nodes=[cNode, rNode],
                                                    table=dist)
    rNode.set_dist(rDistribution)

    #wetgrass
    dist = zeros([sNode.size(), rNode.size(), wNode.size()], dtype=float32)
    dist[0, 0, ] = [1.0, 0.0]
    dist[1, 0, ] = [0.1, 0.9]
    dist[0, 1, ] = [0.1, 0.9]
    dist[1, 1, ] = [0.01, 0.99]
    wgDistribution = ConditionalDiscreteDistribution(
        nodes=[sNode, rNode, wNode], table=dist)
    wNode.set_dist(wgDistribution)

    #create bayes net
    bnet = BayesNet(nodes)
    return bnet
def get_game_network():
    """Create a Bayes Net representation of the game problem.
    Name the nodes as "A","B","C","AvB","BvC" and "CvA".  """
    nodes = []
    # TODO: fill this out
    #raise NotImplementedError
    #Skill level Nodes: each has 0-3 four levels
    A_node=BayesNode(0, 4, name='A')
    B_node = BayesNode(1, 4, name='B')
    C_node = BayesNode(2, 4, name='C')

    # match nodes: each has win, lose or tie
    AvB_node=BayesNode(3, 3, name='AvB')
    BvC_node = BayesNode(4, 3, name='BvC')
    CvA_node=BayesNode(5, 3, name='CvA')

    nodes = [A_node, B_node, C_node, AvB_node, BvC_node, CvA_node]

    #create network
    A_node.add_child(AvB_node)
    AvB_node.add_parent(A_node)
    A_node.add_child(CvA_node)
    CvA_node.add_parent(A_node)

    B_node.add_child(AvB_node)
    AvB_node.add_parent(B_node)
    B_node.add_child(BvC_node)
    BvC_node.add_parent(B_node)

    C_node.add_child(CvA_node)
    CvA_node.add_parent(C_node)
    C_node.add_child(BvC_node)
    BvC_node.add_parent(C_node)

    #set Probability
    # each team has 4 level of skills with probability 0.15, 0.45, 0.3 0.1
    A_distribution = DiscreteDistribution(A_node)
    index = A_distribution.generate_index([], [])
    A_distribution[index] = [0.15, 0.45, 0.30, 0.10]
    A_node.set_dist(A_distribution)

    B_distribution = DiscreteDistribution(B_node)
    index = B_distribution.generate_index([], [])
    B_distribution[index] = [0.15, 0.45, 0.30, 0.10]
    B_node.set_dist(B_distribution)

    C_distribution = DiscreteDistribution(C_node)
    index = C_distribution.generate_index([], [])
    C_distribution[index] = [0.15, 0.45, 0.30, 0.10]
    C_node.set_dist(C_distribution)

    #Probability of matches
    #AvB: given skill level A, B, P(AvB|A,B)
    dist = zeros([A_node.size(), B_node.size(), AvB_node.size()], dtype=float32)
    dist[0, 0, :] = [0.1, 0.1, 0.8]
    dist[0, 1, :] = [0.2, 0.6, 0.2]
    dist[0, 2, :] = [0.15, 0.75, 0.1]
    dist[0, 3, :] = [0.05, 0.9, 0.05]
    dist[1, 0, :] = [0.6, 0.2, 0.2]
    dist[1, 1, :] = [0.1, 0.1, 0.8]
    dist[1, 2, :] = [0.2, 0.6, 0.2]
    dist[1, 3, :] = [0.15, 0.75, 0.1]
    dist[2, 0, :] = [0.75, 0.15, 0.1]
    dist[2, 1, :] = [0.6, 0.2, 0.2]
    dist[2, 2, :] = [0.1, 0.1, 0.8]
    dist[2, 3, :] = [0.2, 0.6, 0.2]
    dist[3, 0, :] = [0.9, 0.05, 0.05]
    dist[3, 1, :] = [0.75, 0.15, 0.1]
    dist[3, 2, :] = [0.6, 0.2, 0.2]
    dist[3, 3, :] = [0.1, 0.1, 0.8]
    AvB_distribution = ConditionalDiscreteDistribution(nodes=[A_node, B_node, AvB_node], table=dist)
    AvB_node.set_dist(AvB_distribution)

    # BvC: given skill level B, C, P(BvC|B,C)
    dist = zeros([B_node.size(), C_node.size(), BvC_node.size()], dtype=float32)
    dist[0, 0, :] = [0.1, 0.1, 0.8]
    dist[0, 1, :] = [0.2, 0.6, 0.2]
    dist[0, 2, :] = [0.15, 0.75, 0.1]
    dist[0, 3, :] = [0.05, 0.9, 0.05]
    dist[1, 0, :] = [0.6, 0.2, 0.2]
    dist[1, 1, :] = [0.1, 0.1, 0.8]
    dist[1, 2, :] = [0.2, 0.6, 0.2]
    dist[1, 3, :] = [0.15, 0.75, 0.1]
    dist[2, 0, :] = [0.75, 0.15, 0.1]
    dist[2, 1, :] = [0.6, 0.2, 0.2]
    dist[2, 2, :] = [0.1, 0.1, 0.8]
    dist[2, 3, :] = [0.2, 0.6, 0.2]
    dist[3, 0, :] = [0.9, 0.05, 0.05]
    dist[3, 1, :] = [0.75, 0.15, 0.1]
    dist[3, 2, :] = [0.6, 0.2, 0.2]
    dist[3, 3, :] = [0.1, 0.1, 0.8]
    BvC_distribution = ConditionalDiscreteDistribution(nodes=[B_node, C_node, BvC_node], table=dist)
    BvC_node.set_dist(BvC_distribution)

    # CvA: given skill level C, A, P(CvA|C,A)
    dist = zeros([C_node.size(), A_node.size(), CvA_node.size()], dtype=float32)
    dist[0, 0, :] = [0.1, 0.1, 0.8]
    dist[0, 1, :] = [0.2, 0.6, 0.2]
    dist[0, 2, :] = [0.15, 0.75, 0.1]
    dist[0, 3, :] = [0.05, 0.9, 0.05]
    dist[1, 0, :] = [0.6, 0.2, 0.2]
    dist[1, 1, :] = [0.1, 0.1, 0.8]
    dist[1, 2, :] = [0.2, 0.6, 0.2]
    dist[1, 3, :] = [0.15, 0.75, 0.1]
    dist[2, 0, :] = [0.75, 0.15, 0.1]
    dist[2, 1, :] = [0.6, 0.2, 0.2]
    dist[2, 2, :] = [0.1, 0.1, 0.8]
    dist[2, 3, :] = [0.2, 0.6, 0.2]
    dist[3, 0, :] = [0.9, 0.05, 0.05]
    dist[3, 1, :] = [0.75, 0.15, 0.1]
    dist[3, 2, :] = [0.6, 0.2, 0.2]
    dist[3, 3, :] = [0.1, 0.1, 0.8]
    CvA_distribution = ConditionalDiscreteDistribution(nodes=[C_node, A_node, CvA_node], table=dist)
    CvA_node.set_dist(CvA_distribution)

    return BayesNet(nodes)