-
-
Save ShaunakInamdar/9a914b43bb778aac04e8f254f3e5329f to your computer and use it in GitHub Desktop.
Here is my implementation for the pagerank pset for cs50 ai
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
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.