Core decomposition

This notebook illustrates the \(k\)-core decomposition of graphs.

[1]:
from IPython.display import SVG
[2]:
import numpy as np
[3]:
from sknetwork.data import karate_club, painters
from sknetwork.topology import CoreDecomposition
from sknetwork.visualization import svg_graph, svg_digraph
from sknetwork.utils import directed2undirected

Graphs

[4]:
graph = karate_club(metadata=True)
adjacency = graph.adjacency
position = graph.position
[5]:
core = CoreDecomposition()
[6]:
labels = core.fit_transform(adjacency)
[7]:
image = svg_graph(adjacency, position, scores=labels)
SVG(image)
[7]:
../../_images/tutorials_topology_core_decomposition_9_0.svg

Digraphs

[8]:
graph = painters(metadata=True)
adjacency = graph.adjacency
names = graph.names
position = graph.position
[9]:
labels = core.fit_transform(directed2undirected(adjacency))
[10]:
image = svg_digraph(adjacency, position, names, scores=labels)
SVG(image)
[10]:
../../_images/tutorials_topology_core_decomposition_13_0.svg