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 get_core_decomposition
from sknetwork.visualization import visualize_graph
from sknetwork.utils import directed2undirected
Graphs
[4]:
graph = karate_club(metadata=True)
adjacency = graph.adjacency
position = graph.position
[5]:
values = get_core_decomposition(adjacency)
[6]:
image = visualize_graph(adjacency, position, scores=values)
SVG(image)
[6]:
Directed graphs
[7]:
graph = painters(metadata=True)
adjacency = graph.adjacency
names = graph.names
position = graph.position
[8]:
values = get_core_decomposition(directed2undirected(adjacency))
[9]:
image = visualize_graph(adjacency, position, names, scores=values)
SVG(image)
[9]: