Last active
June 21, 2019 06:29
-
-
Save ofou/b8588c3a88ef4d122bb46841f0f01cd7 to your computer and use it in GitHub Desktop.
Pagerank using iterative method
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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