Skip to content

Instantly share code, notes, and snippets.

@bkj
Last active August 9, 2019 13:15
Show Gist options
  • Save bkj/6a7b9db8408d27da255bec6438de655b to your computer and use it in GitHub Desktop.
Save bkj/6a7b9db8408d27da255bec6438de655b to your computer and use it in GitHub Desktop.
// Note: `@` refers to matrix-matrix or matrix-vector multiplication. `*` refers to elementwise multiplication.
degrees = // vector s.t. degree[i] is the degree of the i'th node in graph G
D = // diagonal matrix s.t. D[i, i] = degrees[i]
D_inv = // diagonal matrix s.t. D_inv[i, i] = 1 / sqrt(degrees[i])
q = // zero matrix of shape (max_iters, num_nodes)
grad = -alpha * D_inv @ s
while k < max_iters do
for i in num_nodes do
rad = rho * alpha * sqrt(degrees[i])
| q[k,i] - (grad[i] + rad) if q[k,i] - grad[i] >= rad
q[k + 1, i] = | 0 if -rad < q[k,i] - grad[i] < rad
| q[k,i] - (grad[i] - rad) if q[k,i] - grad[i] <= -rad
end for
grad = D_inv @ (D - (1 - alpha) / 2 * (D + A)) @ D_inv @ q[k + 1] - alpha * D_inv @ s
k = k + 1
end while
return sqrt(D) @ q[k]
@W-KE
Copy link

W-KE commented Aug 9, 2019

the last line should be return sqrt(D) @ q[k]

@bkj
Copy link
Author

bkj commented Aug 9, 2019

@martinferreira @W-KE — good catches, updated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment