Modularity (networks)

From HandWiki
Short description: Measure of network community structure
Example of modularity measurement and colouring on a scale-free network.

Modularity is a measure of the structure of networks or graphs which measures the strength of division of a network into modules (also called groups, clusters or communities). Networks with high modularity have dense connections between the nodes within modules but sparse connections between nodes in different modules. Modularity is often used in optimization methods for detecting community structure in networks. Biological networks, including animal brains, exhibit a high degree of modularity. However, modularity maximization is not statistically consistent, and finds communities in its own null model, i.e. fully random graphs, and therefore it cannot be used to find statistically significant community structures in empirical networks. Furthermore, it has been shown that modularity suffers a resolution limit and, therefore, it is unable to detect small communities.

Motivation

Many scientifically important problems can be represented and empirically studied using networks. For example, biological and social patterns, the World Wide Web, metabolic networks, food webs, neural networks and pathological networks are real world problems that can be mathematically represented and topologically studied to reveal some unexpected structural features.[1] Most of these networks possess a certain community structure that has substantial importance in building an understanding regarding the dynamics of the network. For instance, a closely connected social community will imply a faster rate of transmission of information or rumor among them than a loosely connected community. Thus, if a network is represented by a number of individual nodes connected by links which signify a certain degree of interaction between the nodes, communities are defined as groups of densely interconnected nodes that are only sparsely connected with the rest of the network. Hence, it may be imperative to identify the communities in networks since the communities may have quite different properties such as node degree, clustering coefficient, betweenness, centrality,[2] etc., from that of the average network. Modularity is one such measure, which when maximized, leads to the appearance of communities in a given network.

Definition

Modularity is the fraction of the edges that fall within the given groups minus the expected fraction if edges were distributed at random. The value of the modularity for unweighted and undirected graphs lies in the range [math]\displaystyle{ [-1/2,1] }[/math].[3] It is positive if the number of edges within groups exceeds the number expected on the basis of chance. For a given division of the network's vertices into some modules, modularity reflects the concentration of edges within modules compared with random distribution of links between all nodes regardless of modules.

There are different methods for calculating modularity.[1] In the most common version of the concept, the randomization of the edges is done so as to preserve the degree of each vertex. Consider a graph with [math]\displaystyle{ n }[/math] nodes and [math]\displaystyle{ m }[/math] links (edges) such that the graph can be partitioned into two communities using a membership variable [math]\displaystyle{ s }[/math]. If a node [math]\displaystyle{ v }[/math] belongs to community 1, [math]\displaystyle{ s_v = 1 }[/math], or if [math]\displaystyle{ v }[/math] belongs to community 2, [math]\displaystyle{ s_v = -1 }[/math]. Let the adjacency matrix for the network be represented by [math]\displaystyle{ A }[/math], where [math]\displaystyle{ A_{{vw}}=0 }[/math] means there's no edge (no interaction) between nodes [math]\displaystyle{ v }[/math] and [math]\displaystyle{ w }[/math] and [math]\displaystyle{ A_{vw} = 1 }[/math] means there is an edge between the two. Also for simplicity we consider an undirected network. Thus [math]\displaystyle{ A_{vw} = A_{wv} }[/math]. (It is important to note that multiple edges may exist between two nodes, but here we assess the simplest case).

Modularity [math]\displaystyle{ Q }[/math] is then defined as the fraction of edges that fall within group 1 or 2, minus the expected number of edges within groups 1 and 2 for a random graph with the same node degree distribution as the given network.

The expected number of edges shall be computed using the concept of a configuration model.[4] The configuration model is a randomized realization of a particular network. Given a network with [math]\displaystyle{ n }[/math] nodes, where each node [math]\displaystyle{ v }[/math] has a node degree [math]\displaystyle{ k_v }[/math], the configuration model cuts each edge into two halves, and then each half edge, called a stub, is rewired randomly with any other stub in the network, even allowing self-loops (which occur when a stub is rewired to another stub from the same node) and multiple-edges between the same two nodes. Thus, even though the node degree distribution of the graph remains intact, the configuration model results in a completely random network.

Expected Number of Edges Between Nodes

Now consider two nodes [math]\displaystyle{ v }[/math] and [math]\displaystyle{ w }[/math], with node degrees [math]\displaystyle{ k_v }[/math] and [math]\displaystyle{ k_w }[/math] respectively, from a randomly rewired network as described above. We calculate the expected number of full edges between these nodes.

Let us consider each of the [math]\displaystyle{ k_v }[/math] stubs of node [math]\displaystyle{ v }[/math] and create associated indicator variables [math]\displaystyle{ I_i^{(v,w)} }[/math] for them, [math]\displaystyle{ i = 1, \ldots, k_v }[/math], with [math]\displaystyle{ I_i^{(v,w)} = 1 }[/math] if the [math]\displaystyle{ i }[/math]-th stub happens to connect to one of the [math]\displaystyle{ k_w }[/math] stubs of node [math]\displaystyle{ w }[/math] in this particular random graph. If it does not, then [math]\displaystyle{ I_i^{(v,w)}=0 }[/math]. Since the [math]\displaystyle{ i }[/math]-th stub of node [math]\displaystyle{ v }[/math] can connect to any of the [math]\displaystyle{ 2m-1 }[/math] remaining stubs with equal probability, and since there are [math]\displaystyle{ k_w }[/math] stubs it can connect to associated with node [math]\displaystyle{ w }[/math], evidently

[math]\displaystyle{ p(I_i^{(v,w)} = 1) = E[I_i^{(v,w)}] = \frac{k_w}{2m-1} }[/math]

The total number of full edges [math]\displaystyle{ J_{vw} }[/math] between [math]\displaystyle{ v }[/math] and [math]\displaystyle{ w }[/math] is just [math]\displaystyle{ J_{vw} = \sum_{i=1}^{k_v}I_i^{(v,w)} }[/math], so the expected value of this quantity is

[math]\displaystyle{ E[J_{vw}] = E\left[\sum_{i=1}^{k_v} I_i^{(v,w)}\right] = \sum_{i=1}^{k_v} E[I_i^{(v,w)}] = \sum_{i=1}^{k_v} \frac{k_w}{2m-1} = \frac{k_v k_w}{2m - 1} }[/math]

Many texts then make the following approximations, for random networks with a large number of edges. When [math]\displaystyle{ m }[/math] is large, they drop the subtraction of [math]\displaystyle{ 1 }[/math] in the denominator above and simply use the approximate expression [math]\displaystyle{ \frac{k_v k_w}{2m} }[/math] for the expected number of edges between two nodes. Additionally, in a large random network, the number of self-loops and multi-edges is vanishingly small.[5] Ignoring self-loops and multi-edges allows one to assume that there is at most one edge between any two nodes. In that case, [math]\displaystyle{ J_{vw} }[/math] becomes a binary indicator variable, so its expected value is also the probability that it equals [math]\displaystyle{ 1 }[/math], which means one can approximate the probability of an edge existing between nodes [math]\displaystyle{ v }[/math] and [math]\displaystyle{ w }[/math] as [math]\displaystyle{ \frac{k_v k_w}{2m} }[/math].

Modularity

Hence, the difference between the actual number of edges between node [math]\displaystyle{ v }[/math] and [math]\displaystyle{ w }[/math] and the expected number of edges between them is

[math]\displaystyle{ A_{vw} - \frac{k_v k_w}{2m} }[/math]

Summing over all node pairs gives the equation for modularity, [math]\displaystyle{ Q }[/math].[1]

[math]\displaystyle{ Q = \frac{1}{2m} \sum_{vw} \left[ A_{vw} - \frac{k_v k_w}{2m} \right] \frac{s_{v} s_{w}+1}{2} }[/math]

 

 

 

 

(3)

It is important to note that Eq. 3 holds good for partitioning into two communities only. Hierarchical partitioning (i.e. partitioning into two communities, then the two sub-communities further partitioned into two smaller sub communities only to maximize Q) is a possible approach to identify multiple communities in a network. Additionally, (3) can be generalized for partitioning a network into c communities.[6]

[math]\displaystyle{ Q = \frac{1}{(2m)}\sum_{vw} \left[ A_{vw} - \frac{k_v k_w}{(2m)} \right] \delta(c_{v}, c_{w}) =\sum_{i=1}^{c} (e_{ij}-a_{i}^2) }[/math]

 

 

 

 

(4)

where eij is the fraction of edges with one end vertices in community i and the other in community j:

[math]\displaystyle{ e_{ij}= \sum_{vw} \frac{A_{vw}}{2m} 1_{v\in c_i} 1_{w\in c_j} }[/math]

and ai is the fraction of ends of edges that are attached to vertices in community i:

[math]\displaystyle{ a_i=\frac{k_i}{2m} = \sum_{j} e_{ij} }[/math]

Example of multiple community detection

We consider an undirected network with 10 nodes and 12 edges and the following adjacency matrix.

Fig 1. Sample Network corresponding to the Adjacency matrix with 10 nodes, 12 edges.
Fig 2. Network partitions that maximize Q. Maximum Q=0.4896
Node ID 1 2 3 4 5 6 7 8 9 10
1 0 1 1 0 0 0 0 0 0 1
2 1 0 1 0 0 0 0 0 0 0
3 1 1 0 0 0 0 0 0 0 0
4 0 0 0 0 1 1 0 0 0 1
5 0 0 0 1 0 1 0 0 0 0
6 0 0 0 1 1 0 0 0 0 0
7 0 0 0 0 0 0 0 1 1 1
8 0 0 0 0 0 0 1 0 1 0
9 0 0 0 0 0 0 1 1 0 0
10 1 0 0 1 0 0 1 0 0 0

The communities in the graph are represented by the red, green and blue node clusters in Fig 1. The optimal community partitions are depicted in Fig 2.

Matrix formulation

An alternative formulation of the modularity, useful particularly in spectral optimization algorithms, is as follows.[1] Define [math]\displaystyle{ S_{vr} }[/math] to be [math]\displaystyle{ 1 }[/math] if vertex [math]\displaystyle{ v }[/math] belongs to group [math]\displaystyle{ r }[/math] and [math]\displaystyle{ 0 }[/math] otherwise. Then

[math]\displaystyle{ \delta(c_v,c_w) = \sum_r S_{vr} S_{wr} }[/math]

and hence

[math]\displaystyle{ Q = \frac{1}{2m} \sum_{vw} \sum_r \left[ A_{vw} - \frac{k_v k_w}{2m} \right] S_{vr} S_{wr} = \frac{1}{2m} \mathrm{Tr}(\mathbf{S}^\mathrm{T}\mathbf{BS}), }[/math]

where [math]\displaystyle{ S }[/math] is the (non-square) matrix having elements [math]\displaystyle{ S_{v} }[/math] and [math]\displaystyle{ B }[/math] is the so-called modularity matrix, which has elements

[math]\displaystyle{ B_{vw} = A_{vw} - \frac{k_v k_w}{2m}. }[/math]

All rows and columns of the modularity matrix sum to zero, which means that the modularity of an undivided network is also always [math]\displaystyle{ 0 }[/math].

For networks divided into just two communities, one can alternatively define [math]\displaystyle{ s_v = \pm 1 }[/math] to indicate the community to which node [math]\displaystyle{ v }[/math] belongs, which then leads to

[math]\displaystyle{ Q = {1\over 4m} \sum_{vw} B_{vw} s_v s_w = {1\over 4m} \mathbf{s}^\mathrm{T}\mathbf{Bs}, }[/math]

where [math]\displaystyle{ s }[/math] is the column vector with elements [math]\displaystyle{ s_v }[/math].[1]

This function has the same form as the Hamiltonian of an Ising spin glass, a connection that has been exploited to create simple computer algorithms, for instance using simulated annealing, to maximize the modularity. The general form of the modularity for arbitrary numbers of communities is equivalent to a Potts spin glass and similar algorithms can be developed for this case also.[7]

Overfitting

Although the method of modularity maximization is motivated by computing a deviation from a null model, this deviation is not computed in a statistically consistent manner.[8] Because of this, the method notoriously finds high-scoring communities in its own null model [9] (the configuration model), which by definition cannot be statistically significant. Because of this, the method cannot be used to reliably obtain statistically significant community structure in empirical networks.

Resolution limit

Modularity compares the number of edges inside a cluster with the expected number of edges that one would find in the cluster if the network were a random network with the same number of nodes and where each node keeps its degree, but edges are otherwise randomly attached. This random null model implicitly assumes that each node can get attached to any other node of the network. This assumption is however unreasonable if the network is very large, as the horizon of a node includes a small part of the network, ignoring most of it. Moreover, this implies that the expected number of edges between two groups of nodes decreases if the size of the network increases. So, if a network is large enough, the expected number of edges between two groups of nodes in modularity's null model may be smaller than one. If this happens, a single edge between the two clusters would be interpreted by modularity as a sign of a strong correlation between the two clusters, and optimizing modularity would lead to the merging of the two clusters, independently of the clusters' features. So, even weakly interconnected complete graphs, which have the highest possible density of internal edges, and represent the best identifiable communities, would be merged by modularity optimization if the network were sufficiently large.[10] For this reason, optimizing modularity in large networks would fail to resolve small communities, even when they are well defined. This bias is inevitable for methods like modularity optimization, which rely on a global null model.[11]

Multiresolution methods

