中心和权威评分:networkx与igraph

2024-06-23 19:34:24 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用igraph和networkx计算了一个简单图的hub和authority分数,它们给出了相同的结果。例如,请参见下文

import networkx as nx
from igraph import *
G = nx.DiGraph() 
G.add_edges_from([('A', 'D'), ('B', 'C'), ('B', 'E'), ('C', 'A'), 
                  ('D', 'C'), ('E', 'D'), ('E', 'B'), ('E', 'F'), 
                  ('E', 'C'), ('F', 'C'), ('F', 'H'), ('G', 'A'),  
                  ('G', 'C'), ('H', 'A')]) 
hubs, authorities = nx.hits(G, max_iter = 50, normalized = True) 
edges = [('A', 'D'), ('B', 'C'), ('B', 'E'), ('C', 'A'), 
                  ('D', 'C'), ('E', 'D'), ('E', 'B'), ('E', 'F'), 
                  ('E', 'C'), ('F', 'C'), ('F', 'H'), ('G', 'A'),  
                  ('G', 'C'), ('H', 'A')]
g = Graph.TupleList(directed=True,edges=edges)
hub_igraph = [g.hub_score()[i]/sum(g.hub_score()) for i in range(len(g.hub_score()))]
In[1] print(hubs)
Out[1]
{'A': 0.04642540386472174,
 'D': 0.133660375232863,
 'B': 0.15763599440595596,
 'C': 0.037389132480584515,
 'E': 0.2588144594158868,
 'F': 0.15763599440595596,
 'H': 0.037389132480584515,
 'G': 0.17104950771344754}
In[2] print(hub_igraph)
Out[2] 
[0.04642540403219994,
 0.13366037526115376,
 0.1576359944296732,
 0.03738913224642651,
 0.2588144598468665,
 0.1576359944296732,
 0.037389132246426524,
 0.17104950750758036]

然而,对于稀疏且几乎像树一样的大型图(2k节点),结果却大不相同。我使用HITS算法计算了hub/authority分数,大图的输出与networkx中的匹配,但与igraph中的不匹配。我找不到igraph的源代码,因此我想知道差异来自哪里

任何暗示都将不胜感激。谢谢


Tags: infromimportnetworkxtrueout分数hub

热门问题