truss_decomposition#
- graph_tool.structure.truss_decomposition(g, eprop=None)[git][source]#
Perform a k-truss decomposition of the given graph.
- Parameters:
- g
Graph Graph to be used. If it is directed, it is treated as undirected.
- eprop
EdgePropertyMap(optional, default:None) Edge property map where the trussness values will be stored, of type
int32_t.
- g
- Returns:
- eprop
EdgePropertyMap Edge property map with the trussness of each edge.
- eprop
See also
kcore_decompositionVertex counterpart based on degrees
onion_decompositionRefinement of the k-core decomposition into layers
graph_tool.clustering.edge_clusteringNumber of triangles of every edge
Notes
The \(k\)-truss of a graph is its largest subgraph in which every edge belongs to at least \(k-2\) triangles of the subgraph [cohen-trusses-2008]. The trussness of an edge is the largest \(k\) such that the edge belongs to the \(k\)-truss; edges that belong to no triangle have trussness 2. Since a \(k\)-truss is a \((k-1)\)-core (see
kcore_decomposition()), the decomposition finds cohesive subgraphs at a finer level than the cores.Parallel edges are treated as a single edge (and receive the same value), and self-loops receive the value zero.
The algorithm of [wang-truss-2012] is used, which removes the edges in increasing order of the number of triangles they belong to, and runs in time \(O(E^{3/2})\).
References
[cohen-trusses-2008]Jonathan Cohen, “Trusses: Cohesive subgraphs for social network analysis”, National Security Agency technical report (2008).
[wang-truss-2012]Jia Wang and James Cheng, “Truss decomposition in massive networks”, Proceedings of the VLDB Endowment 5, 812-823 (2012), DOI: 10.14778/2311906.2311909 [sci-hub, @tor], arXiv: 1205.6693
Examples
>>> g = gt.collection.data["football"] >>> truss = gt.truss_decomposition(g) >>> print(np.bincount(truss.fa)) [ 0 0 96 88 39 0 157 65 96 72]
The trussness can be visualized by coloring the edges:
>>> from matplotlib.colors import LinearSegmentedColormap >>> cmap = LinearSegmentedColormap.from_list("truss", ["#d9d9d9", ... "#e41a1c"]) >>> gt.graph_draw(g, g.vp.pos, vertex_fill_color="#cccccc", ... edge_color=truss.copy("double"), ecmap=cmap, ... eorder=truss, edge_pen_width=1.5, ... output="truss_decomposition-football.pdf") <...>
Truss decomposition of the network of American college football games. The colors of the edges range from gray (trussness 2) to red (trussness 9).#