📜  紧密度中心度(中心度度量)

📅  最后修改于: 2021-05-20 07:21:06             🧑  作者: Mango

在连接的图中,节点的紧密度中心度(或紧密度)是网络中的中心度的度量,计算为该节点与图中所有其他节点之间的最短路径的长度之和。因此,节点越中心,它与所有其他节点越近。

亲近度由Bavelas(1950)定义为相近度的倒数,即:

C(x)={\frac  {1}{\sum _{y}d(y,x)}}
在哪里 d(y,x)是顶点之间的距离x y 。当谈到紧密度中心性时,人们通常会引用其归一化形式,该形式代表最短路径的平均长度而不是它们的总和。通常由前面的公式乘以 N-1 , 在哪里 N是图中的节点数。对于大图,这种差异变得无关紧要,因此 -1被丢弃导致:

C(x)={\frac {N}{\sum _{y}d(y,x)}}
此调整允许在不同大小的图形的节点之间进行比较。

在无向图中,与其他节点之间的距离是无关紧要的,而在有向图中,它可以产生完全不同的结果(例如,一个网站与传出链接的紧密度很高,而与传入链接的紧密度很低)。

在断开的图中
当图没有牢固地联系在一起时,一个普遍的想法是使用距离的倒数之和,而不是距离之和的倒数,按照惯例 1/\infty=0

 H(x)=\sum _{{y\neq x}}{\frac  {1}{d(y,x)}}
Bavelas对贴近度定义的最自然的修改是遵循Marchiori和Latora(2000)提出的一般原理,即在无限距离的图中,谐波均值的表现优于算术均值。确实,Bavelas的亲和度可以描述为距离的算术平均值的非规范化倒数,而谐波中心性是距离的谐波平均值的非规范化倒数。

对于无向图,Dekker(2005)将其命名为“中心性”,Rochat(2009)将其命名为“谐波中心性”,Garg(2009)将其公理化,然后由Opsahl(2010)再次提出。 Boldi和Vigna(2014)在一般有向图上进行了研究。这个想法也与哈里斯(Harris,1954)提出的市场潜力非常相似,该术语现在经常被称为市场准入。

变体
Dangalchev(2006)在有关网络漏洞的工作中为无向图提出了不同的定义:

 D(x)=\sum _{{y\neq x}}{\frac  {1}{2^{{d(y,x)}}}}.
此定义可有效用于断开连接的图,并允许为图操作创建方便的公式。例如,如果一个图  G_{1}+G_{2}通过链接图的节点p创建 G_{1}到节点q图的G_{2}那么合并的紧密度是:

 D(G_{1}+G_{2})=D(G_{1})+D(G_{2})+(1+D(p))(1+D(q)).
Stephenson和Zelen(1989)的信息中心性是另一种接近度度量,它计算到顶点x的电阻距离的谐波均值,如果x具有许多将其连接到其他顶点的小电阻路径,则该距离较小。

在接近中心性的经典定义中,信息的传播是通过使用最短路径来建模的。对于所有类型的通信场景,此模型可能都不是最实际的。因此,已经讨论了相关的定义来测量亲密性,例如Noh和Rieger(2004)引入的随机步行亲密性中心性。它测量了随机游走消息从图中其他位置到达顶点的速度,这种速度是一种紧密度集中的随机游走形式。 Tran和Kwon(2014)的分层紧密度是扩展的紧密度中心度,可以用另一种方式处理图中没有紧密联系的紧密度的局限性。层次紧密性明确包含有关可能受给定节点影响的其他节点范围的信息。

以下是用于计算图形及其各个节点的“紧密度中心性”的代码。

def closeness_centrality(G, u=None, distance=None, normalized=True):
    r"""Compute closeness centrality for nodes.
  
    Closeness centrality [1]_ of a node `u` is the reciprocal of the
    sum of the shortest path distances from `u` to all `n-1` other nodes.
    Since the sum of distances depends on the number of nodes in the
    graph, closeness is normalized by the sum of minimum possible
    distances `n-1`.
  
    .. math::
  
        C(u) = \frac{n - 1}{\sum_{v=1}^{n-1} d(v, u)},
  
    where `d(v, u)` is the shortest-path distance between `v` and `u`,
    and `n` is the number of nodes in the graph.
  
    Notice that higher values of closeness indicate higher centrality.
  
    Parameters
    ----------
    G : graph
      A NetworkX graph
    u : node, optional
      Return only the value for node u
    distance : edge attribute key, optional (default=None)
      Use the specified edge attribute as the edge distance in shortest 
      path calculations
    normalized : bool, optional
      If True (default) normalize by the number of nodes in the connected
      part of the graph.
  
    Returns
    -------
    nodes : dictionary
      Dictionary of nodes with closeness centrality as the value.
  
    See Also
    --------
    betweenness_centrality, load_centrality, eigenvector_centrality,
    degree_centrality
  
    Notes
    -----
    The closeness centrality is normalized to `(n-1)/(|G|-1)` where
    `n` is the number of nodes in the connected part of graph
    containing the node.  If the graph is not completely connected,
    this algorithm computes the closeness centrality for each
    connected part separately.
  
    If the 'distance' keyword is set to an edge attribute key then the
    shortest-path length will be computed using Dijkstra's algorithm with
    that edge attribute as the edge weight.
  
     
    """
    if distance is not None:
  
        # use Dijkstra's algorithm with specified attribute as edge weight 
        path_length = functools.partial(nx.single_source_dijkstra_path_length,
                                        weight=distance)
    else:
        path_length = nx.single_source_shortest_path_length
  
    if u is None:
        nodes = G.nodes()
    else:
        nodes = [u]
    closeness_centrality = {}
    for n in nodes:
        sp = path_length(G,n)
        totsp = sum(sp.values())
        if totsp > 0.0 and len(G) > 1:
            closeness_centrality[n] = (len(sp)-1.0) / totsp
  
            # normalize to number of nodes-1 in connected part
            if normalized:
                s = (len(sp)-1.0) / ( len(G) - 1 )
                closeness_centrality[n] *= s
        else:
            closeness_centrality[n] = 0.0
    if u is not None:
        return closeness_centrality[u]
    else:
        return closeness_centrality

