onion_decomposition

onion_decomposition#

graph_tool.structure.onion_decomposition(g, mode='total')[git][source]#

Perform the onion decomposition of the given graph.

Parameters:
gGraph

Graph to be used.

modestr (optional, default: "total")

For directed graphs, the degree used in the decomposition: "total", "in", or "out".

Returns:
coreVertexPropertyMap

The k-core of every vertex, as given by kcore_decomposition().

layerVertexPropertyMap

The layer of every vertex, numbered from one.

See also

kcore_decomposition

K-core decomposition

kcore_subgraph

K-core, k-shell, k-crust, or k-corona as a subgraph

truss_decomposition

Edge counterpart based on triangles

Notes

The onion decomposition [hebert-dufresne-multi-scale-2016] refines the k-core decomposition by removing the vertices in rounds. Starting with \(k\) equal to the smallest degree, in every round all the remaining vertices whose degree in the remaining graph is at most \(k\) are removed simultaneously, receive the core number \(k\), and form a new layer; when no remaining vertex has degree at most \(k\), \(k\) is increased to the smallest remaining degree. The layers are thus numbered consecutively over all the cores, so that the vertices of a layer belong to the same core, and the layers of higher cores have higher numbers.

The algorithm runs in \(O(V + E)\) time.

References

[hebert-dufresne-multi-scale-2016]

Laurent Hébert-Dufresne, Joshua A. Grochow and Antoine Allard, “Multi-scale structure and topological anomaly detection via a new network statistic: The onion decomposition”, Scientific Reports 6, 31708 (2016), DOI: 10.1038/srep31708 [sci-hub, @tor], arXiv: 1510.08542

Examples

>>> g = gt.collection.data["netscience"]
>>> core, layer = gt.onion_decomposition(g)
>>> print(core.a.max(), layer.a.max())
19 26

The layers can be visualized by coloring the vertices, here of the largest component:

>>> from matplotlib.colors import LinearSegmentedColormap
>>> cmap = LinearSegmentedColormap.from_list("layer", ["#d9d9d9",
...                                                    "#7dabd1"])
>>> u = gt.extract_largest_component(g)
>>> gt.graph_draw(u, g.vp.pos, vertex_fill_color=layer.copy("double"),
...               vcmap=cmap,
...               edge_color="#999999",
...               output="onion_decomposition-netsci.pdf")
<...>
../_images/onion_decomposition-netsci.png

Onion decomposition of the network of coauthorships in network science, shown for its largest component. The colors of the vertices range from gray (first layer) to blue (last layer).#