Algorithm Search⌘K

Proofs: Louvain method

These are the human proofs of Louvain method, at full length.

The Louvain method raises modularity at every move, stops, and ends at a partition that no single move of the last level improves full

This proof shows: correctness, termination.

Let GG be an undirected graph on VV with non-negative weights Aij=AjiA_{ij} = A_{ji}, where AiiA_{ii} is the weight of the self-loop at ii, and total weight W>0W > 0. For a graph HH with weights BB, use the conventions of the page: kx=∑y≠xBxy+2Bxxk_x = \sum_{y \ne x} B_{xy} + 2 B_{xx}, WH=12∑xkxW_H = \frac12 \sum_x k_x, in(C)=∑{x,y}⊆C,x≠yBxy+∑x∈CBxx\mathrm{in}(C) = \sum_{\{x,y\} \subseteq C, x \ne y} B_{xy} + \sum_{x \in C} B_{xx} and tot(C)=∑x∈Ckx\mathrm{tot}(C) = \sum_{x \in C} k_x, and QH(C)=∑C(in(C)/WH−(tot(C)/2WH)2)Q_H(\mathcal{C}) = \sum_{C} \left( \mathrm{in}(C)/W_H - (\mathrm{tot}(C)/2W_H)^2 \right).

Lemma 1 (the gain formula). Let C\mathcal{C} be a partition of the vertices of HH in which {v}\{v\} is a part, and let D∈CD \in \mathcal{C} with v∉Dv \notin D. Moving vv into DD changes QHQ_H by ΔQ(v,D)=kv,D/WH−tot(D)kv/(2WH2)\Delta Q(v, D) = k_{v,D}/W_H - \mathrm{tot}(D) k_v / (2 W_H^2), where kv,D=∑y∈DBvyk_{v,D} = \sum_{y \in D} B_{vy}. If D=∅D = \emptyset, the change is 0.

Proof. Only the terms of {v}\{v\} and DD change. The new part D∪{v}D \cup \{v\} has in=in(D)+kv,D+Bvv\mathrm{in} = \mathrm{in}(D) + k_{v,D} + B_{vv} and tot=tot(D)+kv\mathrm{tot} = \mathrm{tot}(D) + k_v. The change is

kv,D+BvvWH−(tot(D)+kv)2−tot(D)24WH2−BvvWH+kv24WH2=kv,DWH−2 tot(D)kv4WH2.\frac{k_{v,D} + B_{vv}}{W_H} - \frac{(\mathrm{tot}(D) + k_v)^2 - \mathrm{tot}(D)^2}{4 W_H^2} - \frac{B_{vv}}{W_H} + \frac{k_v^2}{4 W_H^2} = \frac{k_{v,D}}{W_H} - \frac{2\,\mathrm{tot}(D) k_v}{4 W_H^2}.

For D=∅D = \emptyset, moving vv into it changes nothing. □\square

Lemma 2 (each move raises Q). Let lines L7 to L9 take vv from the community oldold to C≠oldC \ne old. Then QHQ_H after the step is larger than before it.

Proof. Line L7 gives the partition C−\mathcal{C}^- in which vv is alone. By Lemma 1, the partition before the step has QH(C−)+ΔQ(v,old∖{v})Q_H(\mathcal{C}^-) + \Delta Q(v, old \setminus \{v\}) and the one after has QH(C−)+ΔQ(v,C)Q_H(\mathcal{C}^-) + \Delta Q(v, C). Line L8 picks C≠oldC \ne old only when ΔQ(v,C)>ΔQ(v,old∖{v})\Delta Q(v, C) > \Delta Q(v, old \setminus \{v\}), since on ties it keeps oldold. □\square

Lemma 3 (aggregation keeps Q). Let H′H' be built from HH and the partition comm\mathrm{comm} by line L13, and let D\mathcal{D} be a partition of the vertices of H′H'. Let D∗\mathcal{D}^\ast be the partition of the vertices of HH that puts xx in the part of D\mathcal{D} that holds the community of xx. Then QH′(D)=QH(D∗)Q_{H'}(\mathcal{D}) = Q_H(\mathcal{D}^\ast).

Proof. The vertex cc of H′H' has a self-loop of weight inH(c)\mathrm{in}_H(c) and an edge of weight ∑x∈c,y∈c′Bxy\sum_{x \in c, y \in c'} B_{xy} to c′c'. So kck_c in H′H' is 2 inH(c)+∑x∈c,y∉cBxy=totH(c)2\,\mathrm{in}_H(c) + \sum_{x \in c, y \notin c} B_{xy} = \mathrm{tot}_H(c), and WH′=WHW_{H'} = W_H. For a part DD of D\mathcal{D}, inH′(D)\mathrm{in}_{H'}(D) adds the self-loops of its vertices and the edges between them, which is the weight of all edges of HH inside D∗D^\ast, so inH′(D)=inH(D∗)\mathrm{in}_{H'}(D) = \mathrm{in}_H(D^\ast), and totH′(D)=totH(D∗)\mathrm{tot}_{H'}(D) = \mathrm{tot}_H(D^\ast). The terms of QQ agree. □\square

By induction over the levels with Lemma 3, starting from H=GH = G and the singletons, the following holds at line L2: each vertex of HH is a part of PP, and for every partition of the vertices of HH, its QHQ_H equals QGQ_G of the matching partition of VV; in particular, the all-singleton partition of HH has QH=QG(P)Q_H = Q_G(P).

Lemma 4 (termination). For integer weights, the run makes fewer than 8W28W^2 moves in all and has at most nn levels.

Proof. For integer weights, 4W2Q=∑C(4W in(C)−tot(C)2)4W^2 Q = \sum_C (4W\,\mathrm{in}(C) - \mathrm{tot}(C)^2) is an integer, and WH=WW_H = W at every level. By Lemma 2 and the invariant, every move raises QGQ_G of the current partition of VV, so it raises 4W2QG4W^2 Q_G by at least 1, and phase 2 does not change it. Since QG≥−∑C(tot(C)/2W)2≥−1Q_G \ge -\sum_C (\mathrm{tot}(C)/2W)^2 \ge -1 and QG<1Q_G < 1, the integer 4W2QG4W^2 Q_G takes fewer than 8W28W^2 values, which bounds the number of moves. For real weights the same holds with "finitely many", because QGQ_G strictly increases and there are finitely many partitions of VV. A sweep without a move ends a level, so each level ends. A level that reaches line L12 made a move, so its final partition of HH has QHQ_H larger than that of the singletons of HH; hence it is not the singleton partition and has fewer parts than HH has vertices. So the number of vertices of HH drops at every level, and there are at most nn levels. □\square

Theorem. LOUVAIN(GG) stops. It returns a partition PP of VV such that QG(P)≥QGQ_G(P) \ge Q_G of every partition reached before, QG(P)≥QG(singletons of V)Q_G(P) \ge Q_G(\text{singletons of } V), and no move of one vertex of the last graph HH (one part of PP) into the community of another part raises QGQ_G.

Proof. Termination is Lemma 4. Q never drops by Lemma 2 and Lemma 3. The method returns at line L11 after a level in which nobody moved; in its last sweep, line L8 kept every vertex vv of HH in its own singleton community, so ΔQ(v,D)≤ΔQ(v,∅)=0\Delta Q(v, D) \le \Delta Q(v, \emptyset) = 0 for every community DD of a neighbour, by Lemma 1 and the tie rule. With the partition of HH into singletons, these are exactly the single moves of a part of PP into a neighbouring part, and by the invariant they do not raise QGQ_G. A move of a part into a part with no edge to it has kv,D=0k_{v,D} = 0, so its gain is at most 0 as well. □\square

∎

Back to Louvain method