leiden_partitions#
- leiden_partitions(G, *, weight='weight', metric='cpm', resolution=1.0, seed=None, theta=0.01)[source]#
Yield partitions at each level of Leiden Community Detection
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 the tree the communities get bigger and the overall partition quality metric increases.
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.
- metricstr (default=”cpm”)
The name of the partition quality metric that the algorithm optimises. Allowed names are “cpm” and “modularity”.
- resolutionfloat, optional (default=1)
Resolution should be a positive number indicating the coarseness of the communities produced. With a lower resolution, larger communities are produced. To see the smaller sub-communities, use a higher resolution.
- seedinteger, random_state, or None (default)
Indicator of random number generation state. See Randomness.
- thetafloat (default=0.01)
Parameter that determines the degree of randomness in the second phase _refine_partition step of the algorithm,
- Yields:
- list of sets of nodes
A partition of
Gas a list of disjoint sets of nodes. Each set represents one community of nodes and each node ofGappears in exactly one set. The quality metric of the yielded partitions increases with each iteration.
See also
References
[1]Traag, V.A., Waltman, L. & van Eck, N.J. From Louvain to Leiden: guaranteeing well-connected communities. Sci Rep 9, 5233 (2019). https://doi.org/10.1038/s41598-019-41695-z