Created
January 19, 2020 16:29
-
-
Save kevinmartinjos/c78ffad5a13a5119c53361651bd5378d to your computer and use it in GitHub Desktop.
Pagerank - irdm sheet 11 problem 1
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
| import numpy as np | |
| def iterate(alpha, n, P, pi): | |
| e = np.array([[1], [1], [1], [1], [1], [1]]) | |
| return (alpha * e)/n + (1-alpha) * np.matmul(np.transpose(P), pi) | |
| if __name__ == "__main__": | |
| P = np.array([ | |
| [0, 0.5, 0, 0.5, 0, 0], | |
| [0, 0, 0, 0.5, 0, 0.5], | |
| [0, 0.5, 0, 0, 0, 0.5], | |
| [0, 0, 1, 0, 0, 0], | |
| [0, 0.5, 0, 0.5, 0, 0], | |
| [0, 0, 0, 0, 1, 0] | |
| ]) | |
| pi = np.array([[1/6], [1/6], [1/6], [1/6], [1/6], [1/6]]) | |
| alpha = 0.15 | |
| n = 6 | |
| for i in range(5): | |
| pi = iterate(alpha, n, P, pi) | |
| print(pi) | |
| # pi = iterate(alpha, n, P, pi) | |
| # print(pi) | |
| #pi = iterate(alpha, n, P, pi) | |
| #print(pi) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment