Girvan-Newman record of removed edges

51 views
Skip to first unread message

Daniel Burns

unread,
Jul 22, 2022, 3:20:55 PMJul 22
to networkx-discuss
Hello,

I am using the Girvan-Newman algorithm to break up a network into communities.

I am using the default edge_betweeness_centrality as the method of selecting edges to remove in order to find the communities and using edge weights in the calculation.

Once I have the number of communities I want, is there a way to see which edges were removed and in which order?  

Thank you,
Dan

Dan Schult

unread,
Jul 22, 2022, 10:44:40 PMJul 22
to networkx...@googlegroups.com
I think that is precisely the kind of personalization that was intended for the argument: most_valuable_edge
The default value calls networkx.edge_betweenness_centrality() and returns the edge with the 
largest centrality. So, you could write a function to do exactly that same calculation, but to also store the
edge in a list accessible to the function, but also to you outside of that function.


edges_removed = []
def recorded_most_valuable_edge(G)
    betweenness = nx.edge_betweenness_centrality(G) 
    max_edge = max(betweenness, key=betweenness.get)
    edges_removed.append(max_edge)
    return max_edge

comp = girvan_newman(G, most_valuable_edge=recorded_most_valuable_edge)
print(edges_removed)

Daniel Burns

unread,
Jul 28, 2022, 11:02:16 AMJul 28
to networkx-discuss
Thank you!  Works great - I added the list as an argument to the function before trying it verbatim.

Thank you,

Dan

Reply all
Reply to author
Forward
0 new messages