Search code examples
graphnetworkxpagerankstochastic

Computing a pagerank on a weighted graph with absolute weights


I am facing the same issue as expressed in this link (Networkx PageRank - Equal Ranks with Different Weights).

Essentially, I am using networkx to compute the pagerank on a graph. Since, pagerank computation first converts the graph to a right stochastic matrix (all out-going edges are normalised to one).

What I need is a way to not normalise the edge weights. So, If one node as only one outgoing edge with weight 0.1 and another one has only one outgoing edge with weight 0.05, I want this information to be used in the computation of pagerank (rather than being normalized to 1 each).

Does anyone know what could be the right way of modifying pagerank to achieve this.

thanks in advance, Amit


Solution

  • I have a graph which is not right stochastic (i.e. edge weights are absolute and consistent across nodes). I changed pagerank implementation of networkx to avoid converting initial matrix to a right stochastic matrix thus giving me the right answer. However, this implies that pagerank doesn't converge as sometimes total sum of edges > 1, but usually rankings are fairly consistent after 30-40 iterations.

    In essence, removing this line from the networkx code (algorithms/link_analysis/pagerank_alg.py) did the job:-

    W = x.stochastic_graph(D, weight=weight)