📜  度中心性(中心性度量)

📅  最后修改于: 2022-05-13 01:54:45.954000             🧑  作者: Mango

度中心性(中心性度量)

程度
在图论中,图的顶点的度数(或效价)是入射到顶点的边数,循环计数两次。 [1]顶点的度数 v表示 \deg(v)或者 \deg v .图 G 的最大度数,记为\Delta (G),以及图的最小度,表示为\delta (G), 是其顶点的最大和最小度数。在右图中,最大度数为5,最小度数为0。在正则图中,所有度数都相同,因此我们可以说图的度数。

度中心性
历史上第一个也是概念上最简单的是度中心性,它被定义为一个节点上的链接数(即,一个节点具有的关系数)。该程度可以根据节点捕获流经网络的任何内容(例如病毒或某些信息)的直接风险来解释。在有向网络的情况下(关系有方向),我们通常定义两个独立的度中心性度量,即入度和出度。因此,入度是指向该节点的关联数的计数,而出度是该节点指向其他节点的关联数。当关系与友谊或合作等积极方面相关联时,入度通常被解释为一种受欢迎的形式,而出度通常被解释为合群。

顶点的度中心性v , 对于给定的图G:=(V,E)|V| 顶点和|E|边,定义为

C_{D}(v)=\deg(v)
计算图中所有节点的度中心性需要\Theta(V^2)在图的密集邻接矩阵表示中,对于边采用\Theta(E)在稀疏矩阵表示中。

节点级别的中心性定义可以扩展到整个图,在这种情况下,我们说的是图中心化。让v*成为中心度最高的节点G .让X:=(Y,Z)成为|Y|使以下数量最大化的节点连通图(与y*是中心度最高的节点X ):

H=\sum _{{j=1}}^{{|Y|}}[C_{D}(y*)-C_{D}(y_{j})]
相应地,图的集中度G如下:

C_D(G)= \frac{\displaystyle{\sum^{|V|}_{i=1}{[C_D(v*)-C_D(v_i)]}}}{H}
的价值H当图形最大化时X包含一个所有其他节点都连接到的中心节点(星形图),在这种情况下

{H=(n-1)\cdot ((n-1)-1)=n^{2}-3n+2} .

以下是计算图及其各个节点的度中心性的代码。

import networkx as nx
  
def degree_centrality(G, nodes):
    r"""Compute the degree centrality for nodes in a bipartite network.
  
    The degree centrality for a node `v` is the fraction of nodes 
    connected to it.
  
    Parameters
    ----------
    G : graph
       A bipartite network
  
    nodes : list or container
      Container with all nodes in one bipartite node set.
  
    Returns
    -------
    centrality : dictionary
       Dictionary keyed by node with bipartite degree centrality as the value.
  
    Notes
    -----
    The nodes input parameter must contain all nodes in one bipartite node set,
    but the dictionary returned contains all nodes from both bipartite node
    sets.
  
    For unipartite networks, the degree centrality values are 
    normalized by dividing by the maximum possible degree (which is 
    `n-1` where `n` is the number of nodes in G). 
  
    In the bipartite case, the maximum possible degree of a node in a
    bipartite node set is the number of nodes in the opposite node set
    [1]_.  The degree centrality for a node `v` in the bipartite
    sets `U` with `n` nodes and `V` with `m` nodes is
  
    .. math::
  
        d_{v} = \frac{deg(v)}{m}, \mbox{for} v \in U ,
  
        d_{v} = \frac{deg(v)}{n}, \mbox{for} v \in V ,
  
  
    where `deg(v)` is the degree of node `v`.        
  
      
    """
    top = set(nodes)
    bottom = set(G) - top
    s = 1.0/len(bottom)
    centrality = dict((n,d*s) for n,d in G.degree_iter(top))
    s = 1.0/len(top)
    centrality.update(dict((n,d*s) for n,d in G.degree_iter(bottom)))
    return centrality

