onion_layers#
- onion_layers(G)[source]#
Returns the layer of each vertex in an onion decomposition of the graph.
The onion decomposition refines the k-core decomposition by providing information on the internal organization of each k-shell. It is usually used alongside the
core numbers
.- Parameters:
- GNetworkX graph
An undirected graph without self loops.
- Returns:
- od_layersdictionary
A dictionary keyed by node to the onion layer. The layers are contiguous integers starting at 1.
- Raises:
- NetworkXNotImplemented
If
G
is a multigraph or directed graph or if it contains self loops.
See also
References
[1]Multi-scale structure and topological anomaly detection via a new network statistic: The onion decomposition L. Hébert-Dufresne, J. A. Grochow, and A. Allard Scientific Reports 6, 31708 (2016) http://doi.org/10.1038/srep31708
[2]Percolation and the effective structure of complex networks A. Allard and L. Hébert-Dufresne Physical Review X 9, 011023 (2019) http://doi.org/10.1103/PhysRevX.9.011023
Examples
>>> degrees = [0, 1, 2, 2, 2, 2, 3] >>> H = nx.havel_hakimi_graph(degrees) >>> H.degree DegreeView({0: 1, 1: 2, 2: 2, 3: 2, 4: 2, 5: 3, 6: 0}) >>> nx.onion_layers(H) {6: 1, 0: 2, 4: 3, 1: 4, 2: 4, 3: 4, 5: 4}