Advertisement
Guy_Lalonde

compute_ranks v.2

Jul 7th, 2014
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. def compute_ranks(graph):
  2. d = 0.8 # damping factor
  3. numloops = 10
  4.  
  5. ranks = {}
  6. npages = len(graph)
  7. for page in graph:
  8. ranks[page] = 1.0 / npages
  9. print 'ranks', ranks
  10.  
  11. for i in range(0, numloops):
  12. newranks = {}
  13. for page in graph:
  14. newrank = (1 - d) / npages
  15. for key in graph:
  16. stash = 0
  17. if page in graph[key]:
  18. stash = stash +(d*ranks[page])/len (graph[key])
  19. newrank= newrank + stash
  20.  
  21. newranks[page] = newrank
  22. ranks = newranks
  23. print 'newranks', newranks
  24. return ranks
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement