如何为整个网络的特征向量集中创建 networkx 函数? (弗里曼)

How do you create a networkx function for eigenvector centralization for a whole network? (Freeman)

问题是:如何使用 networkx 计算图形的特征​​向量集中度?

(例如,不是针对单个节点,而是针对比较节点的整个图,使用 Freeman 的方法来执行此操作)。

我需要比较一些不同的图表,我希望使用四种不同的中心性度量来比较它们:

目前 networkx 没有任何计算整个网络集中度的函数 - 所有函数 return 每个节点的中心度字典。

请注意,中心化是关于中心性在网络中的分布。

我已经编写了一个函数,可以计算其中前三个的整个网络的中心性,但我不知道如何计算特征向量中心性。

理论上它应该是总和(最大中心性 - 每个节点的中心性)除以大小为 n 的网络的理论最大值。

我最接近弄清楚如何为特征向量中心性做到这一点的是在 this set of lecture notes 的幻灯片 32 上看到这个理论,看起来像这样:

Ce<-function(Y)
{
    n<-nrow(Y)
    e<-evecc(Y)
    Y.sgn<-matrix(0,n,n) ; Y.sgn[1,-1]<-1 ; Y.sgn<-Y.sgn+t(Y.sgn)
    e.sgn<-evecc(Y.sgn)
    sum(max(e)-e)/ sum(max(e.sgn)-e.sgn)
}

这似乎是(最大特征中心性减去每个节点特征中心性)除以一些没有意义的东西的总和 - 这是我无法计算的分母。

到目前为止,我在 python 中的代码说明了其他三种类型,但我不知道这段代码在做什么(上面)。指出了我无法弄清楚的代码部分。非常感谢大家的帮助。

def getCentrality(centrality, c_type):

    c_denominator = float(1)

    n_val = float(len(centrality))

    print (str(len(centrality)) + "," +  c_type + "\n")

    if (c_type=="degree"):
        c_denominator = (n_val-1)*(n_val-2)

    if (c_type=="close"):
        c_top = (n_val-1)*(n_val-2)
        c_bottom = (2*n_val)-3  
        c_denominator = float(c_top/c_bottom)

    if (c_type=="between"):
        c_denominator = (n_val*n_val*(n_val-2))
    if (c_type=="eigen"):
        c_denominator = [THIS PART I CAN'T FIGURE OUT]




    c_node_max = max(centrality.values())


    c_sorted = sorted(centrality.values(),reverse=True)

    print "max node" + str(c_node_max) + "\n"

    c_numerator = 0

    for value in c_sorted:

        if c_type == "degree":
            #remove normalisation for each value
            c_numerator += (c_node_max*(n_val-1) - value*(n_val-1))
        else:
            c_numerator += (c_node_max - value)

    print ('numerator:' + str(c_numerator)  + "\n") 
    print ('denominator:' + str(c_denominator)  + "\n") 

    network_centrality = float(c_numerator/c_denominator)

    if c_type == "between":
        network_centrality = network_centrality * 2

    return network_centrality

(请注意,将这些值输入此函数时,不应将紧密度和介数归一化)

更新:根据答案,代码已完成并发布为 gist function 供其他人使用

需要说明的是,您正在寻找(我认为)网络的特征向量中心化Centrality 是一个节点级索引,仅针对网络节点定义(考虑到它们所测量的内容,这是有道理的)。 (我记得,弗里曼称集中化 "graph centrality",但术语 "centralization" 已被替换,因此评论中可能会出现混淆。)

特征向量集中的理论最大值是相同大小的网络,两个节点之间只有一条边。在有向网络的情况下,这是 n - 1。在无向网络的情况下,是sqrt(2)/2 * (n - 2)。 (参见 Butts, 2016, pg. 56

考虑到这一点:

from math import sqrt
if (c_type=="eigen"):
    c_denominator = sqrt(2)/2 * (n_val - 2)

或:

if (c_type=="eigen"):
    c_denominator = n_val - 1