- naive_greedy_modularity_communities(G, resolution=1)¶
Find communities in G using greedy modularity maximization.
This implementation is O(n^4), much slower than alternatives, but it is provided as an easy-to-understand reference implementation.
Greedy modularity maximization begins with each node in its own community and joins the pair of communities that most increases modularity until no such pair exists.
This function maximizes the generalized modularity, where
resolutionis the resolution parameter, often expressed as \(\gamma\). See
- GNetworkX graph
- resolutionfloat (default=1)
If resolution is less than 1, modularity favors larger communities. Greater than 1 favors smaller communities.
A list of sets of nodes, one for each community. Sorted by length with largest communities first.
>>> from networkx.algorithms.community import \ ... naive_greedy_modularity_communities >>> G = nx.karate_club_graph() >>> c = naive_greedy_modularity_communities(G) >>> sorted(c) [8, 14, 15, 18, 20, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33]