Skip to content

Instantly share code, notes, and snippets.

@ofou
Last active June 21, 2019 06:29
Show Gist options
  • Save ofou/b8588c3a88ef4d122bb46841f0f01cd7 to your computer and use it in GitHub Desktop.
Save ofou/b8588c3a88ef4d122bb46841f0f01cd7 to your computer and use it in GitHub Desktop.
Pagerank using iterative method
def pagerank(self):
M = self.google_matrix()
n, m = np.shape(M)
r = np.ones(n) / n
r = np.transpose(r)
iterations = 1
while True:
print("pass: ", iterations)
previous_r = r
r = np.dot(r, M)
err = np.abs(r - previous_r).sum()
if err < 0.000001:
break
iterations += 1
print(iterations)
with np.printoptions(threshold=np.inf, suppress=True):
print(r.transpose())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment