Exemplo n.º 1
0
def test_bipartite_common_neighbour():
    B = nx.Graph()
    B.add_nodes_from(range(1, 5), eligible=0)
    B.add_nodes_from("abc", eligible=1)
    B.add_edges_from([(1, "a"), (1, "b"), (2, "a"), (2, "b"), (2, "c"),
                      (3, "c"), (4, "a")])

    expected = {Pair("a", "b"): 2, Pair("b", "c"): 1, Pair("a", "c"): 1}
    assert CommonNeighbours(B, eligible="eligible").predict() == expected
Exemplo n.º 2
0
def test_bipartite_common_neighbour():
    B = nx.Graph()
    B.add_nodes_from(range(1, 5), eligible=0)
    B.add_nodes_from('abc', eligible=1)
    B.add_edges_from([(1, 'a'), (1, 'b'), (2, 'a'), (2, 'b'), (2, 'c'),
                      (3, 'c'), (4, 'a')])

    expected = {Pair('a', 'b'): 2, Pair('b', 'c'): 1, Pair('a', 'c'): 1}
    assert_dict_equal(CommonNeighbours(B, eligible='eligible').predict(), expected)
Exemplo n.º 3
0
def test_for_comparison():
    from linkpred.linkpred import for_comparison
    from linkpred.evaluation import Pair

    G = nx.path_graph(10)
    expected = set(Pair(x) for x in [(0, 1), (1, 2), (2, 3), (3, 4), (4, 5),
                                     (5, 6), (6, 7), (7, 8), (8, 9)])
    assert_equal(for_comparison(G), expected)

    to_delete = [Pair(2, 3), Pair(8, 9)]
    expected = expected.difference(to_delete)
    assert_equal(for_comparison(G, exclude=to_delete), expected)
Exemplo n.º 4
0
def test_for_comparison():
    from linkpred.linkpred import for_comparison
    from linkpred.evaluation import Pair

    G = nx.path_graph(10)
    expected = {(0, 1), (1, 2), (2, 3), (3, 4), (4, 5), (5, 6), (6, 7), (7, 8),
                (8, 9)}
    assert for_comparison(G) == expected

    to_delete = [Pair(2, 3), Pair(8, 9)]
    expected = {Pair(t) for t in expected}
    expected = expected.difference(to_delete)
    assert for_comparison(G, exclude=to_delete) == expected
Exemplo n.º 5
0
def test_random_exclude_noneligible():
    G = nx.Graph()
    G.add_nodes_from(range(5), eligible=True)
    G.add_nodes_from(range(5, 10), eligible=False)
    prediction = Random(G, eligible='eligible').predict()
    assert_equal(len(prediction), 10)
    for i in range(5):
        for j in range(5):
            if i != j:
                assert Pair(i, j) in prediction
Exemplo n.º 6
0
 def test_copy_weighted(self):
     expected = {Pair(0, 1): 3.0, Pair(1, 2): 7.5}
     assert_dict_equal(Copy(self.G).predict(weight="weight"), expected)
Exemplo n.º 7
0
 def test_copy_unweighted(self):
     expected = {Pair(0, 1): 1, Pair(1, 2): 1}
     assert_dict_equal(Copy(self.G).predict(), expected)
Exemplo n.º 8
0
 def test_copy_unweighted(self):
     expected = {Pair(0, 1): 1, Pair(1, 2): 1}
     assert Copy(self.G).predict() == expected