square_clustering#
- graph_tool.clustering.square_clustering(g, prop=None)[git][source]#
Return the square clustering coefficients of the vertices.
- Parameters:
- g
Graph Graph to be used. If it is directed, it is treated as undirected.
- prop
VertexPropertyMap(optional, default:None) Vertex property map of type
doublewhere results will be stored.
- g
- Returns:
- prop
VertexPropertyMap Vertex property containing the square clustering coefficients.
- prop
See also
local_clusteringLocal clustering coefficient
butterfliesNumber of cycles of length four
latapy_clusteringLocal bipartite clustering coefficient
Notes
The square clustering coefficient [lind-cycles-2005] is the analogue of the local clustering coefficient (see
local_clustering()) for cycles of length four, which are the shortest cycles in bipartite networks, where there are no triangles. For each pair \(u,w\) of neighbors of \(v\), let \(q_v(u,w)\) be their number of common neighbors other than \(v\), and \(a_v(u,w) = (k_u - 1 - q_v(u,w) - \theta_{uw}) + (k_w - 1 - q_v(u,w) - \theta_{uw})\) the sum of their numbers of other neighbors, i.e. excluding \(v\), these common neighbors, and each other, where \(k_u\) is the number of neighbors of \(u\), and \(\theta_{uw} = 1\) if \(u\) and \(w\) are adjacent and \(0\) otherwise. Then\[c^{(4)}_v = \frac{\sum_{u<w}q_v(u,w)}{\sum_{u<w}[a_v(u,w) + q_v(u,w)]},\]where the sums are over the pairs of neighbors of \(v\), and the value is zero if the denominator vanishes (in particular for vertices with fewer than two neighbors). Parallel edges and self-loops are ignored. The algorithm runs in time \(O(\sum_v\sum_{u\in N_v}k_u)\).
Parallel implementation.
If enabled during compilation, this algorithm will run in parallel using OpenMP. See the parallel algorithms section for information about how to control several aspects of parallelization.
References
[lind-cycles-2005]Pedro G. Lind, Marta C. González and Hans J. Herrmann, “Cycles and clustering in bipartite networks”, Phys. Rev. E 72, 056127 (2005), DOI: 10.1103/PhysRevE.72.056127 [sci-hub, @tor], arXiv: cond-mat/0504241
Examples
>>> g = gt.collection.data["football"] >>> c4 = gt.square_clustering(g) >>> print(c4.a.mean()) 0.162874013...
The values can be visualized by drawing the network with vertex colors and sizes given by them:
>>> cmap = matplotlib.colors.LinearSegmentedColormap.from_list( ... "gray-blue", ["#d9d9d9", "#7dabd1"]) >>> gt.graph_draw(g, g.vp.pos, vertex_fill_color=c4, vcmap=cmap, ... vertex_size=gt.prop_to_size(c4, mi=5, ma=15), ... output="square_clustering-football.pdf") <...>
Square clustering coefficients of the vertices of the network of American college football games. The vertex colors, from gray to blue, and the vertex sizes increase with the value.#