特征向量中心性 numpy 的不同结果

Different results in eigenvector centrality numpy

以下示例给出了使用 eigenvector_centralityeigenvector_centrality_numpy 获得的不同结果。有没有办法让这样的计算更健壮?我正在使用 networkx 2.4numpy 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}

edit - 查看 dshult 的回复。他是 maintains/updates networkx.

的主要人物之一

我认为这可能是一个错误,但不是你想的那样。该图是有向的和非循环的。所以对于这张图,我认为不存在非零特征值。

看起来该算法似乎隐含地假设了一个无向图,或者至少如果它是有向的,它就具有循环。如果没有循环,我希望算法会中断。

我将鼓励 networkx 的人更详细地研究这个问题。

我真的很惊讶它收敛于非 numpy 版本。

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