average_clustering#

average_clustering(G, nodes=None, weight=None, count_zeros=True)[source]#

计算图 G 的平均聚类系数。

图的聚类系数是平均值,

\[C = \frac{1}{n}\sum_{v \in G} c_v,\]

其中 \(n\) 是图 G 中的节点数。

参数:
G
nodes节点容器,可选(默认为 G 中的所有节点)

计算此容器中节点的平均聚类系数。

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

用作权重的边属性,保存数值。如果为 None,则每条边的权重为 1。

count_zeros布尔值

如果为 False,则平均值仅包含聚类系数非零的节点。

返回:
avg浮点数

平均聚类系数

注意

这是一个节省空间的例程;使用 clustering 函数获取列表然后计算平均值可能更快。

忽略自环。

参考文献

[1]

Generalizations of the clustering coefficient to weighted complex networks by J. Saramäki, M. Kivelä, J.-P. Onnela, K. Kaski, and J. Kertész, Physical Review E, 75 027105 (2007). http://jponnela.com/web_documents/a9.pdf

[2]

Marcus Kaiser, Mean clustering coefficients: the role of isolated nodes and leafs on clustering measures for small-world networks. https://arxiv.org/abs/0802.2512

示例

>>> G = nx.complete_graph(5)
>>> print(nx.average_clustering(G))
1.0
----

其他后端实现了此函数

cugraphGPU加速后端。

尚不支持有向图和 weight 参数。

graphblas : 支持 OpenMP 的稀疏线性代数后端。