aryagraph.algorithms.community.greedy_modularity_communities#

aryagraph.algorithms.community.greedy_modularity_communities(g: Any, weight: str | Callable[[Hashable, Hashable, dict], float] | None = None, resolution: float = 1.0, cutoff: int = 1, best_n: int | None = None) → list[set][source]#

Greedy agglomerative modularity maximisation (Clauset–Newman–Moore).

Starting from singletons, repeatedly merge the pair of adjacent communities with the largest modularity gain ΔQ while ΔQ ≥ 0 (O(m d log n) with a lazily-updated max-heap). Ties go to the pair whose first community comes earliest in graph order, which reproduces networkx’s merges exactly whenever node labels sort in insertion order.

Parameters:
  • cutoff – Stop once only this many communities are left.

  • best_n – Keep merging (even with ΔQ < 0) until at most this many remain.