Created
December 19, 2020 19:32
-
-
Save parthvshah/9a222f50d4db5127d7e534f46bd7b887 to your computer and use it in GitHub Desktop.
This file contains 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
# cook your dish here | |
graph = { | |
0: [1, 2], | |
1: [2], | |
2: [0], | |
3: [2] | |
} | |
# no of nodes | |
n = 4 | |
init = 1 | |
damp = 0.85 | |
# no of iterations | |
k = 25 | |
ranks = [init for _ in range(n)] | |
# for each iteration | |
for x in range(k): | |
print(x, ":", sep="") | |
for rank in ranks: | |
print(rank, " ", end="") | |
print() | |
# for each node in the network | |
for i in range(n): | |
newRank = 0 | |
for k, v in graph.items(): | |
for node in v: | |
if(node == i): | |
newRank += ranks[k] / len(graph[k]) | |
ranks[i] = (1-damp) + (damp * newRank) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment