Proofs: Force-directed layout
These are the human proofs of Force-directed layout, at full length.
Each round of the Fruchterman-Reingold layout is a capped descent step on an energy, and its fixed points are the balanced drawings full
This proof shows: correctness, termination.
Let be an undirected simple graph with vertices, let , and let be a drawing in in which no two vertices share a point. Define
Lemma 1 (the displacement is the force). After lines L3 to L5, for every vertex .
Proof. For and , the gradient of with respect to is . So the gradient with respect to of the edge term is , and that of is . With respect to the signs flip, since changes sign. A pair term depends only on and , so is the sum, over all , of times the unit vector from to , plus the sum, over the neighbours of , of times the same unit vector. Line L4 adds exactly the first sum to , with the pair written in either order, and line L5 adds exactly the second.
Lemma 2 (step length). In line L6 of round , each vertex moves by in the direction of , where ; a vertex with zero force does not move.
Proof. Line L1 sets , and line L7 at the end of round sets , so during round . Line L6 moves by the unit vector of times , and Lemma 1 identifies .
Lemma 3 (fixed points). Let . A round leaves the drawing unchanged if and only if .
Proof. If , every is 0 by Lemma 1 and line L6 moves nothing. If some , Lemma 2 moves by .
Lemma 4 (two balance distances). A single edge with no other vertex is balanced exactly when . A path with at the midpoint of and on the segment between them is balanced exactly when .
Proof. For the edge, the force on along the unit vector from is , which is zero exactly when . For the path, let . By symmetry, the forces on from and from cancel. All forces on lie on the line, and along the unit vector from to they are from , from and from the edge . The sum is zero exactly when , and the case of is the mirror image.
Theorem. FORCE-DIRECTED-LAYOUT stops after rounds. In round every vertex takes a step of length at most along the negative gradient of with respect to its own position, so it ends within distance of its start. A drawing with distinct points is left unchanged by a round with positive temperature exactly when it is a critical point of .
Proof. The loop of line L2 runs times, and each round does a finite amount of work. The step claims are Lemma 2, and the bound on the total distance follows by the triangle inequality. The last claim is Lemma 3.
∎