Networkx PageRank - Equal Ranks with Different Weights

时光总嘲笑我的痴心妄想 提交于 2019-12-10 10:54:29

问题


I have a question about PageRank which may show that I don't understand it well. If I have a graph with two nodes "A" and "B" and the link A --> B weights 1.0 and B --> A weight 2.0, shouldn't A rank higher because its in-degree weights higher?

It seems that this is not the case when I try PageRank from networkx but I don't know why.

>>> from networkx import nx 
>>> DG = nx.DiGraph()
>>> DG.add_weighted_edges_from([("A", "B", 1.0),("B", "A",2.0)])
>>> pr = nx.pagerank(DG)
>>> pr
{'A': 0.5, 'B': 0.5}

回答1:


The PageRank of a directed graph can be thought of as the probability distribution over all nodes of where a random surfer will end up after several random hops along directed edges (with random teleportation to address disconnected and dangling nodes). At each hop, the probability of the random surfer following a specific edge is its weight divided by the sum of weights on all edges leaving the current node.

In your example, the random surfer at each node has only 1 link to follow to hop to the other, thus no matter what weights you put on those 2 links, PageRank will always give (0.5,0.5).



来源:https://stackoverflow.com/questions/15962324/networkx-pagerank-equal-ranks-with-different-weights

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