Note

This documents the development version of NetworkX. Documentation for the current release can be found here.

# networkx.algorithms.community.modularity_max.naive_greedy_modularity_communities¶

naive_greedy_modularity_communities(G, resolution=1)[source]

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 resolution is the resolution parameter, often expressed as $$\gamma$$. See modularity().

Parameters
GNetworkX graph
Returns
list

A list of sets of nodes, one for each community. Sorted by length with largest communities first.

greedy_modularity_communities
modularity
>>> from networkx.algorithms.community import greedy_modularity_communities