Aller au contenu principal

Louvain method


Louvain method


The Louvain method for community detection is a method 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). The method is a greedy optimization method that appears to run in time O ( n log n ) {\displaystyle O(n\cdot \log n)} where n {\displaystyle n} is the number of nodes in the network.

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 −0.5 (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 iterations 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. The Louvain algorithm was shown to correctly identify the community structure when it exists, in particular in the stochastic block model.

Algorithm

The value to be optimized is modularity, defined as a value in the range [ 1 / 2 , 1 ] {\displaystyle [-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 = 1 2 m i = 1 N j = 1 N [ A i j k i k j 2 m ] δ ( c i , c j ) , {\displaystyle Q={\frac {1}{2m}}\sum _{i=1}^{N}\sum _{j=1}^{N}{\bigg [}A_{ij}-{\frac {k_{i}k_{j}}{2m}}{\bigg ]}\delta (c_{i},c_{j}),}

where:

  • A i j {\displaystyle A_{ij}} represents the edge weight between nodes i {\displaystyle i} and j {\displaystyle j} ; see Adjacency matrix;
  • k i {\displaystyle k_{i}} and k j {\displaystyle k_{j}} are the sum of the weights of the edges attached to nodes i {\displaystyle i} and j {\displaystyle j} , respectively;
  • m {\displaystyle m} is the sum of all of the edge weights in the graph;
  • N {\displaystyle N} is the total number of nodes in the graph;
  • c i {\displaystyle c_{i}} and c j {\displaystyle c_{j}} are the communities to which the nodes i {\displaystyle i} and j {\displaystyle j} belong; and
  • δ {\displaystyle \delta } is Kronecker delta function:

δ ( c i , c j ) = { 1 if  c i  and  c j  are the same cluster 0 otherwise {\displaystyle {\begin{aligned}\delta (c_{i},c_{j})&={\begin{cases}1&{\text{if }}c_{i}{\text{ and }}c_{j}{\text{ are the same cluster}}\\0&{\text{otherwise}}\end{cases}}\end{aligned}}}

Based on the above equation, the modularity of a community c {\displaystyle c} can be calculated as:

Q c = 1 2 m i j A i j 1 { c i = c j = c } ( i k i 2 m 1 { c i = c } ) 2 = Σ i n 2 m ( Σ t o t 2 m ) 2 {\displaystyle {\begin{aligned}Q_{c}&={\dfrac {1}{2m}}\sum _{i}\sum _{j}A_{ij}\mathbf {1} \left\{c_{i}=c_{j}=c\right\}-\left(\sum _{i}{\dfrac {k_{i}}{2m}}\mathbf {1} \left\{c_{i}=c\right\}\right)^{2}\\&={\frac {\Sigma _{in}}{2m}}-\left({\frac {\Sigma _{tot}}{2m}}\right)^{2}\end{aligned}}}

where

  • Σ i n {\displaystyle \Sigma _{in}} is the sum of edge weights between nodes within the community c {\displaystyle c} (each edge is considered twice); and
  • Σ t o t {\displaystyle \Sigma _{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 {\displaystyle Q} , it can be written as:

Q = c Q c {\displaystyle Q=\sum _{c}Q_{c}}

In order to maximize modularity efficiently, the Louvain Method has two phases that are repeated iteratively.

Phase 1:

1. First, each node in the network is assigned to its own community.

2. Next, for each node i {\displaystyle i} , the change in modularity is calculated for removing i {\displaystyle i} from its own community and moving it into the community of each neighbor j {\displaystyle j} of i {\displaystyle i} . This value is computed in two steps:

(a) Compute the change in modularity Δ Q {\displaystyle \Delta Q} for removing node i {\displaystyle i} from its original community.

(b) Compute the change in modularity Δ Q {\displaystyle \Delta Q} for inserting an isolated node i {\displaystyle i} (i.e. node i {\displaystyle i} has no connections and is in a community of only itself) into the community of neighbouring node, denoted c j {\displaystyle c_{j}} .

In the following, we will show the derivation for (b). The equations for (a) are similar and can be computed by similar methods.

First, we compute the modularity of the isolated cluster of node i {\displaystyle i} , which we will call c i {\displaystyle c_{i}} . Here we are assuming that there are no loops, and so A μ μ = 0 {\displaystyle A_{\mu \mu }=0} for all values of μ {\displaystyle \mu } :

Q i prev = 1 2 m μ = 1 N i = 1 ν = 1 N i = 1 A μ ν ( μ = 1 N i = 1 k μ 2 m ) 2 = ( k i 2 m ) 2 {\displaystyle {\begin{aligned}Q_{i}^{\text{prev}}&={\dfrac {1}{2m}}\sum _{\mu =1}^{N_{i}=1}\sum _{\nu =1}^{N_{i}=1}A_{\mu \nu }-\left(\sum _{\mu =1}^{N_{i}=1}{\dfrac {k_{\mu }}{2m}}\right)^{2}\\&=-\left({\dfrac {k_{i}}{2m}}\right)^{2}\end{aligned}}}

Next, we compute the modularity of the cluster c j {\displaystyle c_{j}} before we have added the new node i {\displaystyle i} . We already computed this equation:

Q j prev = 1 2 m μ = 1 N j ν = 1 N j A μ ν ( μ = 1 N j k μ 2 m ) 2 {\displaystyle {\begin{aligned}Q_{j}^{\text{prev}}&={\dfrac {1}{2m}}\sum _{\mu =1}^{N_{j}}\sum _{\nu =1}^{N_{j}}A_{\mu \nu }-\left(\sum _{\mu =1}^{N_{j}}{\dfrac {k_{\mu }}{2m}}\right)^{2}\end{aligned}}}

Finally, we compute the modularity of the cluster c j {\displaystyle c_{j}} after we have added a new node i {\displaystyle i} :

Q j updated = 1 2 m μ = 1 N j + 1 ν = 1 N j + 1 A μ ν ( μ = 1 N j + 1 k μ 2 m ) 2 {\displaystyle {\begin{aligned}Q_{j}^{\text{updated}}&={\dfrac {1}{2m}}\sum _{\mu =1}^{N_{j}+1}\sum _{\nu =1}^{N_{j}+1}A_{\mu \nu }-\left(\sum _{\mu =1}^{N_{j}+1}{\dfrac {k_{\mu }}{2m}}\right)^{2}\end{aligned}}}

We can rewrite the first term as follows:

1 2 m μ = 1 N j + 1 ν = 1 N j + 1 A μ ν = 1 2 m [ μ = 1 N j ν = 1 N j A μ ν + 2 μ = 1 N j + 1 A μ , N j + 1 ] = 1 2 m [ μ = 1 N j ν = 1 N j A μ ν + 2 k i ( j ) ] {\displaystyle {\begin{aligned}{\dfrac {1}{2m}}\sum _{\mu =1}^{N_{j}+1}\sum _{\nu =1}^{N_{j}+1}A_{\mu \nu }&={\dfrac {1}{2m}}\left[\sum _{\mu =1}^{N_{j}}\sum _{\nu =1}^{N_{j}}A_{\mu \nu }+2\sum _{\mu =1}^{N_{j}+1}A_{\mu ,N_{j}+1}\right]\\&={\dfrac {1}{2m}}\left[\sum _{\mu =1}^{N_{j}}\sum _{\nu =1}^{N_{j}}A_{\mu \nu }+2k_{i}^{(j)}\right]\end{aligned}}}

where k i ( j ) {\displaystyle k_{i}^{(j)}} represents the sum of the weights of all the edges which go between node i {\displaystyle i} and the nodes in community c j {\displaystyle c_{j}} . In other words, k i ( j ) {\displaystyle k_{i}^{(j)}} is the degree of node i {\displaystyle i} within community c j {\displaystyle c_{j}} .

We can rewrite the second term as:

( μ = 1 N j + 1 k μ 2 m ) 2 = μ = 1 N j + 1 ν = 1 N j + 1 k μ k ν ( 2 m ) 2 = μ = 1 N j ν = 1 N j k μ k ν ( 2 m ) 2 + 2 k N j + 1 μ = 1 N j + 1 k μ ( 2 m ) 2 + ( k N j + 1 ) 2 ( 2 m ) 2 = 1 ( 2 m ) 2 [ ( μ = 1 N j k μ + k N j + 1 ) ( ν = 1 N j k ν + k N j + 1 ) ] = ( μ = 1 N j k μ + k N j + 1 2 m ) 2 {\displaystyle {\begin{aligned}\left(\sum _{\mu =1}^{N_{j}+1}{\dfrac {k_{\mu }}{2m}}\right)^{2}&=\sum _{\mu =1}^{N_{j}+1}\sum _{\nu =1}^{N_{j}+1}{\dfrac {k_{\mu }k_{\nu }}{(2m)^{2}}}\\&=\sum _{\mu =1}^{N_{j}}\sum _{\nu =1}^{N_{j}}{\dfrac {k_{\mu }k_{\nu }}{(2m)^{2}}}+2k_{N_{j}+1}\sum _{\mu =1}^{N_{j}+1}{\dfrac {k_{\mu }}{(2m)^{2}}}+{\dfrac {(k_{N_{j}+1})^{2}}{(2m)^{2}}}\\&={\dfrac {1}{(2m)^{2}}}\left[\left(\sum _{\mu =1}^{N_{j}}k_{\mu }+k_{N_{j}+1}\right)\left(\sum _{\nu =1}^{N_{j}}k_{\nu }+k_{N_{j}+1}\right)\right]\\&=\left({\dfrac {\sum _{\mu =1}^{N_{j}}k_{\mu }+k_{N_{j}+1}}{2m}}\right)^{2}\end{aligned}}}

Putting this together we have:

Q j updated = 1 2 m [ μ = 1 N j ν = 1 N j A μ ν + 2 k i ( j ) ] ( μ = 1 N j k μ + k N j + 1 2 m ) 2 {\displaystyle {\begin{aligned}Q_{j}^{\text{updated}}&={\dfrac {1}{2m}}\left[\sum _{\mu =1}^{N_{j}}\sum _{\nu =1}^{N_{j}}A_{\mu \nu }+2k_{i}^{(j)}\right]-\left({\dfrac {\sum _{\mu =1}^{N_{j}}k_{\mu }+k_{N_{j}+1}}{2m}}\right)^{2}\end{aligned}}}

Putting together the equations for Q i prev {\displaystyle Q_{i}^{\text{prev}}} , Q j prev {\displaystyle Q_{j}^{\text{prev}}} , and Q j updated {\displaystyle Q_{j}^{\text{updated}}} , we can compute the change in modularity Δ Q {\displaystyle \Delta Q} for adding an isolated node i {\displaystyle i} to the cluster c j {\displaystyle c_{j}} . This is sometimes referred to as the gain:

Δ Q = Q j updated Q j prev Q i prev = 1 2 m [ μ = 1 N j ν = 1 N j A μ ν + 2 k i ( j ) ] ( μ = 1 N j k μ + k N j + 1 2 m ) 2 [ 1 2 m μ = 1 N j ν = 1 N j A μ ν ( μ = 1 N j k μ 2 m ) 2 ( k i 2 m ) 2 ] {\displaystyle {\begin{aligned}\Delta Q&=Q_{j}^{\text{updated}}-Q_{j}^{\text{prev}}-Q_{i}^{\text{prev}}\\&={\dfrac {1}{2m}}\left[\sum _{\mu =1}^{N_{j}}\sum _{\nu =1}^{N_{j}}A_{\mu \nu }+2k_{i}^{(j)}\right]-\left({\dfrac {\sum _{\mu =1}^{N_{j}}k_{\mu }+k_{N_{j}+1}}{2m}}\right)^{2}\\&-\left[{\dfrac {1}{2m}}\sum _{\mu =1}^{N_{j}}\sum _{\nu =1}^{N_{j}}A_{\mu \nu }-\left(\sum _{\mu =1}^{N_{j}}{\dfrac {k_{\mu }}{2m}}\right)^{2}-\left({\dfrac {k_{i}}{2m}}\right)^{2}\right]\end{aligned}}}

3. Once the change in modularity Δ Q {\displaystyle \Delta Q} has been computed for all communities { c j } {\displaystyle \{c_{j}\}} that node i {\displaystyle i} is connected to, node i {\displaystyle i} is placed into the community that resulted in the greatest modularity increase. If no increase is possible, node i {\displaystyle i} remains in its original community.

4. 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.

Phase 2:

The second phase of the algorithm involves reducing communities to a single node and repeating the steps in Phase 1:

1. Each community c j {\displaystyle c_{j}} is reduced to a single node. Edges connecting nodes from c j {\displaystyle c_{j}} to other communities and likewise reduced to a single weighted edge.

2. Once the new graph is created, the second phase has ended and the first phase can be re-applied to the new network.

Previous uses

  • Twitter social Network (2.4 Million nodes, 38 million links) by Josep Pujol, Vijay Erramilli, and Pablo Rodriguez: The authors explore the problem of partitioning Online Social Networks onto different machines.
  • Mobile phone Network (4 Million nodes, 100 Million links) by Derek Greene, Donal Doyle, and Padraig Cunningham: Community-tracking strategies for identifying dynamic communities of different dynamic social networks.
  • Detecting species in network-based dynamical model.

Disadvantages

It is important to emphasize that Louvain produces only non-overlapping communities, which means that each node can belong to at most one community. This is highly unrealistic in many real-world applications. For example, in social networks, most people belong to multiple communities: their family, their friends, their co-workers, old school buddies, etc. In biological networks, most genes or proteins belong to more than one pathway or complex. Furthermore, Louvain has been shown to sometimes produce arbitrarily badly connected communities, and has been effectively superseded (at least in the non-overlapping case) by the Leiden algorithm.

Comparison to other methods of non-overlapping community detection

When comparing modularity optimization methods, the two measures of importance are the speed and the resulting modularity value. A higher speed is better as it shows a method is more efficient than others and a higher modularity value is desirable as it points to having better-defined communities. The compared methods are, the algorithm of Clauset, Newman, and Moore, Pons and Latapy, and Wakita and Tsurumi.

-/- in the table refers to a method that took over 24hrs to run. This table (from) shows that the Louvain method outperforms many similar modularity optimization methods in both the modularity and the time categories.

See also

  • Leiden algorithm
  • Modularity (networks)
  • Community structure
  • Network science
  • K-means clustering

References

  • "The Louvain method for community detection in large networks" Vincent Blondel http://perso.uclouvain.be/vincent.blondel/research/louvain.html

Text submitted to CC-BY-SA license. Source: Louvain method by Wikipedia (Historical)