networkx.algorithms.cluster.square_clustering¶
-
square_clustering
(G, nodes=None)[source]¶ Compute the squares clustering coefficient for nodes.
For each node return the fraction of possible squares that exist at the node 1
C4(v)=∑kvu=1∑kvw=u+1qv(u,w)∑kvu=1∑kvw=u+1[av(u,w)+qv(u,w)],where qv(u,w) are the number of common neighbors of u and w other than v (ie squares), and av(u,w)=(ku−(1+qv(u,w)+θuv))(kw−(1+qv(u,w)+θuw)), where θuw=1 if u and w are connected and 0 otherwise.
- Parameters
G (graph)
nodes (container of nodes, optional (default=all nodes in G)) – Compute clustering for nodes in this container.
- Returns
c4 – A dictionary keyed by node with the square clustering coefficient value.
- Return type
dictionary
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}
Notes
While C3(v) (triangle clustering) gives the probability that two neighbors of node v are connected with each other, C4(v) is the probability that two neighbors of node v share a common neighbor different from v. This algorithm can be applied to both bipartite and unipartite networks.
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.