Proofs: node2vec
These are the human proofs of node2vec, at full length.
node2vec samples the second-order walk exactly and takes gradient steps on the skip-gram loss full
This proof shows: correctness, termination.
We use the notation of the page. is an undirected graph with positive weights , is the set of neighbours of , and . For an edge and let if , if , and otherwise, and .
Lemma 1 (the step distribution is defined). For every edge , the weights for are positive and their sum is positive, so is a probability distribution on .
Proof. Each is one of , and , which are positive, and each , so every . Since , the set is not empty and .
Lemma 2 (exact sampling). Let be the neighbours of with weights and . Drawing uniform in and returning the first with returns with probability .
Proof. The event that is returned is , an interval of length for . These intervals partition .
Lemma 3 (walks). A walk produced by lines L5 to L7 from a vertex is a sequence of vertices in which consecutive vertices are adjacent. If or it is ; otherwise it has exactly vertices. Given its first vertices ending in , the next vertex is with probability , independently of the earlier vertices.
Proof. Line L5 appends a neighbour of when one exists and ; by Lemma 2 with the weights it is chosen in proportion to the weight. If no vertex was appended, the walk has one vertex and the condition of line L6 fails, so the walk is . Otherwise the last two vertices are adjacent, and by Lemma 1 and Lemma 2 line L7 appends a neighbour of with the stated probability, which depends only on and . Then are adjacent, so the invariant "the last two vertices are adjacent" holds again, and each round adds one vertex, so the loop stops when the walk has vertices.
Lemma 4 (reduction to the weighted walk). If , then , the first-order weighted random walk.
Proof. Every equals 1.
Lemma 5 (the update is a gradient step). For a pair with negative samples , let , with . Then
and the analogous formulas hold for each context vector. The implementation adds to for each target with label for and for the samples, which is .
Proof. and ; apply the chain rule with , whose gradient in is . For the label 1 term, ; for a label 0 term, . Negating and scaling by gives and .
Theorem. NODE2VEC stops, and its walks are independent samples of the second-order walk of Grover and Leskovec, from every vertex, each with vertices (or one vertex from an isolated vertex). Its vectors are the result of stochastic gradient steps on the skip-gram loss with negative sampling over the pairs of these walks.
Proof. Lines L3 and L4 run times, each walk has at most vertices by Lemma 3, and line L9 visits each of the at most positions of the walks, with at most context vertices and samples each, a finite number of updates. So the algorithm stops. The walks have the stated distribution by Lemma 3 and use fresh random numbers, so they are independent given the graph. The learning phase consists of the updates of Lemma 5.