How do weighted edges affect PageRank in networkx?

怎甘沉沦 提交于 2019-11-28 18:01:57

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/9136539/how-do-weighted-edges-affect-pagerank-in-networkx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!