TOPICS
Search

Graph Modularity


Graph modularity assigns a score q_A(G) to a proposed set partition A of the vertex set of a graph G. It is used in community detection to measure how strongly the graph can be divided into communities. The maximum modularity of G, also called the modularity of G, is the maximum of this score over all vertex partitions. A graph community is a group of vertices that are more strongly connected to one another than expected under a specified comparison model. Let G be a graph with m>0 edges, and let A be a set partition of its vertex set. For a part A, let e(A) be the number of edges with both endpoints in A, and let vol(A) be the sum of the vertex degrees in A. The modularity score of A and the maximum modularity of G are

q_A(G)=sum_(A in A)((e(A))/m-(vol(A)^2)/(4m^2))
(1)
q^*(G)=max_(A)q_A(G).
(2)

Any set partition A satisfying q_A(G)=q^*(G) is called a maximum-modularity partition. The first term rewards edges lying within parts, while the second subtracts a degree-based null-model expectation (Newman and Girvan 2004). For every nonempty graph, 0<=q^*(G)<1; by convention, an empty graph has modularity zero. In the Wolfram Language, GraphAssortativity[g, partition, "Normalized" -> False] returns q_A(G) for the supplied set partition. This evaluates that set partition only; q^*(G) is the maximum over all partitions.

Let A and B be two parts of a set partition, and let e(A,B) be the number of edges joining them. Merging the two parts changes the modularity score by

 Deltaq_(merge)=(e(A,B))/m-(vol(A)vol(B))/(2m^2).
(3)

The merge improves the score exactly when 2me(A,B)>vol(A)vol(B). Consequently, two distinct parts in a maximum-modularity partition satisfy the reverse weak inequality, while every bipartition A union B of one part satisfies 2me(A,B)>=vol(A)vol(B).

If e(A,B)=0 and both volumes are positive, splitting A union B strictly improves the score. It follows that, after isolated vertices are removed, every part in every maximum-modularity partition induces a connected graph. The merge criterion also shows that no part can consist of a single nonisolated vertex, so every tree leaf belongs to the same part as its unique neighbor. Isolated vertices may be deleted or assigned arbitrarily without changing modularity (Brandes et al. 2008, Meeks and Skerman 2020).

For an exact decomposition, let G_1,...,G_k be the connected components having m_i>0 edges, let a_i=m_i/m, and define the resolution-gamma maximum of a graph H with m_H edges by

 q_gamma^*(H)=max_(P)sum_(A in P)((e_H(A))/(m_H)-gamma(vol_(H)(A)^2)/(4m_H^2)).
(4)

Then the globally normalized component identity is

 q^*(G)=sum_(i=1)^ka_iq_(a_i)^*(G_i).
(5)

Indeed, after isolated vertices are removed, every optimal part lies in one connected component, and its globally normalized contribution is a_i times its resolution-a_i contribution. Thus the modularity of a disconnected graph is not in general a sum, maximum, or weighted mean of the ordinary values q^*(G_i). However, if q^*(G_i)=0 for every edge-bearing connected component, the identity simplifies to

 q^*(G)=1-sum_(i=1)^k((m_i)/m)^2.
(6)

In particular, for n>=1, the n-ladder rung graph nP_2 is the disjoint graph union of n one-edge connected components and therefore has

 q^*(nP_2)=1-1/n.
(7)

Its values are 0, 1/2, 2/3, 3/4, ..., with reduced numerators 0, 1, 2, 3, ... (OEIS A001477) and denominators 1, 2, 3, 4, ... (OEIS A000027).

For the cycle graph C_n with n>=4, a maximum-modularity partition may be chosen to consist of contiguous paths whose sizes differ by at most one (Brandes et al. 2008). Set k=|_(1+sqrt(1+4n))/2_|, s=|_n/k_|, and r=n-ks, where |_x_| is the floor function. Then, for n>=3,

 q^*(C_n)=max{0,1-k/n-((k-r)s^2+r(s+1)^2)/(n^2)}.
(8)

At n=t(t+1) for t>=2, partitions into t and t+1 parts tie. In particular,

 q^*(C_n)=1-2/(sqrt(n))+O(1/n).
(9)

where O denotes big-O notation (McDiarmid and Skerman 2018).

Every complete graph and every complete multipartite graph has modularity zero. McDiarmid and Skerman (2026) proved that, for n>=4, the fewest edges that can be deleted from K_n to obtain positive modularity is |_n/2_|+1, where |_x_| is the floor function. For the binomial random graph G_(n,p) in the very dense regime p=1-Theta(1/n), they found a transition governed by the average vertex degree of the complementary graph. For fixed epsilon>0, q^*(G_(n,p))=0 with high probability when 1-p<=(1-epsilon)/n. At p=1-1/n, the probability of zero modularity is 1/2+o(1), while with probability approaching 1/2 the modularity is positive and of order n^(-3/2). For fixed 1<c_1<c_2, if 1-c_2/n<=p<=1-c_1/n, then q^*(G_(n,p))=Theta(1/n) with high probability.


See also

Community Detection, Complete Graph, Complete Multipartite Graph, Connected Component, Cycle Graph, Graph Assortativity, Graph Community, Graph Complement, Ladder Rung Graph, Random Graph, Set Partition, Vertex Degree

Explore with Wolfram|Alpha

References

Brandes, U.; Delling, D.; Gaertler, M.; Görke, R.; Hoefer, M.; Nikoloski, Z.; and Wagner, D. "On Modularity Clustering." IEEE Trans. Knowl. Data Eng. 20, 172-188, 2008. https://doi.org/10.1109/TKDE.2007.190689.McDiarmid, C. and Skerman, F. "Modularity of Regular and Treelike Graphs." J. Complex Networks 6, 596-619, 2018. https://doi.org/10.1093/comnet/cnx046.McDiarmid, C. and Skerman, F. "On Graphs with Modularity Zero or Near-Zero." Elec. J. Combin. 33, No. 3, P3.51, 1-45, 2026. https://doi.org/10.37236/12644.Meeks, K. and Skerman, F. "The Parameterised Complexity of Computing the Maximum Modularity of a Graph." Algorithmica 82, 2174-2199, 2020. https://doi.org/10.1007/s00453-019-00649-7.Newman, M. E. J. and Girvan, M. "Finding and Evaluating Community Structure in Networks." Phys. Rev. E 69, 026113, 2004. https://doi.org/10.1103/PhysRevE.69.026113.Sloane, N. J. A. Sequences A000027 and A001477 in "The On-Line Encyclopedia of Integer Sequences."

Cite this as:

Weisstein, Eric W. "Graph Modularity." From MathWorld--A Wolfram Resource. https://mathworld.wolfram.com/GraphModularity.html

Subject classifications