Algorithm Search⌘K

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 (γ\gamma-separation, uniform γ\gamma-density and subset optimality) are not proved here.

Let GG be an undirected graph on VV with positive integer 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, use the conventions of the Louvain page: kxk_x counts a self-loop twice, in(C)\mathrm{in}(C) is the weight inside CC, tot(C)=∑x∈Ckx\mathrm{tot}(C) = \sum_{x \in C} k_x, and QH(C)=∑C(in(C)/W−(tot(C)/2W)2)Q_H(\mathcal{C}) = \sum_C (\mathrm{in}(C)/W - (\mathrm{tot}(C)/2W)^2). Every graph HH that the algorithm builds has WH=WW_H = W.

Three facts come from the proof of the Louvain method: (gain) if {v}\{v\} is a part of a partition and DD is another part, merging vv into DD changes QHQ_H by ΔQ(v,D)=kv,D/W−tot(D)kv/(2W2)\Delta Q(v, D) = k_{v,D}/W - \mathrm{tot}(D) k_v/(2W^2), and ΔQ(v,∅)=0\Delta Q(v, \emptyset) = 0; (aggregation) if H′H' is built from HH and a partition RR as in line L8, then QH′Q_{H'} of a partition of the vertices of H′H' equals QHQ_H of the matching partition of the vertices of HH; (integrality) for integer weights, 4W2Q4W^2 Q is an integer and −1≤Q<1-1 \le Q < 1. By the aggregation fact and induction, QHQ_H of the current partition PP of HH always equals QGQ_G of the matching partition of VV.

Lemma 1 (moves raise Q). Each execution of lines L14 to L16 that changes the community of vv raises QGQ_G of the current partition of VV by a positive amount.

Proof. Let C−\mathcal{C}^- be the partition with vv alone. By the gain fact, putting vv into a community DD gives QH(C−)+ΔQ(v,D)Q_H(\mathcal{C}^-) + \Delta Q(v, D), and putting it into an empty community gives QH(C−)Q_H(\mathcal{C}^-). Line L15 leaves oldold only for a choice whose gain is strictly larger than the gain of oldold. □\square

Lemma 2 (local optimality at the end of MOVE-NODES-FAST). When MOVE-NODES-FAST returns, no vertex vv of HH has a community DD 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 vv exactly when such a DD exists. □\square

Lemma 3 (termination of the moves). In the whole run there are fewer than 8W28W^2 moves.

Proof. Lines L7 to L9 and the start of a pass do not change the partition of VV, and refinement only changes RR. So by Lemma 1 the integer 4W2QG4W^2 Q_G rises by at least 1 at each move and never falls. It takes fewer than 8W28W^2 values. □\square

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 QQ; a vertex enters QQ 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 PP and let C∈PC \in P. Every v∈Cv \in C is well connected in CC.

Proof. If C={v}C = \{v\}, both sides of the inequality are 0. Otherwise, by Lemma 2, the gain of staying in CC is at least the gain 0 of the empty community: kv,C∖v/W−(tot(C)−kv)kv/(2W2)≥0k_{v, C \setminus v}/W - (\mathrm{tot}(C) - k_v) k_v/(2W^2) \ge 0. Multiplying by WW gives E({v},C∖{v})≥kv(tot(C)−kv)/2WE(\{v\}, C \setminus \{v\}) \ge k_v (\mathrm{tot}(C) - k_v)/2W, which is the definition. □\square

Lemma 5 (refinement makes progress). If PP has a community CC with at least two vertices of HH, then REFINE merges at least one vertex of CC into another part.

Proof. By Lemma 4, line L22 gives A=CA = C. Let vv be the first vertex of CC in index order. When line L24 reaches it, no vertex of CC has been touched, so all parts of RR inside CC are singletons, and each {u}\{u\} with u∈Cu \in C is well connected by Lemma 4. Every vertex xx of CC has kx>0k_x > 0: a vertex of HH with kx=0k_x = 0 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 vv, kv,C∖v≥kv(tot(C)−kv)/2W>0k_{v, C \setminus v} \ge k_v (\mathrm{tot}(C) - k_v)/2W > 0, so vv has a neighbour in CC and TT is not empty. Since kv,Dk_{v,D} and tot(D)\mathrm{tot}(D) are additive in DD,

∑u∈C∖vΔQ(v,{u})=ΔQ(v,C∖{v})≥0\sum_{u \in C \setminus v} \Delta Q(v, \{u\}) = \Delta Q(v, C \setminus \{v\}) \ge 0

by Lemma 2 again. A term with uu not adjacent to vv is −kukv/(2W2)<0-k_u k_v/(2W^2) < 0, so the terms of the neighbours of vv in CC, which are the members of TT, sum to a non-negative number, and the largest of them is non-negative. Line L27 merges vv. □\square

Lemma 6 (parts are connected). At every moment, each vertex of HH stands for a set of vertices of GG that induces a connected subgraph, and each part of RR is a set of vertices of HH whose union is connected in GG.

Proof. At the start of each pass, H=GH = G and its vertices are single vertices. A part of RR starts as one vertex of HH and grows only at line L27, by a vertex vv of HH that is adjacent in HH to the part SS. An edge of HH between vv and a vertex of SS comes from an edge of GG between their sets; so if the union for SS and the set of vv are connected, so is their union. Line L8 makes each part of RR a vertex of the next HH. □\square

Theorem. LEIDEN(GG) stops. It returns a partition PP of VV such that

  1. every community of PP induces a connected subgraph of GG;
  2. QG(P)≥QG(singletons of V)Q_G(P) \ge Q_G(\text{singletons of } V);
  3. no vertex of GG raises QGQ_G 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 HH, so by Lemma 5 the refinement merges something, RR has fewer parts than HH has vertices, and the next HH is smaller. So the loop of lines L4 to L9 runs at most nn times. A pass that ends with P≠PoldP \ne P_{old} made a move, so by Lemma 3 there are fewer than 8W2+18W^2 + 1 passes.

Property 1. The pass returns from line L6, when each community of PP is one vertex of HH; by Lemma 6 it is connected in GG.

Property 2. QGQ_G starts at the singletons and never falls (Lemma 1 and the aggregation fact).

Property 3. In the last pass, PP equals PoldP_{old} at the end. Any move in the pass would raise QGQ_G 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 H=GH = G, made no move and returned PoldP_{old}, and by Lemma 2 no vertex of GG 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 QGQ_G. □\square

∎

Back to Leiden algorithm