I'm playing around with networkx (graph library in python) and I found documentation saying the PageRank algorithm takes edge weights into account when scoring, but I was wondering if larger edge weights were better or lower weights better?
Asked
Active
Viewed 1.9k times
1 Answers
33
Shortly, large weights are better for incoming nodes.
PageRank works on a directed weighted graph. If page A has a link to page B, then the score for B goes up, i.e. the more input the page B (node) have, the higher is its score.
Wikipedia article on PageRank for further details.
Edit: let's make an experiment. Create a directed graph with 3 nodes and two directed edges with equal weights.
import networkx as nx
D=nx.DiGraph()
D.add_weighted_edges_from([('A','B',0.5),('A','C',0.5)])
print nx.pagerank(D)
>> {'A': 0.259740259292235, 'C': 0.3701298703538825, 'B': 0.3701298703538825}
Now, increase the weight of the (A,C) edge:
D['A']['C']['weight']=1
print nx.pagerank(D)
>> {'A': 0.259740259292235, 'C': 0.40692640737443164, 'B': 0.3333333333333333}
As you see, the node C got higher score with increasing weight of the incoming edge.

Max Li
- 5,069
- 3
- 23
- 35
-
2I'm not sure "PageRank works on a directed weighted graph" is correct. It is my understanding that ordinarily the edges used in PageRank are not weighted, there is either an edge between nodes or there isn't. This makes sense because you can't have half a link between two pages. Although it appears that the pagerank method in networkx does allow for edges to be weighted, like they can be using [TextRank](http://digital.library.unt.edu/ark:/67531/metadc30962/m2/1/high_res_d/Mihalcea-2004-TextRank-Bringing_Order_into_Texts.pdf) (section 2.2), which is based on PageRank. – jksnw Mar 28 '15 at 17:54
-
Why would you assign a link more weight? Is it left up to the implementation to figure out how certain links are worth more? (Like links in the body vs links in the comments?) – Xeoncross Oct 24 '16 at 17:13
-
1@Xeoncross, one use-case for weighted links would be when handling whole sites rather than single pages - in that case the weight would be the number of links from one site to another. Another example would be of analysing a social network, where the weight could be proportional to the number of messages Alice sent to Bob. – yoniLavi Oct 11 '19 at 22:03