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 be an undirected graph on with non-negative weights , where is the weight of the self-loop at , and total weight . For a graph with weights , use the conventions of the page: , , and , and .
Lemma 1 (the gain formula). Let be a partition of the vertices of in which is a part, and let with . Moving into changes by , where . If , the change is 0.
Proof. Only the terms of and change. The new part has and . The change is
For , moving into it changes nothing.
Lemma 2 (each move raises Q). Let lines L7 to L9 take from the community to . Then after the step is larger than before it.
Proof. Line L7 gives the partition in which is alone. By Lemma 1, the partition before the step has and the one after has . Line L8 picks only when , since on ties it keeps .
Lemma 3 (aggregation keeps Q). Let be built from and the partition by line L13, and let be a partition of the vertices of . Let be the partition of the vertices of that puts in the part of that holds the community of . Then .
Proof. The vertex of has a self-loop of weight and an edge of weight to . So in is , and . For a part of , adds the self-loops of its vertices and the edges between them, which is the weight of all edges of inside , so , and . The terms of agree.
By induction over the levels with Lemma 3, starting from and the singletons, the following holds at line L2: each vertex of is a part of , and for every partition of the vertices of , its equals of the matching partition of ; in particular, the all-singleton partition of has .
Lemma 4 (termination). For integer weights, the run makes fewer than moves in all and has at most levels.
Proof. For integer weights, is an integer, and at every level. By Lemma 2 and the invariant, every move raises of the current partition of , so it raises by at least 1, and phase 2 does not change it. Since and , the integer takes fewer than values, which bounds the number of moves. For real weights the same holds with "finitely many", because strictly increases and there are finitely many partitions of . 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 has larger than that of the singletons of ; hence it is not the singleton partition and has fewer parts than has vertices. So the number of vertices of drops at every level, and there are at most levels.
Theorem. LOUVAIN() stops. It returns a partition of such that of every partition reached before, , and no move of one vertex of the last graph (one part of ) into the community of another part raises .
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 of in its own singleton community, so for every community of a neighbour, by Lemma 1 and the tie rule. With the partition of into singletons, these are exactly the single moves of a part of into a neighbouring part, and by the invariant they do not raise . A move of a part into a part with no edge to it has , so its gain is at most 0 as well.
∎