上面的函数是使用networkx库调用的,一旦安装了库,你最终可以使用它,下面的代码必须用Python编写来实现节点的度中心性。

import networkx as nx
G=nx.erdos_renyi_graph(100,0.5)
d=nx.degree_centrality(G)
print(d)

结果如下:

{0: 0.5252525252525253, 1: 0.4444444444444445, 2: 0.5454545454545455, 3: 0.36363636363636365, 
4: 0.42424242424242425, 5: 0.494949494949495, 6: 0.5454545454545455, 7: 0.494949494949495, 
8: 0.5555555555555556, 9: 0.5151515151515152, 10: 0.5454545454545455, 11: 0.5151515151515152, 
12: 0.494949494949495, 13: 0.4444444444444445, 14: 0.494949494949495, 15: 0.4141414141414142, 
16: 0.43434343434343436, 17: 0.5555555555555556, 18: 0.494949494949495, 19: 0.5151515151515152, 
20: 0.42424242424242425, 21: 0.494949494949495, 22: 0.5555555555555556, 23: 0.5151515151515152, 
24: 0.4646464646464647, 25: 0.4747474747474748, 26: 0.4747474747474748, 27: 0.494949494949495, 
28: 0.5656565656565657, 29: 0.5353535353535354, 30: 0.4747474747474748, 31: 0.494949494949495, 
32: 0.43434343434343436, 33: 0.4444444444444445, 34: 0.5151515151515152, 35: 0.48484848484848486,
 36: 0.43434343434343436, 37: 0.4040404040404041, 38: 0.5656565656565657, 39: 0.5656565656565657, 
40: 0.494949494949495, 41: 0.5252525252525253, 42: 0.4545454545454546, 43: 0.42424242424242425, 
44: 0.494949494949495, 45: 0.595959595959596, 46: 0.5454545454545455, 47: 0.5050505050505051,
 48: 0.4646464646464647, 49: 0.48484848484848486, 50: 0.5353535353535354, 51: 0.5454545454545455,
 52: 0.5252525252525253, 53: 0.5252525252525253, 54: 0.5353535353535354, 55: 0.6464646464646465, 
56: 0.4444444444444445, 57: 0.48484848484848486, 58: 0.5353535353535354, 59: 0.494949494949495, 
60: 0.4646464646464647, 61: 0.5858585858585859, 62: 0.494949494949495, 63: 0.48484848484848486, 
64: 0.4444444444444445, 65: 0.6262626262626263, 66: 0.5151515151515152, 67: 0.4444444444444445, 
68: 0.4747474747474748, 69: 0.5454545454545455, 70: 0.48484848484848486, 71: 0.5050505050505051,
 72: 0.4646464646464647, 73: 0.4646464646464647, 74: 0.5454545454545455, 75: 0.4444444444444445,
 76: 0.42424242424242425, 77: 0.4545454545454546, 78: 0.494949494949495, 79: 0.494949494949495, 
80: 0.4444444444444445, 81: 0.48484848484848486, 82: 0.48484848484848486, 83: 0.5151515151515152,
 84: 0.494949494949495, 85: 0.5151515151515152, 86: 0.5252525252525253, 87: 0.4545454545454546, 
88: 0.5252525252525253, 89: 0.5353535353535354, 90: 0.5252525252525253, 91: 0.4646464646464647, 
92: 0.4646464646464647, 93: 0.5555555555555556, 94: 0.5656565656565657, 95: 0.4646464646464647,
 96: 0.494949494949495, 97: 0.494949494949495, 98: 0.5050505050505051, 99: 0.5050505050505051}

上面的结果是一个字典,描述了每个节点的度中心性值。以上是我关于中心性度量的系列文章的延伸。继续联网!!!

参考
你可以阅读更多关于相同的内容

https://en.wikipedia.org/wiki/Centrality#Degree_centrality
http://networkx.readthedocs.io/en/networkx-1.10/index.html