Exemplo n.º 1
0
 def test_cpm(self):
     g = get_string_graph()
     coms = algorithms.cpm(g)
     self.assertEqual(type(coms.communities), list)
     if len(coms.communities) > 0:
         self.assertEqual(type(coms.communities[0]), list)
         self.assertEqual(type(coms.communities[0][0]), str)
Exemplo n.º 2
0
    g = nx.Graph()
    for line in f:
        fields = line.strip("\n").split("\t")
        if (options.bipartite):
            g.add_node(fields[0], bipartite=0)
            g.add_node(fields[1], bipartite=1)
        g.add_edge(fields[0], fields[1], weight=float(fields[2]))

    print(g.number_of_nodes())
    print(g.number_of_edges())
    if (options.method == 'leiden'):
        communities = algorithms.leiden(g, weights='weight', **clust_kwargs)
    elif (options.method == 'louvain'):
        communities = algorithms.louvain(g, weight='weight', **clust_kwargs)
    elif (options.method == 'cpm'):
        communities = algorithms.cpm(g, weights='weight', **clust_kwargs)
    elif (options.method == 'der'):
        communities = algorithms.der(g, **clust_kwargs)
    elif (options.method == 'edmot'):
        communities = algorithms.edmot(g, **clust_kwargs)
    elif (options.method == 'eigenvector'):
        communities = algorithms.eigenvector(g, **clust_kwargs)
    elif (options.method == 'gdmp2'):
        communities = algorithms.gdmp2(g, **clust_kwargs)
    elif (options.method == 'greedy_modularity'):
        communities = algorithms.greedy_modularity(g,
                                                   weight='weight',
                                                   **clust_kwargs)
    #elif(options.method == 'infomap'):
    #	communities = algorithms.infomap(g)
    elif (options.method == 'label_propagation'):
Exemplo n.º 3
0
#
# CONSIGLIO: passare alla cella successiva che carica i risultati da file

# In[30]:

accuracy_spinglass = 0
accuracy_eigenvector = 0
accuracy_leiden = 0
accuracy_cpm = 0
accuracy_rber_pots = 0

for i in range(10):
    result_spinglass_tmp = algorithms.spinglass(g1)
    result_eigenvector_tmp = algorithms.eigenvector(g1)
    result_leiden_tmp = algorithms.leiden(g1)
    result_cpm_tmp = algorithms.cpm(g1, resolution_parameter=.00018)
    result_rber_pots_tmp = algorithms.rber_pots(g1, resolution_parameter=.32)

    #definizione colonne che servono per calcolare l'accuracy
    nodes1['community_spinglass'] = -1
    for i in range(len(result_spinglass_tmp.communities)):
        for j in result_spinglass_tmp.communities[i]:
            nodes1.loc[j, 'community_spinglass'] = i
    nodes1['community_eigenvector'] = -1
    for i in range(len(result_eigenvector_tmp.communities)):
        for j in result_eigenvector_tmp.communities[i]:
            nodes1.loc[j, 'community_eigenvector'] = i
    nodes1['community_leiden'] = -1
    for i in range(len(result_leiden_tmp.communities)):
        for j in result_leiden_tmp.communities[i]:
            nodes1.loc[j, 'community_leiden'] = i