提问人:Utkarsh Saboo 提问时间:8/28/2018 更新时间:12/22/2018 访问量:2091
学位、接近度和等级声望
Degree, Proximity and Rank Prestige
问:
我想使用 python 为现有图找到这三个声望度量:
- 学位声望
- 邻近声望
- 等级声望
我可以将 networkx 用于此目的吗?如果没有,那么我可以使用哪个库以及如何操作。任何链接或参考资料都是值得赞赏的。
答:
1赞
abc
8/29/2018
#1
是的,据我所知,你可以自己实施这些措施。
例如,考虑度声望,定义为节点的传入链接数除以可能的传入链接总数。
在这种情况下,您可以将其计算为:
n_nodes = 10
d = nx.gnp_random_graph(n_nodes, 0.5, directed=True)
degree_prestige = dict((v,len(d.in_edges(v))/(n_nodes-1)) for v in d.nodes_iter())
其他措施也是如此,这些措施可以使用 networkx 定义的函数轻松实现。
0赞
Utkarsh Saboo
12/22/2018
#2
n_nodes = 5
d = nx.gnp_random_graph(n_nodes, 0.5, directed=True)
degree_prestige = dict((v,len(d.in_edges(v))/(n_nodes-1)) for v in d.nodes())
print("DEGREE PRESTIGE :\n")
for i in degree_prestige:
print(i, " : ", degree_prestige[i])
distance = []
temp_dis = 0
n = 0
for dest in d.nodes:
temp_dis = 0
n = 0
for src in d.nodes:
if (nx.has_path(d,src,dest) == True):
temp_dis = temp_dis + nx.shortest_path_length(d,source = src,target = dest)
n = n + 1
if temp_dis == 0:
distance.append([dest, 0])
else:
distance.append([dest, temp_dis/(n - 1)])
print("\nPROXIMITY PRESTIGE :\n")
for i in distance:
print(str(i[0]) + " : " + str(i[1]))
prominance = np.random.randint(1, 4, size=n_nodes)
print("\nASSUME PROMINANCE :\n")
print(prominance)
rank_prestige = np.zeros([n_nodes], dtype = int)
path_matrix = np.zeros([n_nodes, n_nodes], dtype = int)
i = 0
j = 0
for src in d.nodes:
for dest in d.nodes:
if d.has_edge(dest, src):
path_matrix[i][j] = 1
j = j+1
j = 0
i = i+1
for i in range(n_nodes):
pr_i = 0
for j in range(n_nodes):
pr_i = pr_i + path_matrix[i][j] * prominance[j]
rank_prestige[i] = pr_i
print("\nRANK PRESTIGE :\n")
print(rank_prestige)
评论