In order to implement the PageRank algorithm, we need to agree on a graphical representation. In order to avoid introducing other dependencies, we will use a simple representation via dictionaries. Each node in the graph will have a key in the dictionary. The associated value contains another dictionary whose keys are the linked nodes from the key. The graph we are studying in this section is written as follows:
G = {
'A': {'B': 1, 'D': 1},
'B': {'A': 1},
'C': {'B': 1},
'D': {'B': 1},
}
The page_rank function we are going to write has the following parameters:
- G, the graph for which the algorithm will compute the PageRank.
- d, the damping factor whose default value is 0.85.
- tolerance, the tolerance to stop the iteration when the algorithm has converged. We will set a default value of 0.01.
- max_iterations, a sanity check to make sure...