Skip to content

Instantly share code, notes, and snippets.

@srolel
Created August 2, 2018 04:18
Show Gist options
  • Save srolel/88a883136e8f5480e4290a80e8fa09bd to your computer and use it in GitHub Desktop.
Save srolel/88a883136e8f5480e4290a80e8fa09bd to your computer and use it in GitHub Desktop.
ranks = [1,1,1,1]
links = [[1], [0], [0,3], [2]]
damping = 1
iterations = 100
for _ in range(0, iterations):
contributions = [0,0,0,0]
for i, page_links in enumerate(links):
for link in page_links:
contributions[link] += ranks[i] / len(page_links)
ranks = [(1 - damping) / len(ranks) + damping * c for c in contributions]
print ('Page ranks after %d iterations: %s' % (iterations, ranks))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment