gpt4 book ai didi

python-3.x - 特征向量中心性numpy的不同结果

转载 作者:行者123 更新时间:2023-12-03 21:12:51 25 4
gpt4 key购买 nike

以下示例给出了使用 eigenvector_centrality 获得的不同结果和 eigenvector_centrality_numpy .有没有办法让这种计算更加健壮?我正在使用 networkx 2.4 , numpy 1.18.5scipy 1.5.0 .

import numpy as np
import networkx as nx

AdjacencyMatrix = {
0: {
1: 0.6,
},
1: {
2: 0,
3: 0,
},
2: {
4: 0.5,
5: 0.5,
},
3: {
6: 0.5,
7: 0.5,
8: 0.5,
},
4: {},
5: {},
6: {},
7: {},
8: {},
}

G = nx.DiGraph()

for nodeID in AdjacencyMatrix.keys():
G.add_node(nodeID)

for k1 in AdjacencyMatrix.keys():
for k2 in AdjacencyMatrix[k1]:
weight = AdjacencyMatrix[k1][k2]
split_factor = len(AdjacencyMatrix[k1])
G.add_edge(k1, k2, weight=weight / split_factor, reciprocal=1.0 / (split_factor * weight) if weight != 0 else np.inf)

eigenvector_centrality = {v[0]: v[1] for v in sorted(nx.eigenvector_centrality(G.reverse() if G.is_directed() else G, max_iter=10000, weight="weight").items(), key=lambda x: x[1], reverse=True)}
print(eigenvector_centrality)

eigenvector_centrality_numpy = {v[0]: v[1] for v in sorted(nx.eigenvector_centrality_numpy(G.reverse() if G.is_directed() else G, max_iter=10000, weight="weight").items(), key=lambda x: x[1], reverse=True)}
print(eigenvector_centrality_numpy)
这是我的输出:
{0: 0.6468489798823026, 3: 0.5392481399595738, 2: 0.5392481399595732, 1: 0.0012439403459275048, 4: 0.0012439403459275048, 5: 0.0012439403459275048, 6: 0.0012439403459275048, 7: 0.0012439403459275048, 8: 0.0012439403459275048}
{3: 0.9637027924175013, 0: 0.0031436862826891288, 6: 9.593026373266866e-11, 8: 3.5132785569658154e-11, 4: 1.2627565659784068e-11, 1: 9.433263632036004e-14, 7: -2.6958851817582286e-11, 5: -3.185304797703736e-11, 2: -0.26695888283266833}

最佳答案

Joel 说 eigenvector_centrality 不是有向无环图的有用度量是正确的。见 this nice description of centrality .这对于代码的 numpy 和非 numpy 版本应该是无用的。

关于python-3.x - 特征向量中心性numpy的不同结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62561548/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com