Algorithm Search⌘K

Proofs: Walktrap algorithm

These are the human proofs of Walktrap algorithm, at full length.

Walktrap merges by the least increase of sigma and ends with one community per component full

This proof shows: correctness, termination.

We use the notation of the page. After line L1, AA is symmetric with positive diagonal, d(k)>0d(k) > 0 for every kk, and P=D−1AP = D^{-1} A. Let vi=D−1/2Pi⋅t∈Rnv_i = D^{-1/2} P^t_{i\cdot} \in \mathbb{R}^n, and for a set CC let vˉC=1∣C∣∑i∈Cvi\bar v_C = \frac{1}{|C|} \sum_{i \in C} v_i. Then D−1/2PC⋅t=vˉCD^{-1/2} P^t_{C\cdot} = \bar v_C by linearity, so rC1C2=∥vˉC1−vˉC2∥r_{C_1 C_2} = \|\bar v_{C_1} - \bar v_{C_2}\| and riC=∥vi−vˉC∥r_{iC} = \|v_i - \bar v_C\|. For a set CC write W(C)=∑i∈C∥vi−vˉC∥2W(C) = \sum_{i \in C} \|v_i - \bar v_C\|^2, so that σ(P)=1n∑C∈PW(C)\sigma(\mathcal{P}) = \frac{1}{n} \sum_{C \in \mathcal{P}} W(C).

Lemma 1 (Ward's identity). For disjoint non-empty sets C1,C2C_1, C_2, W(C1∪C2)−W(C1)−W(C2)=∣C1∣ ∣C2∣∣C1∣+∣C2∣∥vˉC1−vˉC2∥2W(C_1 \cup C_2) - W(C_1) - W(C_2) = \frac{|C_1|\,|C_2|}{|C_1| + |C_2|} \|\bar v_{C_1} - \bar v_{C_2}\|^2.

Proof. For any set CC and any point xx, ∑i∈C∥vi−x∥2=W(C)+∣C∣ ∥vˉC−x∥2\sum_{i \in C} \|v_i - x\|^2 = W(C) + |C|\, \|\bar v_C - x\|^2, because the cross term 2∑i∈C(vi−vˉC)⋅(vˉC−x)2 \sum_{i \in C} (v_i - \bar v_C) \cdot (\bar v_C - x) is 0. Let C=C1∪C2C = C_1 \cup C_2, s1=∣C1∣s_1 = |C_1|, s2=∣C2∣s_2 = |C_2|, and μ=vˉC=(s1vˉC1+s2vˉC2)/(s1+s2)\mu = \bar v_C = (s_1 \bar v_{C_1} + s_2 \bar v_{C_2}) / (s_1 + s_2). Splitting the sum over CC and applying the identity to C1C_1 and to C2C_2 with x=μx = \mu gives W(C)=W(C1)+s1∥vˉC1−μ∥2+W(C2)+s2∥vˉC2−μ∥2W(C) = W(C_1) + s_1 \|\bar v_{C_1} - \mu\|^2 + W(C_2) + s_2 \|\bar v_{C_2} - \mu\|^2. Now vˉC1−μ=s2s1+s2(vˉC1−vˉC2)\bar v_{C_1} - \mu = \frac{s_2}{s_1 + s_2} (\bar v_{C_1} - \bar v_{C_2}) and vˉC2−μ=−s1s1+s2(vˉC1−vˉC2)\bar v_{C_2} - \mu = -\frac{s_1}{s_1 + s_2} (\bar v_{C_1} - \bar v_{C_2}), so the two extra terms add to s1s22+s2s12(s1+s2)2∥vˉC1−vˉC2∥2=s1s2s1+s2∥vˉC1−vˉC2∥2\frac{s_1 s_2^2 + s_2 s_1^2}{(s_1 + s_2)^2} \|\bar v_{C_1} - \bar v_{C_2}\|^2 = \frac{s_1 s_2}{s_1 + s_2} \|\bar v_{C_1} - \bar v_{C_2}\|^2. □\square

So merging C1C_1 and C2C_2 changes σ\sigma by exactly Δσ(C1,C2)=1n∣C1∣∣C2∣∣C1∣+∣C2∣rC1C22\Delta\sigma(C_1, C_2) = \frac{1}{n} \frac{|C_1||C_2|}{|C_1| + |C_2|} r_{C_1 C_2}^2, since the other communities are unchanged.

Call two disjoint sets adjacent if some edge of GG (not a loop) joins them.

Lemma 2 (invariants). Before each test of line L5: (a) the current communities partition VV; (b) each community CC has stored vector vˉC\bar v_C; (c) the table holds an entry for a pair of current communities exactly when they are adjacent, and the entry equals Δσ\Delta\sigma of the pair; (d) each community induces a connected subgraph of GG.

Proof. Initially (lines L2 and L3) the communities are the singletons, with vˉ{i}=vi\bar v_{\{i\}} = v_i; the pairs in the table are the edges, with value 1n⋅1⋅12∥vi−vj∥2\frac{1}{n} \cdot \frac{1 \cdot 1}{2} \|v_i - v_j\|^2, which is Δσ\Delta\sigma; and singletons are connected. Suppose the invariants hold and lines L6 to L8 merge C1C_1 and C2C_2, which are adjacent by (c). (a) The new set of communities is again a partition. (b) Line L7 sets the vector of C3C_3 to ∣C1∣vˉC1+∣C2∣vˉC2∣C1∣+∣C2∣=vˉC3\frac{|C_1| \bar v_{C_1} + |C_2| \bar v_{C_2}}{|C_1| + |C_2|} = \bar v_{C_3}, and the other vectors are unchanged. (c) The entries with C1C_1 or C2C_2 are removed. A community C≠C3C \ne C_3 is adjacent to C3C_3 exactly when it is adjacent to C1C_1 or to C2C_2, and line L8 adds an entry for each such CC, with value Δσ(C,C3)\Delta\sigma(C, C_3) by (b). Entries between two other communities are unchanged and still correct, as their communities and vectors did not change. (d) C1C_1 and C2C_2 are connected and joined by an edge, so their union is connected. □\square

Lemma 3 (termination). The loop of lines L5 to L9 runs at most n−1n - 1 times, and when it stops, the communities are exactly the connected components of GG.

Proof. Each round reduces the number of communities by one, and there is at least one community while n≥1n \ge 1, so there are at most n−1n - 1 rounds. When the loop stops, no two communities are adjacent. By Lemma 2(d) each community lies inside one component. If a component contained two communities, then, the component being connected, some edge would join two different communities inside it, and they would be adjacent, a contradiction. □\square

Theorem. WALKTRAP(G,t)(G, t) stops. Each merge it performs joins the pair of adjacent communities whose union increases σ\sigma the least (the smallest pair of ids among equal increases), and the dendrogram ends with one community per connected component. The returned partition is the one of largest modularity among the partitions of the dendrogram, the earliest among equal ones.

Proof. Termination and the final partition are Lemma 3. By Lemma 2(c) the table at line L6 holds the value Δσ\Delta\sigma for exactly the adjacent pairs, and by Lemma 1 this value is the increase of σ\sigma caused by the merge, so line L6 picks the pair with the least increase, with the stated tie rule. Line L9 records every partition of the dendrogram, and line L10 scans them in order and keeps the first maximum of modularity. ■\blacksquare

Back to Walktrap algorithm