square_clustering#
- square_clustering(G, nodes=None)[source]#
计算节点的平方聚类系数。
对于每个节点,返回存在的平方数与可能的平方数的比例 [1]
\[C_4(v) = \frac{ \sum_{u=1}^{k_v} \sum_{w=u+1}^{k_v} q_v(u,w) }{ \sum_{u=1}^{k_v} \sum_{w=u+1}^{k_v} [a_v(u,w) + q_v(u,w)]},\]其中 \(q_v(u,w)\) 是 \(u\) 和 \(w\) 除了 \(v\) 之外的共同邻居数(即平方数),而 \(a_v(u,w) = (k_u - (1+q_v(u,w)+\theta_{uv})) + (k_w - (1+q_v(u,w)+\theta_{uw}))\) ,其中 \(\theta_{uw} = 1\) 如果 \(u\) 和 \(w\) 相连,否则为 0。 [2]
- Parameters:
- G图
- nodes节点容器,可选(默认=G中的所有节点)
计算容器中节点的聚类系数。
- Returns:
- c4字典
一个以节点为键,平方聚类系数值为值的字典。
Notes
虽然 \(C_3(v)\) (三角形聚类)给出了节点 v 的两个邻居相互连接的概率,但 \(C_4(v)\) 是节点 v 的两个邻居共享一个不同于 v 的共同邻居的概率。此算法可应用于二分图和单分图网络。
References
[1]Pedro G. Lind, Marta C. González, and Hans J. Herrmann. 2005 Cycles and clustering in bipartite networks. Physical Review E (72) 056127.
[2]Zhang, Peng et al. Clustering Coefficient and Community Structure of Bipartite Networks. Physica A: Statistical Mechanics and its Applications 387.27 (2008): 6869–6875. https://arxiv.org/abs/0710.0117v1
Examples
>>> G = nx.complete_graph(5) >>> print(nx.square_clustering(G, 0)) 1.0 >>> print(nx.square_clustering(G)) {0: 1.0, 1: 1.0, 2: 1.0, 3: 1.0, 4: 1.0}
Additional backends implement this function
- graphblasOpenMP-enabled sparse linear algebra backend.
- Additional parameters:
- chunksizeint or str, optional
Split the computation into chunks; may specify size as string or number of rows. Default “256 MiB”
- parallelParallel backend for NetworkX algorithms
The nodes are chunked into
node_chunks
and then the square clustering coefficient for allnode_chunks
are computed in parallel over all available CPU cores.- Additional parameters:
- get_chunksstr, function (default = “chunks”)
A function that takes in a list of all the nodes (or nbunch) as input and returns an iterable
node_chunks
. The default chunking is done by slicing thenodes
inton
chunks, wheren
is the number of CPU cores.
[Source]