Пример #1
0
def mixed_cpd_model(edges_five_nodes):
    """
    X-shaped 5 node model plus one more node, 'w', with edge from 'w' to 'z'.
    'z' is an AND node while all other nodes are OR nodes.
    """
    u_node = BernoulliOrNode(label_id='u', children=['x'], parents=[])
    v_node = BernoulliOrNode(label_id='v', children=['x'], parents=[])
    x_node = BernoulliOrNode(label_id='x',
                             children=['y', 'z'],
                             parents=['u', 'v'])
    y_node = BernoulliOrNode(label_id='y', children=[], parents=['x'])
    z_node = BernoulliAndNode(label_id='z', children=[], parents=['x', 'w'])
    w_node = BernoulliOrNode(label_id='w', children=['z'], parents=[])
    return BeliefUpdateNodeModel(
        nodes_dict={
            'u': u_node,
            'v': v_node,
            'x': x_node,
            'y': y_node,
            'z': z_node,
            'w': w_node
        })
Пример #2
0
def custom_cpd_model():
    """
    Y-shaped model, with parents ,'u' and 'v' as Or-nodes, 'x' a node with
    cardinality 3 and custom CPD, 'y' a node with cardinality 2 and custom CPD.
    """
    custom_cpd_x = TabularCPD(variable='x',
                              variable_card=3,
                              parents=['u', 'v'],
                              parents_card=[2, 2],
                              values=[[0.2, 0, 0.3, 0.1], [0.4, 1, 0.7, 0.2],
                                      [0.4, 0, 0, 0.7]],
                              state_names={
                                  'x': ['lo', 'med', 'hi'],
                                  'u': ['False', 'True'],
                                  'v': ['False', 'True']
                              })
    custom_cpd_y = TabularCPD(variable='y',
                              variable_card=2,
                              parents=['x'],
                              parents_card=[3],
                              values=[[0.3, 0.1, 0], [0.7, 0.9, 1]],
                              state_names={
                                  'x': ['lo', 'med', 'hi'],
                                  'y': ['False', 'True']
                              })

    u_node = BernoulliOrNode(label_id='u', children=['x'], parents=[])
    v_node = BernoulliOrNode(label_id='v', children=['x'], parents=[])
    x_node = Node(children=['y'], cpd=custom_cpd_x)
    y_node = Node(children=[], cpd=custom_cpd_y)
    return BeliefUpdateNodeModel(nodes_dict={
        'u': u_node,
        'v': v_node,
        'x': x_node,
        'y': y_node
    })
Пример #3
0
def five_node_and_model(edges_five_nodes):
    return BeliefUpdateNodeModel.init_from_edges(edges_five_nodes,
                                                 BernoulliAndNode)
Пример #4
0
def one_node_model():
    a_node = BernoulliOrNode(label_id='x', children=[], parents=[])
    return BeliefUpdateNodeModel(nodes_dict={'x': a_node})
Пример #5
0
def many_parents_and_model(many_parents_edges):
    return BeliefUpdateNodeModel.init_from_edges(many_parents_edges,
                                                 BernoulliAndNode)
Пример #6
0
def simple_model(simple_edges):
    return BeliefUpdateNodeModel.init_from_edges(simple_edges, BernoulliOrNode)