Skip to content

Instantly share code, notes, and snippets.

@parthvshah
Created December 19, 2020 19:32
Show Gist options
  • Save parthvshah/9a222f50d4db5127d7e534f46bd7b887 to your computer and use it in GitHub Desktop.
Save parthvshah/9a222f50d4db5127d7e534f46bd7b887 to your computer and use it in GitHub Desktop.
# 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