def generate_CET_forest(ori_graph, graph, explanatory_var, observation, explanadum, path):
    if len(explanatory_var) is 0:
        return [ExplanationTreeNode()]

    forest = []
    for x in explanatory_var:

        for value in graph.get_node_with_name(x).cpt.values():
            intervened_graph = graph.create_graph_with_intervention( {x:value} )
            new_forest = generate_CET_forest(ori_graph, intervened_graph, cut(explanatory_var, x), observation, explanadum, path + [(x, value)])
            for new_tree in new_forest:
                t = ExplanationTreeNode(parent = path[-1][0] if path else None, root = x)
                strength = math.log( intervened_graph.prob_given(explanadum, observation) / \
                            ori_graph.prob_given(explanadum, observation), 2) if intervened_graph.prob_given(explanadum, observation) and ori_graph.prob_given(explanadum, observation) else float("NaN")
                t.add_branch(value, new_tree, strength)
                forest.append(t)

    return forest
def generate_causal_explanation_tree(ori_graph, graph, explanatory_var, observation, explanadum, path, alpha):
    x, inf = max_causal_information(graph, explanatory_var, observation, explanadum)
    
    if inf < alpha:
       return ExplanationTreeNode()

    if len(explanatory_var) is 0:
        return ExplanationTreeNode()

    t = ExplanationTreeNode(parent = path[-1][0] if path else None, root = x) #new tree with a parent pointer to its parent
    
    for value in graph.get_node_with_name(x).cpt.values():
        intervened_graph = graph.create_graph_with_intervention( {x:value} )
        new_tree = generate_causal_explanation_tree(ori_graph, intervened_graph, cut(explanatory_var, x), \
                            observation, explanadum, path + [(x, value)], alpha)
        strength = math.log( intervened_graph.prob_given(explanadum, observation) / \
                            ori_graph.prob_given(explanadum, observation), 2) if intervened_graph.prob_given(explanadum, observation) and ori_graph.prob_given(explanadum, observation) else float("NaN")
        t.add_branch(value, new_tree, strength)

    return t
예제 #3
0
def generate_CET_forest(ori_graph, graph, explanatory_var, observation,
                        explanadum, path):
    if len(explanatory_var) is 0:
        return [ExplanationTreeNode()]

    forest = []
    for x in explanatory_var:

        for value in graph.get_node_with_name(x).cpt.values():
            intervened_graph = graph.create_graph_with_intervention({x: value})
            new_forest = generate_CET_forest(ori_graph, intervened_graph,
                                             cut(explanatory_var,
                                                 x), observation, explanadum,
                                             path + [(x, value)])
            for new_tree in new_forest:
                t = ExplanationTreeNode(parent=path[-1][0] if path else None,
                                        root=x)
                strength = math.log( intervened_graph.prob_given(explanadum, observation) / \
                            ori_graph.prob_given(explanadum, observation), 2) if intervened_graph.prob_given(explanadum, observation) and ori_graph.prob_given(explanadum, observation) else float("NaN")
                t.add_branch(value, new_tree, strength)
                forest.append(t)

    return forest
예제 #4
0
def generate_causal_explanation_tree(ori_graph, graph, explanatory_var,
                                     observation, explanadum, path, alpha):
    x, inf = max_causal_information(graph, explanatory_var, observation,
                                    explanadum)

    if inf < alpha:
        return ExplanationTreeNode()

    if len(explanatory_var) is 0:
        return ExplanationTreeNode()

    t = ExplanationTreeNode(
        parent=path[-1][0] if path else None,
        root=x)  #new tree with a parent pointer to its parent

    for value in graph.get_node_with_name(x).cpt.values():
        intervened_graph = graph.create_graph_with_intervention({x: value})
        new_tree = generate_causal_explanation_tree(ori_graph, intervened_graph, cut(explanatory_var, x), \
                            observation, explanadum, path + [(x, value)], alpha)
        strength = math.log( intervened_graph.prob_given(explanadum, observation) / \
                            ori_graph.prob_given(explanadum, observation), 2) if intervened_graph.prob_given(explanadum, observation) and ori_graph.prob_given(explanadum, observation) else float("NaN")
        t.add_branch(value, new_tree, strength)

    return t