Skip to content

Instantly share code, notes, and snippets.

@ShaunakInamdar
Created May 21, 2020 08:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ShaunakInamdar/9a914b43bb778aac04e8f254f3e5329f to your computer and use it in GitHub Desktop.
Save ShaunakInamdar/9a914b43bb778aac04e8f254f3e5329f to your computer and use it in GitHub Desktop.
Here is my implementation for the pagerank pset for cs50 ai
def sample_pagerank(corpus, damping_factor, n):
for i in corpus:
pageRank[i] = 0
weights = [0]*len(corpus)
count = n
while count != 0:
count -= 1
sample = random.choices(list(corpus),weights)[0]
weights = list(transition_model(corpus,sample,damping_factor).values())
pageRank[sample] = pageRank[sample] + 1
for i in pageRank:
pageRank[i] /= n
return pageRank
@hamadsuniverse
Copy link

Before manipulating pageRank on line 3, you should define it, is it a list (array) or a dict?
Try pageRank = {} to create an empty dictionary before the loop on line 2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment