Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

girvan_newman ValueError: max() arg is an empty sequence #1799

Closed
gfairchild opened this issue Oct 6, 2015 · 1 comment
Closed

girvan_newman ValueError: max() arg is an empty sequence #1799

gfairchild opened this issue Oct 6, 2015 · 1 comment

Comments

@gfairchild
Copy link

First off, I'm running Python 3.4.3 and NetworkX 2.0.dev20151006145736 (installed earlier today from the latest Git master).

I have a simple graph (download the pickle here) that I'm trying to run girvan_newman on:

communities = nx.girvan_newman(graph)
pprint.pprint(list(communities))

I'm getting the following error:

> ./community_detection.py ../data/en_Influenza_1.pickle 
Traceback (most recent call last):
  File "./community_detection.py", line 32, in <module>
    communities = nx.girvan_newman(args.graph)
  File "[path]/env/lib/python3.4/site-packages/networkx/algorithms/community/centrality.py", line 39, in girvan_newman
    _remove_max_edge(g, weight)
  File "[path]/env/lib/python3.4/site-packages/networkx/algorithms/community/centrality.py", line 61, in _remove_max_edge
    max_value = max(betweenness.values())
ValueError: max() arg is an empty sequence

I'm guessing there's just an edge case in the girvan_newman code that was missed.

@hagberg
Copy link
Member

hagberg commented Oct 24, 2015

There are definitely some issues with the girvan_newman() algorithm.

  1. Your case is triggering a bug where self-loops are not considered - Self loops need to be removed, e.g.
    g = G.copy().to_undirected()
    g.remove_edges_from(g.selfloop_edges())
  1. Your original graph has betweenness centralities all equal which triggers a bug where all of the edges are removed in the first pass (one community). The _remove_edge code needs to be something like
    number_components = nx.number_connected_components(G)
    while nx.number_connected_components(G) <= number_components:
        betweenness = nx.edge_betweenness_centrality(G, weight=weight)
        edge = max(betweenness, key=(lambda k:betweenness[k]))
        G.remove_edge(*edge)
  1. The tests are hard to understand and possibly not robust to alternate edge orderings that may occur and are still correct.

@hagberg hagberg added this to the networkx-2.0 milestone Dec 27, 2015
dschult added a commit that referenced this issue Apr 14, 2016
Fixes several issues with the Girvan-Newman partitioning function. Fixes #1703, #1725, #1799
@dschult dschult closed this as completed Apr 14, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants