gpt4 book ai didi

python - 特征向量中心性的快速计算在 networkx 中花费的时间太长

转载 作者:太空宇宙 更新时间:2023-11-03 15:33:13 25 4
gpt4 key购买 nike

我正在使用 networkx 计算特征向量中心性。问题是它花费的时间太长(已经运行了大约 6 个小时)。有没有更快的方法得到结果?

图中有大约 200,000 个节点和 60,000,000 条边。

最佳答案

通过查看源代码,networkx.algorithms.centrality.eigenvector 使用幂法求主特征向量。

如果您坚持使用 networkx,请像 Joel 注意到的那样使用它:

eigenvector_centrality_numpy

centrality = nx.eigenvector_centrality_numpy(G)

或者:

您可以使用使用 ARPACK 的 scipy.sparse.linalg.eigs 并请求仅返回 1 个特征向量。

玩具示例:

import scipy.sparse as sparse

X = np.array() # dimensions 200000 by 200000 as the adjacency
# Note: k=1 and you request the Largest real.
vals, vecs = sparse.linalg.eigs(X, k=1, which='LR')

在任何情况下,2000000 x 200000 都很大,根据矩阵的稀疏性和性质,算法可能需要很长时间。您还需要大量的 CPU 和 RAM。

networkx.algorithms.centrality.eigenvector 的额外提示:

如果您坚持使用 networkx,请尝试放宽公差:

eigenvector_centrality(G, max_iter=100, tol=1e-06, nstart=None, weight=None)

尝试设置 tol=1e-04 甚至 tol=1e-03

关于python - 特征向量中心性的快速计算在 networkx 中花费的时间太长,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56707517/

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