def get_trivial_example():
    subgraph = nx.DiGraph()
    subgraph.add_edge(0, 3)

    big_graph = nx.complete_graph(4, create_using=nx.DiGraph())

    source, target = 0, 3

    big_hypothgraph = convert_to_hypothgraph.convert_to_hypothgraph(big_graph)
    sub_hypothgraph = convert_to_hypothgraph.convert_to_hypothgraph(subgraph)

    # big, small, source, target
    return big_hypothgraph, sub_hypothgraph, source, target
Beispiel #2
0
def get_digraph_with_cycle():
    digraph = nx.complete_graph(5, create_using=nx.DiGraph())
    digraph.add_path(xrange(4, 10))

    hypothgraph = convert_to_hypothgraph.convert_to_hypothgraph(digraph)

    return hypothgraph
Beispiel #3
0
def get_path_graph_and_configurations():
    path_graph = nx.path_graph(10, nx.DiGraph())
    hypothgraph = convert_to_hypothgraph.convert_to_hypothgraph(path_graph)

    # hypothesis configurations (source, target, evidenced_nodes), we fix
    # source and target to some nodes
    source = 0
    target = 4

    # nothing evidenced, partially within boundary, full within boundary,
    # nothing inside, some outside
    nothing = Hypoth_Conf(source=source, target=target, evidenced_nodes=[])
    partial_within = Hypoth_Conf(source=source,
                                 target=target,
                                 evidenced_nodes=[0, 2])
    full_within = Hypoth_Conf(source=source,
                              target=target,
                              evidenced_nodes=[0, 1, 2, 3, 4])

    return {
        'hypothgraph': hypothgraph,
        'nothing': nothing,
        'partial_within': partial_within,
        'full_within': full_within,
    }
Beispiel #4
0
def generate_sub_hypothgraph(hypothgraph, source, target,
                            ratio_endpoints_paths=0.5,
                            ratio_on_boundary_paths=0.5,
                            data=False):
    sub_hypothgraph = nx.DiGraph()
    sub_hypothgraph = convert_to_hypothgraph.convert_to_hypothgraph(sub_hypothgraph)

    # adding endpoints paths
    endpoints_paths = paths.take_ratio_endpoints_paths_rand(
            hypothgraph, source, target, ratio=ratio_endpoints_paths)

    for endpoints_path in endpoints_paths:
        sub_hypothgraph.add_path(endpoints_path)

    # adding on boundary paths
    on_boundary_paths = paths.take_ratio_boundary_paths_rand(
            hypothgraph, source, target, ratio=ratio_on_boundary_paths)

    for on_boundary_path in on_boundary_paths:
        sub_hypothgraph.add_path(on_boundary_path)

    # add data if required
    sub_hypothgraph = copy_data_to_subgraph(hypothgraph, sub_hypothgraph)

    return sub_hypothgraph
def get_richer_example():
    big_graph = nx.complete_graph(10, create_using=nx.DiGraph())
    subgraph = big_graph.subgraph(xrange(4))

    # add some paths to a far node in the big graph
    subgraph.add_edge(2, 6)
    subgraph.add_edge(3, 6)
    subgraph.add_edge(3, 5)
    subgraph.add_edge(5, 6)

    # convert to hypothesis graphs and return
    big_hypothgraph = convert_to_hypothgraph.convert_to_hypothgraph(big_graph)
    sub_hypothgraph = convert_to_hypothgraph.convert_to_hypothgraph(subgraph)

    # big, small, source, target
    return big_hypothgraph, sub_hypothgraph, 2, 6
Beispiel #6
0
def sample_hypothgraph(digraph=None):
    if digraph:
        digraph = digraph.copy()
    else:
        digraph = sample_digraph()

    hypothgraph = convert_to_hypothgraph.convert_to_hypothgraph(digraph)

    return hypothgraph
Beispiel #7
0
def test_convert_to_hypothgraph(get_complete_graph):
    digraph = get_complete_graph
    # assert there are no computed meta data like `evidence_weight` etc.
    for node, node_data in digraph.nodes_iter(data=True):
        assert not 'evidence_weight' in node_data
        assert not 'importance_weight' in node_data

    hypothgraph = convert_to_hypothgraph.convert_to_hypothgraph(digraph)

    # every node should have computed btwin_centrality
    for node, node_data in hypothgraph.nodes_iter(data=True):
        assert 'evidence_weight' in node_data
        assert 'importance_weight' in node_data
def get_complex_graph_and_configurations():
    digraph = nx.path_graph(11, create_using=nx.DiGraph())
    digraph.add_cycle([2, 3, 4])
    digraph.add_cycle([6, 7, 8])
    hypothgraph = convert_to_hypothgraph.convert_to_hypothgraph(digraph)

    source, target = 2, 8

    nothing  =  Hypoth_Conf(source=source, target=target, evidenced_nodes=[])
    partial  =  Hypoth_Conf(source=source, target=target, evidenced_nodes=[3, 6, 7])
    full     =  Hypoth_Conf(source=source, target=target, evidenced_nodes=range(2,9))

    return {
        'hypothgraph': hypothgraph,
        'nothing': nothing,
        'partial_within': partial,
        'full_within': full
    }
def get_trivial_example():
    digraph = nx.complete_graph(6, create_using=nx.DiGraph())
    hypothgraph = convert_to_hypothgraph.convert_to_hypothgraph(digraph)

    return hypothgraph