-1

I have been using the Girvan-Newman algorithm from networkx to find the modularity of a network with 4039 nodes and 88,234 edges. Due to the nature of the algorithm, it was running overnight, and wouldn't complete. Hence I paid for colab pro and I was intending to use CuGraph to speed this up, but can't find a CuGraph algorithm that does work. How would I be able to build one, using the edge centrality algorithm, to produce something similar to this:

G2 = nx.karate_club_graph()

comp = girvan_newman(G2)

node_groups = []
for com in next(comp):
  node_groups.append(list(com))

print(node_groups)

color_map = []
for node in G2:
    if node in node_groups[0]:
        color_map.append('blue')
    else: 
        color_map.append('green')  
nx.draw(G2, node_color=color_map, with_labels=True)
plt.show() 
Szabolcs
  • 24,728
  • 9
  • 85
  • 174
  • Welcome to [Stack Overflow.](https://stackoverflow.com/ "Stack Overflow")! Questions that ask for general guidance regarding a problem approach are typically too broad and are not a good fit for this site. People have their own method for approaching the problem and because of this there cannot be a correct answer. Give a good read over [Where to Start](https://softwareengineering.meta.stackexchange.com/questions/6366/where-to-start/6367#6367), and [Minimal Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example "Minimal Reproducible Example") then edit your post. – itprorh66 Nov 09 '21 at 18:41
  • You mentioned Modularity, but Girvan-Netwman returns a dendrogram that shows the structure after each edge removal. Modularity was added in the follow-up paper Newman-Girvan and then in Fast-Newman – Brad Rees Nov 09 '21 at 19:14

2 Answers2

1

The Girvan-Newman algorithm is not in cuGraph. It is a very sequential algorithm where you run betweenness centrality and then drop edge with the highest score. Then just keep repeating that process.

If you are interested in Modularity, you could use either the Louvain, Leiden, ECG, or Spectral community detection algorithms.

A graph with 88 thousand edges should be a few seconds

Brad Rees
  • 96
  • 1
0

Girvan Newman Algorithm just partitions the network on the basis of highest edge betweenness, calculates the modularity for each community structure, and returns the structure having maximum Q. GN is not to optimize modularity. Use Louvain and its improved version Leiden or Fast Greedy: (Clauset-Newman-Moore community detection).