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
Ejemplo n.º 2
0
def relative_confidence_spectrum(big, small, source, target):
    evidenced_nodes = []
    iterative_hypoth_conf = Hypoth_Conf(source, target, evidenced_nodes)
    dict_confidences = {}

    # shortcut names for confidence functions
    func_conf = compute_confidence.confidence
    func_conf_norm = compute_confidence.normalized_confidence

    # compute max confidences in the small and in the big graphs
    max_small_confidence = compute_confidence.max_confidence(
        small, source, target)
    max_big_confidence = compute_confidence.max_confidence(big, source, target)

    # all nodes in the boundary interior of the SUBGRAPH
    nodes_boundary_interior = boundary.in_boundary_interior(
        small, source, target)

    # initial confidence values
    dict_confidences['sub_confidence_spectrum'] = [
        func_conf(small, iterative_hypoth_conf)
    ]
    dict_confidences['big_confidence_spectrum'] = [
        func_conf(big, iterative_hypoth_conf)
    ]
    dict_confidences['sub_confidence_normalized_spectrum'] = [
        func_conf_norm(small, iterative_hypoth_conf)
    ]
    dict_confidences['big_confidence_normalized_spectrum'] = [
        func_conf_norm(big, iterative_hypoth_conf)
    ]

    # add confidence values
    for boundary_interior_node in nodes_boundary_interior:
        evidenced_nodes.append(boundary_interior_node)
        iterative_hypoth_conf = Hypoth_Conf(source, target, evidenced_nodes)

        dict_confidences['sub_confidence_spectrum'].append(
            func_conf(small, iterative_hypoth_conf))
        dict_confidences['big_confidence_spectrum'].append(
            func_conf(big, iterative_hypoth_conf))
        dict_confidences['sub_confidence_normalized_spectrum'].append(
            func_conf_norm(small, iterative_hypoth_conf))
        dict_confidences['big_confidence_normalized_spectrum'].append(
            func_conf_norm(big, iterative_hypoth_conf))

    return dict_confidences
def test_nothing_evidenced_on_path_graph(get_complex_graph_and_configurations):
    test_data   = get_complex_graph_and_configurations
    hypothgraph = test_data['hypothgraph']
    nothing     = test_data['nothing']

    # confidence with nothing evidenced should be 0
    confidence = compute_confidence.confidence(hypothgraph, nothing)
    assert confidence == 0

    # max confidence for the same boundary should be bigger than confidence
    max_confidence = compute_confidence.max_confidence(hypothgraph, nothing.source, nothing.target)
    assert max_confidence > confidence

    # normalized confidence should also be zero since we have nothing evidenced
    normalized_confidence = compute_confidence.normalized_confidence(hypothgraph, nothing)
    assert normalized_confidence == 0
def test_partial_evidenced_within_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']

    # confidence with nothing evidenced should be 0
    confidence = compute_confidence.confidence(hypothgraph, partial_within)
    assert confidence > 0

    # max confidence for the same boundary should be bigger than confidence
    max_confidence = compute_confidence.max_confidence(
            hypothgraph, partial_within.source, partial_within.target)
    assert max_confidence > confidence

    # normalized confidence should be in (0..1)
    normalized_confidence = compute_confidence.normalized_confidence(
            hypothgraph, partial_within)
    assert normalized_confidence > 0 and normalized_confidence < 1
def test_full_evidenced_within_on_path_graph(get_complex_graph_and_configurations):
    test_data   = get_complex_graph_and_configurations
    hypothgraph = test_data['hypothgraph']
    full_within = test_data['full_within']

    # confidence with nothing evidenced should be 0
    confidence = compute_confidence.confidence(hypothgraph, full_within)
    assert confidence > 0

    # max confidence for the same boundary should be equal to confidence
    max_confidence = compute_confidence.max_confidence(
            hypothgraph, full_within.source, full_within.target)
    assert max_confidence == confidence

    # normalized confidence should be 1
    normalized_confidence = compute_confidence.normalized_confidence(
            hypothgraph, full_within)
    assert normalized_confidence == 1