leiden_partitions#
- leiden_partitions(G, weight='weight', resolution=1, seed=None)[source]#
Yield partitions for each level of Leiden Community Detection (backend required)
Attention
This function does not have a default NetworkX implementation. It may only be run with an installable backend that supports it.
Hint: use
backend=...
keyword argument to specify a backend or add backends tonx.config.backend_priority
.Leiden Community Detection is an algorithm to extract the community structure of a network based on modularity optimization.
The partitions across levels (steps of the algorithm) form a dendrogram of communities. A dendrogram is a diagram representing a tree and each level represents a partition of the G graph. The top level contains the smallest communities and as you traverse to the bottom of the tree the communities get bigger and the overall modularity increases making the partition better.
Each level is generated by executing the three phases of the Leiden Community Detection algorithm. See
leiden_communities
.- Parameters:
- GNetworkX graph
- weightstring or None, optional (default=”weight”)
The name of an edge attribute that holds the numerical value used as a weight. If None then each edge has weight 1.
- resolutionfloat, optional (default=1)
If resolution is less than 1, the algorithm favors larger communities. Greater than 1 favors smaller communities.
- seedinteger, random_state, or None (default)
Indicator of random number generation state. See Randomness.
- Yields:
- list
A list of disjoint sets (partition of
G
). Each set represents one community. All communities together contain all the nodes inG
. The yielded partitions increase modularity with each iteration.
See also
References
[1]Traag, V.A., Waltman, L. & van Eck, N.J. From Leiden to Leiden: guaranteeing well-connected communities. Sci Rep 9, 5233 (2019). https://doi.org/10.1038/s41598-019-41695-z