cdlib.algorithms.louvain¶

louvain
(g_original: object, weight: str = 'weight', resolution: float = 1.0, randomize: int = None) → cdlib.classes.node_clustering.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 No Parameters:  g_original – a networkx/igraph object
 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). If int, random_state is the seed used by the random number generator; If RandomState instance, random_state is the random number generator; If None, the random number generator is the RandomState instance used by np.random.
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/pythonlouvain