cdlib.algorithms.louvain

louvain(g_original, weight='weight', resolution=1.0, randomize=False)

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.

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 – boolean, optional Will randomize the node evaluation order and the community evaluation order to get different partitions at each call, default False
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., randomize=False)
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