核心分解
此笔记本演示了图的 \(k\)-核心分解。
[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
图
[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]:
有向图
[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]: