コード例 #1
0
def test_modularity():
    assert modularity(np.array([[0, 1, 0], [1, 0, 1], [0, 1, 0]])) == -0.375
    assert modularity(np.array([[2, 1], [1, 0]])) == -0.125
    assert modularity(
        np.array([[0, 1, 1, 0, 0, 0, 0], [1, 0, 1, 0, 0, 0, 0],
                  [1, 1, 0, 1, 0, 0, 0], [0, 0, 1, 0, 1, 0, 1],
                  [0, 0, 0, 1, 0, 1, 0], [0, 0, 0, 0, 1, 0, 1],
                  [0, 0, 0, 1, 0, 1, 0]])) == -0.1484375
コード例 #2
0
def test_modularity_graph_plus_grand():
    matrix_graph = np.array([[0, 1], [1, 0]])
    matrix_graph1 = np.array([[0, 0, 0], [0, 4, 0], [0, 0, 1]])
    matrix_graph2 = np.array([[4, 0], [0, 1]])
    matrix_graph3 = np.array([[0, 0, 2], [0, 0, 0], [2, 0, 0]])
    matrix_graph4 = np.array([[0, 1, 1], [1, 0, 0], [1, 0, 0]])
    assert -0.5 == modularity(matrix_graph)
    assert -0.5 == modularity(matrix_graph3)
    assert modularity(matrix_graph1) == modularity(matrix_graph2)
    assert -0.375 == modularity(matrix_graph4)
コード例 #3
0
def test_zerolization():
    G = nx.Graph()
    G.add_edge(0, 1, weight=1)
    G.add_edge(0, 2, weight=1)
    G.add_edge(1, 2, weight=1)
    G.add_edge(2, 3, weight=1)
    G.add_edge(3, 4, weight=1)
    G.add_edge(4, 5, weight=1)
    G.add_edge(5, 6, weight=1)
    G.add_edge(3, 6, weight=1)
    A = nx.to_numpy_matrix(G)
    B = A.copy()
    E = zerolize_the_be_visited(A, 0, 1)
    D = compression(B, 0, 1)
    assert modularity(E) == modularity(D)
コード例 #4
0
def test_moudularity_with_seven_nodes():
    G = nx.Graph()
    G.add_edge(0, 1, weight=1)
    G.add_edge(0, 2, weight=1)
    G.add_edge(1, 2, weight=1)
    G.add_edge(2, 3, weight=1)
    G.add_edge(3, 4, weight=1)
    G.add_edge(4, 5, weight=1)
    G.add_edge(5, 6, weight=1)
    G.add_edge(3, 6, weight=1)
    A = nx.to_numpy_matrix(G)
    assert -0.1484375 == modularity(A)
コード例 #5
0
def test_moudularity_after_compression():
    G = nx.Graph()
    G.add_edge(0, 1, weight=1)
    G.add_edge(0, 2, weight=1)
    G.add_edge(1, 2, weight=1)
    G.add_edge(2, 3, weight=1)
    G.add_edge(3, 4, weight=1)
    G.add_edge(4, 5, weight=1)
    G.add_edge(5, 6, weight=1)
    G.add_edge(3, 6, weight=1)
    A = nx.to_numpy_matrix(G)
    B = compression(A, 0, 1)
    assert modularity(B) == -0.0546875
コード例 #6
0
ファイル: main.py プロジェクト: msionkin/community-detection
def louvain_test(graph):
    '''
    :param graph: networkx.Graph
    :return: None
    '''
    print("Louvain has been started started")
    start_time = time.time()
    pa = louvain.best_partition(graph)
    print("time : ", time.time() - start_time)
    modular = louvain.modularity(pa, graph)
    print('Louvain modularity: ', modular)
    # sg.print_graph_communities(pa)
    sg.write_graph_communities(pa, "./data/vk_louvain_source.txt")
    print('\n')
コード例 #7
0
def louvain_test(graph):
    '''
    :param graph: networkx.Graph
    :return: None
    '''
    print("Louvain has been started started")
    start_time = time.time()
    pa = louvain.best_partition(graph)
    print("time : ", time.time() - start_time)
    modular = louvain.modularity(pa, graph)
    print('Louvain modularity: ', modular)
    # sg.print_graph_communities(pa)
    sg.write_graph_communities(pa, "./data/vk_louvain_source.txt")
    print('\n')
コード例 #8
0
def test_modularity_graph_a_node():
    matrix_graph = np.array([[0]])
    assert 0 == modularity(matrix_graph)