greedy_modularity_communities(G, weight=None, resolution=1, cutoff=1, best_n=None, n_communities=None)
This function uses Clauset-Newman-Moore greedy modularity maximization to find the community partition with the largest modularity.
Greedy modularity maximization begins with each node in its own community and repeatedly joins the pair of communities that lead to the largest modularity until no futher increase in modularity is possible (a maximum). Two keyword arguments adjust the stopping condition. :None:None:`cutoff`
is a lower limit on the number of communities so you can stop the process before reaching a maximum (used to save computation time). best_n
is an upper limit on the number of communities so you can make the process continue until at most n communities remain even if the maximum modularity occurs for more. To obtain exactly n communities, set both :None:None:`cutoff`
and best_n
to n.
This function maximizes the generalized modularity, where :None:None:`resolution`
is the resolution parameter, often expressed as $\gamma$. See ~networkx.algorithms.community.quality.modularity
.
The name of an edge attribute that holds the numerical value used as a weight. If None, then each edge has weight 1. The degree is the sum of the edge weights adjacent to the node.
If resolution is less than 1, modularity favors larger communities. Greater than 1 favors smaller communities.
A minimum number of communities below which the merging process stops. The process stops at this number of communities even if modularity is not maximized. The goal is to let the user stop the process early. The process stops before the cutoff if it finds a maximum of modularity.
A maximum number of communities above which the merging process will not stop. This forces community merging to continue after modularity starts to decrease until best_n
communities remain. If None
, don't force it to continue beyond a maximum.
The :None:None:`n_communities`
parameter is deprecated - use :None:None:`cutoff`
and/or :None:None:`best_n`
to set bounds on the desired number of communities instead.
A minimum number of communities below which the merging process stops. The process stops at this number of communities even if modularity is not maximized. The goal is to let the user stop the process early. The process stops before the cutoff if it finds a maximum of modularity.
[1, G.number_of_nodes()]
, or if best_n
< :None:None:`cutoff`
. Also raised if :None:None:`cutoff`
is used with the deprecated n_communities
parameter.
A list of frozensets of nodes, one for each community. Sorted by length with largest communities first.
Find communities in G using greedy modularity maximization.
>>> from networkx.algorithms.community import greedy_modularity_communitiesSee :
... G = nx.karate_club_graph()
... c = greedy_modularity_communities(G)
... sorted(c[0]) [8, 14, 15, 18, 20, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33]
The following pages refer to to this document either explicitly or contain code examples using this.
networkx.algorithms.community.modularity_max.greedy_modularity_communities
networkx.algorithms.community.modularity_max.naive_greedy_modularity_communities
Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.
Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)
SVG is more flexible but power hungry; and does not scale well to 50 + nodes.
All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them