kcore_decomposition#
- graph_tool.structure.kcore_decomposition(g, vprop=None, mode='total')[git][source]#
Perform a k-core decomposition of the given graph.
- Parameters:
- g
Graph Graph to be used.
- vprop
VertexPropertyMap(optional, default:None) Vertex property to store the decomposition. If
Noneis supplied, one is created.- mode
str(optional, default:"total") For directed graphs, the degree used in the decomposition:
"total","in", or"out".
- g
- Returns:
- kval
VertexPropertyMap Vertex property map with the k-core decomposition, i.e. a given vertex v belongs to the
kval[v]-core.
- kval
See also
kcore_subgraphK-core, k-shell, k-crust, or k-corona as a subgraph
onion_decompositionRefinement of the k-core decomposition into layers
truss_decompositionEdge counterpart based on triangles
Notes
The k-core is a maximal set of vertices such that its induced subgraph only contains vertices with degree larger than or equal to k.
For directed graphs, the degree is the total (in + out) degree by default, or the in- or out-degree according to
mode. For the in-degree, the removal of a vertex lowers the in-degrees of its out-neighbors, and analogously for the out-degree.The algorithm accepts graphs with parallel edges and self loops, in which case these edges contribute to the degree in the usual fashion.
This algorithm is described in [batagelj-algorithm] and runs in \(O(V + E)\) time.
References
[batagelj-algorithm]Vladimir Batagelj, Matjaž Zaveršnik, “Fast algorithms for determining (generalized) core groups in social networks”, Advances in Data Analysis and Classification Volume 5, Issue 2, pp 129-145 (2011), DOI: 10.1007/s11634-010-0079-y [sci-hub, @tor], arXiv: cs/0310049
Examples
>>> g = gt.collection.data["netscience"] >>> g = gt.GraphView(g, vfilt=gt.label_largest_component(g)) >>> kcore = gt.kcore_decomposition(g) >>> gt.graph_draw(g, pos=g.vp["pos"], vertex_fill_color=kcore, vertex_text=kcore, output="netsci-kcore.svg") <...>
K-core decomposition of a network of network scientists.#