cdlib.algorithms.louvain¶
- cdlib.algorithms.louvain(g_original: object, partition: NodeClustering | None = None, weight: str = 'weight', resolution: float = 1.0, randomize: int | None = None) NodeClustering¶
Louvain maximizes a modularity score for each community. The algorithm optimises the modularity in two elementary phases: (1) local moving of nodes; (2) aggregation of the network. In the local moving phase, individual nodes are moved to the community that yields the largest increase in the quality function. In the aggregation phase, an aggregate network is created based on the partition obtained in the local moving phase. Each community in this partition becomes a node in the aggregate network. The two phases are repeated until the quality function cannot be increased further.
Supported Graph Types
Undirected
Directed
Weighted
Yes
No
Yes
- Parameters:
g_original – a networkx/igraph object
partition – NodeClustering object, optional the algorithm will start using this partition of the nodes
weight – str, optional the key in graph to use as weight. Default to “weight”
resolution – double, optional Will change the size of the communities, default to 1.
randomize – int, RandomState instance or None, optional (default=None).
- Returns:
NodeClustering object
- Example:
>>> from cdlib import algorithms >>> import networkx as nx >>> G = nx.karate_club_graph() >>> coms = algorithms.louvain(G, weight='weight', resolution=1.)
- References:
Blondel, Vincent D., et al. Fast unfolding of communities in large networks. Journal of statistical mechanics: theory and experiment 2008.10 (2008): P10008.
Note
Reference implementation: https://github.com/taynaud/python-louvain