Proofs: Leiden algorithm
These are the human proofs of Leiden algorithm, at full length.
The deterministic Leiden algorithm stops, never lowers modularity, and returns connected communities in which no single vertex gains by moving full
This proof shows: correctness, termination.
The proof is for the deterministic version of the page, with the check of line L18. The stronger guarantees of Traag, Waltman and van Eck (-separation, uniform -density and subset optimality) are not proved here.
Let be an undirected graph on with positive integer weights , where is the weight of the self-loop at , and total weight . For a graph , use the conventions of the Louvain page: counts a self-loop twice, is the weight inside , , and . Every graph that the algorithm builds has .
Three facts come from the proof of the Louvain method: (gain) if is a part of a partition and is another part, merging into changes by , and ; (aggregation) if is built from and a partition as in line L8, then of a partition of the vertices of equals of the matching partition of the vertices of ; (integrality) for integer weights, is an integer and . By the aggregation fact and induction, of the current partition of always equals of the matching partition of .
Lemma 1 (moves raise Q). Each execution of lines L14 to L16 that changes the community of raises of the current partition of by a positive amount.
Proof. Let be the partition with alone. By the gain fact, putting into a community gives , and putting it into an empty community gives . Line L15 leaves only for a choice whose gain is strictly larger than the gain of .
Lemma 2 (local optimality at the end of MOVE-NODES-FAST). When MOVE-NODES-FAST returns, no vertex of has a community of a neighbour, or the empty community, with a gain larger than that of its own community.
Proof. It returns only when line L18 finds no vertex that line L15 would move, and line L15 would move exactly when such a exists.
Lemma 3 (termination of the moves). In the whole run there are fewer than moves.
Proof. Lines L7 to L9 and the start of a pass do not change the partition of , and refinement only changes . So by Lemma 1 the integer rises by at least 1 at each move and never falls. It takes fewer than values.
Each call of MOVE-NODES-FAST ends: every pop either moves a vertex, which happens finitely often by Lemma 3, or removes a vertex from ; a vertex enters only after a move (line L17) or at a check that found a vertex to move, and the first vertex that such a check finds moves when it is popped, because nothing changes between the check and that pop.
Lemma 4 (well-connected vertices). Let MOVE-NODES-FAST return and let . Every is well connected in .
Proof. If , both sides of the inequality are 0. Otherwise, by Lemma 2, the gain of staying in is at least the gain 0 of the empty community: . Multiplying by gives , which is the definition.
Lemma 5 (refinement makes progress). If has a community with at least two vertices of , then REFINE merges at least one vertex of into another part.
Proof. By Lemma 4, line L22 gives . Let be the first vertex of in index order. When line L24 reaches it, no vertex of has been touched, so all parts of inside are singletons, and each with is well connected by Lemma 4. Every vertex of has : a vertex of with has no neighbour, so it never joins another community and no vertex joins its community (lines L15 and L25 only offer communities of neighbours, besides the empty one), and so its community is a singleton. By the inequality of Lemma 4 for , , so has a neighbour in and is not empty. Since and are additive in ,
by Lemma 2 again. A term with not adjacent to is , so the terms of the neighbours of in , which are the members of , sum to a non-negative number, and the largest of them is non-negative. Line L27 merges .
Lemma 6 (parts are connected). At every moment, each vertex of stands for a set of vertices of that induces a connected subgraph, and each part of is a set of vertices of whose union is connected in .
Proof. At the start of each pass, and its vertices are single vertices. A part of starts as one vertex of and grows only at line L27, by a vertex of that is adjacent in to the part . An edge of between and a vertex of comes from an edge of between their sets; so if the union for and the set of are connected, so is their union. Line L8 makes each part of a vertex of the next .
Theorem. LEIDEN() stops. It returns a partition of such that
- every community of induces a connected subgraph of ;
- ;
- no vertex of raises by moving into the community of a neighbour or into a community of its own.
Proof. Termination. Each call of MOVE-NODES-FAST ends (above). If line L6 does not exit, some community has two vertices of , so by Lemma 5 the refinement merges something, has fewer parts than has vertices, and the next is smaller. So the loop of lines L4 to L9 runs at most times. A pass that ends with made a move, so by Lemma 3 there are fewer than passes.
Property 1. The pass returns from line L6, when each community of is one vertex of ; by Lemma 6 it is connected in .
Property 2. starts at the singletons and never falls (Lemma 1 and the aggregation fact).
Property 3. In the last pass, equals at the end. Any move in the pass would raise by Lemma 1, and nothing lowers it, so the pass ends with a different partition; hence no move happened. In particular, the first call of MOVE-NODES-FAST, on , made no move and returned , and by Lemma 2 no vertex of has a better community among those of its neighbours and the empty one. By the gain fact, the gain of a move is the change of .
∎