The Louvain method for community detection is a greedy optimization method intended to extract non-overlapping communities from large networks created by Blondel et al. from the University of Louvain (the source of this method's name).
Modularity optimization The inspiration for this method of community detection is the optimization of modularity as the algorithm progresses. Modularity is a scale value between −1/2 (non-modular clustering) and 1 (fully modular clustering) that measures the relative density of edges inside communities with respect to edges outside communities. Optimizing this value theoretically results in the best possible grouping of the nodes of a given network. But because going through all possible configurations of the nodes into groups is impractical, heuristic algorithms are used. In the Louvain Method of community detection, first small communities are found by optimizing modularity locally on all nodes, then each small community is grouped into one node and the first step is repeated. The method is similar to the earlier method by Clauset, Newman and Moore that connects communities whose amalgamation produces the largest increase in modularity. Although the Louvain algorithm can correctly identify the community structure when its evidence is sufficiently strong in artificial networks, in particular those sampled from the assortative stochastic block model., it is prone to finding spurious communities in random graphs and has been shown to systematically overfit empirical data .
Algorithm description
Modularity The value to be optimized is modularity, defined as a value in the range [−1/2,1] that measures the density of links inside communities compared to links between communities. For a weighted graph, modularity is defined as: Q=12m∑i=1N∑j=1N[Aij−kikj2m]δ(ci,cj), where:
Aij represents the edge weight between nodes i and j; see Adjacency matrix; ki and kj are the sum of the weights of the edges attached to nodes i and j, respectively; m is the sum of all of the edge weights in the graph; N is the total number of nodes in the graph; ci and cj are the communities to which the nodes i and j belong; and δ is Kronecker delta function: δ(ci,cj)={1if ci and cj are the same cluster0otherwise Based on the above equation, the modularity of a community c can be calculated as: Qc=12m∑i∑jAij𝟏{ci=cj=c}−(∑iki2m𝟏{ci=c})2=Σin2m−(Σtot2m)2 where
Σin is the sum of edge weights between nodes within the community c (each edge is considered twice); and Σtot is the sum of all edge weights for nodes within the community (including edges which link to other communities). As nodes in different communities do not contribute to the modularity Q, it can be written as: Q=∑cQc
The Louvain method algorithm The Louvain method works by repeating two phases. In phase one, nodes are sorted into communities based on how the modularity of the graph changes when a node moves communities. In phase two, the graph is reinterpreted so that communities are seen as individual nodes. A detailed explanation is provided below.
Phase 1
Each node in the network is assigned to its own community. The Louvain method begins by considering each node v in a graph to be its own community. This can be seen in Figure 1, where each dot (representing nodes) is a unique color (representing which community the node belongs to).
Nodes are grouped into communities For each node v, we consider how moving v from its current community C into a neighboring community C' will affect the modularity of the graph partition. In the pseudo-code below, this happens in the for-loop. We select the community C' with the greatest change in modularity, and if the change is positive, we move v into C'; otherwise we leave it where it is. This continues until the modularity stops improving.
This process is applied repeatedly and sequentially to all nodes until no modularity increase can occur. Once this local maximum of modularity is hit, the first phase has ended. Figure 2 shows how the graph in Figure 1 might look after one iteration of phase 1.
Phase 2
Communities are reduced to a single node For each community in our graph's partition, the individual nodes making up that community are combined and the community itself becomes a node. The edges connecting distinct communities are used to weight the new edges connecting our aggregate nodes. This process is modeled in the pseudo-code, where the function aggregateGraph returns a new graph whose vertices are the partition of the old graph, and whose edges are calculated using the old graph. This function does not show the edges being weighted, but a simple modification would allow for that information to be tracked.
Figure 3 shows what the graph from Figure 2 would look like after being aggregated. This graph is analogous to the graph in Figure 1 in the sense that each node is assigned to a single community. From here, the process can be repeated so that more nodes are moved into existing communities until an optimal level of modularity is reached. The pseudo-code below shows how the previous two functions work together to complete the process.
… excerpt ends here. Continue reading the full article.





