Example #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
Example #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)
Example #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)
Example #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)
Example #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
Example #6
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')
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')
Example #8
0
def test_modularity_graph_a_node():
    matrix_graph = np.array([[0]])
    assert 0 == modularity(matrix_graph)