average_degree_connectivity#

average_degree_connectivity(G, source='in+out', target='in+out', nodes=None, weight=None)[source]#

计算图的平均度连接性。

平均度连接性是度为 k 的节点的平均最近邻度。对于加权图,可以使用 [1] 中定义的加权平均邻居度计算类似度量,对于节点 i,其定义为

\[k_{nn,i}^{w} = \frac{1}{s_i} \sum_{j \in N(i)} w_{ij} k_j\]

其中 s_i 是节点 i 的加权度,w_{ij} 是连接 ij 的边的权重,N(i) 是节点 i 的邻居。

参数:
GNetworkX 图
source“in”|”out”|”in+out” (默认值:“in+out”)

仅限有向图。对源节点使用“入”或“出”度。

target“in”|”out”|”in+out” (默认值:“in+out”)

仅限有向图。对目标节点使用“入”或“出”度。

nodes列表或可迭代对象 (可选)

计算这些节点的邻居连接性。默认为所有节点。

weight字符串或 None,可选 (默认值:None)

用作权重的边的属性名称。如果为 None,则每条边的权重为 1。

返回值:
ddict

一个字典,以度 k 为键,平均连接性为值。

抛出:
NetworkXError

如果 sourcetarget 不是 ‘in’、‘out’ 或 ‘in+out’ 之一。如果为无向图传递了 sourcetarget

参考文献

[1]

A. Barrat, M. Barthélemy, R. Pastor-Satorras, and A. Vespignani, “The architecture of complex weighted networks”. PNAS 101 (11): 3747–3752 (2004).

示例

>>> G = nx.path_graph(4)
>>> G.edges[1, 2]["weight"] = 3
>>> nx.average_degree_connectivity(G)
{1: 2.0, 2: 1.5}
>>> nx.average_degree_connectivity(G, weight="weight")
{1: 2.0, 2: 1.75}