上面的函数是使用networkx库调用的,一旦安装了该库,您就可以最终使用它,并且以下代码必须用Python编写,以实现节点的紧密性。

import networkx as nx
G=nx.erdos_renyi_graph(100,0.6)
c=nx.closeness_centrality(G)
print(c)

上面代码的输出是:

{0: 0.6971830985915493, 1: 0.7122302158273381, 2: 0.6875, 3: 0.7021276595744681, 
4: 0.7443609022556391, 5: 0.7388059701492538, 6: 0.7071428571428572, 7: 0.7388059701492538,
 8: 0.7388059701492538, 9: 0.7226277372262774, 10: 0.6923076923076923, 11: 0.7021276595744681,
 12: 0.7388059701492538, 13: 0.6923076923076923, 14: 0.7279411764705882, 15: 0.6644295302013423,
 16: 0.7333333333333333, 17: 0.7388059701492538, 18: 0.7122302158273381, 19: 0.678082191780822,
 20: 0.6923076923076923, 21: 0.717391304347826, 22: 0.6923076923076923, 23: 0.7071428571428572, 
24: 0.7333333333333333, 25: 0.717391304347826, 26: 0.7734375, 27: 0.7071428571428572,
 28: 0.7557251908396947, 29: 0.7279411764705882, 30: 0.717391304347826, 31: 0.7122302158273381,
 32: 0.7122302158273381, 33: 0.7226277372262774, 34: 0.6827586206896552, 35: 0.7021276595744681, 
36: 0.7122302158273381, 37: 0.673469387755102, 38: 0.75, 39: 0.7071428571428572,
 40: 0.7333333333333333, 41: 0.717391304347826, 42: 0.7071428571428572, 43: 0.6875, 
44: 0.7615384615384615, 45: 0.7226277372262774, 46: 0.7857142857142857, 47: 0.7388059701492538,
 48: 0.7333333333333333, 49: 0.717391304347826, 50: 0.7021276595744681, 51: 0.7071428571428572,
 52: 0.717391304347826, 53: 0.7333333333333333, 54: 0.717391304347826, 55: 0.7388059701492538,
 56: 0.7021276595744681, 57: 0.7557251908396947, 58: 0.6971830985915493, 59: 0.7795275590551181,
 60: 0.7122302158273381, 61: 0.7388059701492538, 62: 0.717391304347826, 63: 0.6923076923076923,
 64: 0.7071428571428572, 65: 0.7021276595744681, 66: 0.7021276595744681, 67: 0.7021276595744681,
 68: 0.7388059701492538, 69: 0.7333333333333333, 70: 0.6923076923076923, 71: 0.75, 
72: 0.7557251908396947, 73: 0.7443609022556391, 74: 0.7388059701492538, 75: 0.7388059701492538,
 76: 0.6346153846153846, 77: 0.7071428571428572, 78: 0.7226277372262774, 79: 0.7674418604651163,
 80: 0.7071428571428572, 81: 0.7279411764705882, 82: 0.678082191780822, 83: 0.7333333333333333,
 84: 0.7443609022556391, 85: 0.6923076923076923, 86: 0.7122302158273381, 87: 0.7333333333333333,
 88: 0.7279411764705882, 89: 0.7122302158273381, 90: 0.7122302158273381, 91: 0.7557251908396947,
 92: 0.7388059701492538, 93: 0.7021276595744681, 94: 0.6513157894736842, 95: 0.673469387755102,
 96: 0.7122302158273381, 97: 0.717391304347826, 98: 0.7021276595744681, 99: 0.7388059701492538}

以上结果是一个字典,描述了每个节点的紧密度中心值。以上是我关于集中度度量的文章系列的扩展。保持联网!!!

参考
您可以在以下位置阅读更多有关此内容的信息

https://zh.wikipedia.org/wiki/Closeness_centrality
http://networkx.readthedocs.io/en/networkx-1.10/index.html