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
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
def test_relative_confidence_richer(get_sample_configuration):
    big, small, source, target = get_sample_configuration

    # generate hypothesis configurations according to the small hypothesis
    nothing_small = Hypoth_Conf(source, target, [])
    partial_small = Hypoth_Conf(
        source, target,
        list(boundary.partial_nodes_boundary_interior(small, source, target)))
    full_small = Hypoth_Conf(
        source, target,
        list(boundary.in_boundary_interior(small, source, target)))

    # relative confidence is the normalized confidence in the small
    # hypothegraph to the bigger hypothgraph
    nothing_conf_big = compute_confidence.normalized_confidence(
        big, nothing_small)
    nothing_conf_small = compute_confidence.normalized_confidence(
        small, nothing_small)
    relative_nothing = abs(nothing_conf_small - nothing_conf_big)

    partial_conf_big = compute_confidence.normalized_confidence(
        big, partial_small)
    partial_conf_small = compute_confidence.normalized_confidence(
        small, partial_small)
    relative_partial = abs(partial_conf_small - partial_conf_big)

    full_conf_big = compute_confidence.normalized_confidence(big, full_small)
    full_conf_small = compute_confidence.normalized_confidence(
        small, full_small)
    relative_full = abs(full_conf_small - full_conf_big)

    # with nothing evidenced our confidence should be 0 regardless of the size
    # of the hypothesis
    assert nothing_conf_big == nothing_conf_small == 0

    # with partial nodes smaller hypothesis confidence is at least as big as
    # the confidence in the bigger hypothesis, but usually is bigger
    assert partial_conf_small >= partial_conf_big

    # with full nodes evidenced in the smaller hypothesis, the same
    # configuration in the bigger hypothesis can only give a smaller confidence
    assert full_conf_small >= full_conf_big