latapy_clustering#
- graph_tool.clustering.latapy_clustering(g, mode='dot', prop=None)[git][source]#
Return the bipartite clustering coefficients of Latapy et al. of the vertices.
- Parameters:
- g
Graph Bipartite graph to be used. If it is directed, it is treated as undirected.
- mode
str(optional, default:"dot") Overlap of the neighborhoods of two vertices: one of
"dot","min", or"max"(see below).- prop
VertexPropertyMap(optional, default:None) Vertex property map of type
doublewhere results will be stored.
- g
- Returns:
- prop
VertexPropertyMap Vertex property map containing the clustering coefficients.
- prop
- Raises:
- ValueError
If the graph is not bipartite.
See also
node_redundancyRedundancy of the vertices of a bipartite graph
robins_alexander_clusteringGlobal bipartite clustering coefficient
square_clusteringSquare clustering coefficient
Notes
In a bipartite graph, the neighbors of a vertex are never adjacent, so that the local clustering coefficient (see
local_clustering()) vanishes. Latapy et al. [latapy-basic-2008] instead measure the overlap of the neighborhood of vertex \(v\) with those of the vertices \(N^{(2)}_v\) at distance two from it,\[c_v = \frac{1}{|N^{(2)}_v|}\sum_{w\in N^{(2)}_v}c_{vw},\]where the overlap \(c_{vw}\) is, for
mode == "dot","min", and"max", respectively,\[c_{vw} = \frac{|N_v\cap N_w|}{|N_v\cup N_w|},\quad c_{vw} = \frac{|N_v\cap N_w|}{\min(k_v,k_w)},\quad c_{vw} = \frac{|N_v\cap N_w|}{\max(k_v,k_w)},\]where \(N_v\) is the set of neighbors of \(v\) and \(k_v = |N_v|\). The value is zero if no vertex is at distance two from \(v\). The average clustering of the graph, or of one of its two vertex sets [latapy-basic-2008], is the mean of these values over the corresponding vertices (see the examples below). 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
[latapy-basic-2008] (1,2)Matthieu Latapy, Clémence Magnien and Nathalie Del Vecchio, “Basic notions for the analysis of large two-mode networks”, Social Networks 30, 31-48 (2008), DOI: 10.1016/j.socnet.2007.04.006 [sci-hub, @tor]
Examples
>>> g = gt.collection.ns["davis_southern_women"] >>> c = gt.latapy_clustering(g) >>> print(c.a.mean()) 0.328485836... >>> woman = g.vp.is_woman.a == 1 >>> print(c.a[woman].mean(), c.a[~woman].mean()) 0.317139923... 0.343073437...
The values can be visualized by drawing the network with vertex colors and sizes given by them, and with the women as circles and the events as squares:
>>> pos = gt.sfdp_layout(g) >>> cmap = matplotlib.colors.LinearSegmentedColormap.from_list( ... "gray-blue", ["#d9d9d9", "#7dabd1"]) >>> shape = g.new_vp("string", vals=np.where(g.vp.is_woman.a, "circle", ... "square")) >>> gt.graph_draw(g, pos, vertex_fill_color=c, vcmap=cmap, ... vertex_size=gt.prop_to_size(c, mi=5, ma=15), ... vertex_shape=shape, ... output="latapy_clustering-davis.pdf") <...>
Bipartite clustering coefficients of Latapy et al. of the vertices of the bipartite network of women and the social events they attended. The women are shown as circles and the events as squares. The vertex colors, from gray to blue, and the vertex sizes increase with the value.#