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]
@martinferreira
Copy link

martinferreira commented Jul 30, 2019

s = // zero matrix with s[seed] = 1
assuming dimensions same as adjacent matrix

@martinferreira
Copy link

grad = -alpha * D_inv @ s
Result is two dimentional as its matrix * matrix * scalar
So assumig grad[i] means ith item in matrix

@prog-eval
Copy link

@martinferreira --

  • If you're running ISTA for a single seed node, s is a vector of length # of nodes in graph
  • So, grad = -alpha * D_inv @ s is a scalar * matrix * vector product, which makes it a vector

@martinferreira
Copy link

Seems like line 18 should be outside the for loop if you compare it with the alghorithm

@bkj
Copy link
Author

bkj commented Aug 5, 2019

@martinferreira, yes I think that's right, fixed the gist.

@martinferreira
Copy link

(1 / alpha) should be (1 - alpha) took me a while to figure it out. but i did

@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