There are two main approaches which try to solve the resolution limit within the modularity context: the addition of a resistance r to every node, in the form of a self-loop, which increases (r>0) or decreases (r<0) the aversion of nodes to form communities;[12] or the addition of a parameter γ>0 in front of the null-case term in the definition of modularity, which controls the relative importance between internal links of the communities and the null model.[7] Optimizing modularity for values of these parameters in their respective appropriate ranges, it is possible to recover the whole mesoscale of the network, from the macroscale in which all nodes belong to the same community, to the microscale in which every node forms its own community, hence the name multiresolution methods. However, it has been shown that these methods have limitations when communities are very heterogeneous in size.[13]

Software Tools

There are a couple of software tools available that are able to compute clusterings in graphs with good modularity.

Original implementation of the multi-level Louvain method.[14]

The Leiden algorithm which additionally avoids unconnected communities.[15]

The Vienna Graph Clustering (VieClus) algorithm, a parallel memetic algorithm.[16]


See also

References

  1. 1.0 1.1 1.2 1.3 1.4 Newman, M. E. J. (2006). "Modularity and community structure in networks". Proceedings of the National Academy of Sciences of the United States of America 103 (23): 8577–8696. doi:10.1073/pnas.0601602103. PMID 16723398. Bibcode2006PNAS..103.8577N. 
  2. Newman, M. E. J. (2007). "Mathematics of networks". The New Palgrave Encyclopedia of Economics. 
  3. Brandes, U.; Delling, D.; Gaertler, M.; Gorke, R.; Hoefer, M.; Nikoloski, Z.; Wagner, D. (February 2008). "On Modularity Clustering". IEEE Transactions on Knowledge and Data Engineering 20 (2): 172–188. doi:10.1109/TKDE.2007.190689. http://nbn-resolving.de/urn:nbn:de:bsz:352-opus-71790. 
  4. van der Hofstad, Remco (2013). "Chapter 7". Random Graphs and Complex Networks. http://www.win.tue.nl/~rhofstad/NotesRGCN.pdf#page=149. Retrieved 2013-12-08. 
  5. "NetworkScience". Albert-László Barabási. http://networksciencebook.com/. 
  6. Clauset, Aaron and Newman, M. E. J. and Moore, Cristopher (2004). "Finding community structure in very large networks". Phys. Rev. E 70 (6): 066111. doi:10.1103/PhysRevE.70.066111. PMID 15697438. Bibcode2004PhRvE..70f6111C. 
  7. 7.0 7.1 Joerg Reichardt; Stefan Bornholdt (2006). "Statistical mechanics of community detection". Physical Review E 74 (1): 016110. doi:10.1103/PhysRevE.74.016110. PMID 16907154. Bibcode2006PhRvE..74a6110R. 
  8. Peixoto, Tiago P. (2021). "Descriptive vs. inferential community detection: pitfalls, myths and half-truths". arXiv:2112.00183.
  9. Guimera, Roger; Sales-Pardo, Marta (August 19, 2004), "Modularity from fluctuations in random graphs and complex networks", Physical Review 70 (2): 025101, doi:10.1103/PhysRevE.70.025101, PMID 15447530, Bibcode2004PhRvE..70b5101G 
  10. Santo Fortunato; Marc Barthelemy (2007). "Resolution limit in community detection". Proceedings of the National Academy of Sciences of the United States of America 104 (1): 36–41. doi:10.1073/pnas.0605965104. PMID 17190818. Bibcode2007PNAS..104...36F. 
  11. J.M. Kumpula; J. Saramäki; K. Kaski; J. Kertész (2007). "Limited resolution in complex network community detection with Potts model approach". European Physical Journal B 56 (1): 41–45. doi:10.1140/epjb/e2007-00088-4. Bibcode2007EPJB...56...41K. 
  12. Alex Arenas, Alberto Fernández and Sergio Gómez (2008). "Analysis of the structure of complex networks at different resolution levels". New Journal of Physics 10 (5): 053039. doi:10.1088/1367-2630/10/5/053039. Bibcode2008NJPh...10e3039A. 
  13. Andrea Lancichinetti; Santo Fortunato (2011). "Limits of modularity maximization in community detection". Physical Review E 84 (6): 066122. doi:10.1103/PhysRevE.84.066122. PMID 22304170. Bibcode2011PhRvE..84f6122L. 
  14. First implementation of Louvain algorithm, https://sites.google.com/site/findcommunities/, retrieved 2020-11-30 
  15. Leiden algorithm repository, 15 December 2021, https://github.com/vtraag/leidenalg, retrieved 30 November 2020 
  16. Vienna graph clustering repository, 13 April 2021, https://github.com/VieClus/VieClus, retrieved 30 November 2020