def test_evidenced_outside_on_path_graph(get_complex_graph_and_configurations):
    test_data      = get_complex_graph_and_configurations
    hypothgraph    = test_data['hypothgraph']
    partial_within = test_data['partial_within']
    source         = partial_within.source
    target         = partial_within.target

    before_confidence       =  compute_confidence.confidence(hypothgraph, partial_within)
    before_max_confidence   =  compute_confidence.max_confidence(hypothgraph, source, target)
    before_norm_confidence  =  compute_confidence.normalized_confidence(hypothgraph, partial_within)

    # Evidence nodes which will not contribute to the causation confidence
    on_boundary_nodes = boundary.on_boundary(hypothgraph, source, target)
    outside_evidence_nodes = partial_within.evidenced_nodes + list(on_boundary_nodes)

    # create new hypothesis configuration
    new_conf = Hypoth_Conf(source=source,
                           target=target,
                           evidenced_nodes=outside_evidence_nodes)

    after_confidence       =  compute_confidence.confidence(hypothgraph, new_conf)
    after_max_confidence   =  compute_confidence.max_confidence(hypothgraph, source, target)
    after_norm_confidence  =  compute_confidence.normalized_confidence(hypothgraph, new_conf)

    assert before_confidence == after_confidence
    assert before_max_confidence == after_max_confidence
    assert before_norm_confidence == after_norm_confidence
Пример #2
0
def take_ratio_boundary_paths_rand(hypothgraph, source, target, ratio=0.5):
    on_boundary_nodes = boundary.on_boundary(hypothgraph, source, target)

    boundary_paths = chain_many_to_many_path_generator(hypothgraph,
                                                       on_boundary_nodes)

    return take_ratio_paths_rand(hypothgraph, boundary_paths, ratio=ratio)
Пример #3
0
def test_nodes_on_boundary(get_digraph_with_cycle):
    hypothgraph, source, target = get_digraph_with_cycle

    nodes_on_boundary = boundary.on_boundary(hypothgraph, source, target)
    nodes_in_boundary_interior = list(boundary.in_boundary_interior(hypothgraph, source, target))

    for node_on_boundary in nodes_on_boundary:
        assert not node_on_boundary in nodes_in_boundary_interior
def test_uniqueness_of_simple_on_boundary_paths(get_sample_hypothgraph):
    hypothgraph = get_sample_hypothgraph
    source, target = hypoth_conf.generate_rich_endpoints(hypothgraph)

    on_boundary_nodes = boundary.on_boundary(hypothgraph, source, target)
    on_boundary_paths = list(
            paths.chain_many_to_many_path_generator(hypothgraph, on_boundary_nodes))


    nb_paths = len(on_boundary_paths)
    # no path is repeated in all the paths, you cannot just use
    # `set(all_paths)`, since a path is a list, an unhashable type
    for path in on_boundary_paths:
        other_paths = [other_path for other_path in on_boundary_paths
                                  if not other_path == path]

        assert len(other_paths) == nb_paths-1
def test_ratio_on_boundary_paths_sample_hypothgraph(get_sample_hypothgraph):
    hypothgraph = get_sample_hypothgraph

    source, target = hypoth_conf.generate_rich_endpoints(hypothgraph)
    ratio_paths = 0.7

    on_boundary_nodes = boundary.on_boundary(hypothgraph, source, target)
    boundary_paths = list(
            paths.chain_many_to_many_path_generator(hypothgraph, on_boundary_nodes))

    boundary_ratio_paths = list(
            paths.take_ratio_boundary_paths_rand(hypothgraph, source, target, ratio=ratio_paths))

    # nb of generated paths is at least the given ratio to the total amount of
    # paths
    nb_ratio_paths = len(boundary_ratio_paths)
    nb_total_paths = len(boundary_paths)

    assert nb_ratio_paths == math.ceil(ratio_paths * nb_total_paths)