MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / page_rank

Function page_rank

graphs/page_rank.py:34–49  ·  view source on GitHub ↗
(nodes, limit=3, d=0.85)

Source from the content-addressed store, hash-verified

32
33
34def page_rank(nodes, limit=3, d=0.85):
35 ranks = {}
36 for node in nodes:
37 ranks[node.name] = 1
38
39 outbounds = {}
40 for node in nodes:
41 outbounds[node.name] = len(node.outbound)
42
43 for i in range(limit):
44 print(f"======= Iteration {i + 1} =======")
45 for _, node in enumerate(nodes):
46 ranks[node.name] = (1 - d) + d * sum(
47 ranks[ib] / outbounds[ib] for ib in node.inbound
48 )
49 print(ranks)
50
51
52def main():

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected