Diffusion

This notebook illustrates the ranking of the nodes of a graph by heat diffusion.

[1]:
from IPython.display import SVG
[2]:
import numpy as np
[3]:
from sknetwork.data import karate_club, painters, movie_actor
from sknetwork.ranking import Diffusion, BiDiffusion
from sknetwork.visualization import svg_graph, svg_digraph, svg_bigraph

Graphs

[4]:
graph = karate_club(metadata=True)
adjacency = graph.adjacency
position = graph.position
labels_true = graph.labels
[5]:
diffusion = Diffusion()
seeds = {0: 0, 33: 1}
scores = diffusion.fit_transform(adjacency, seeds)
[6]:
image = svg_graph(adjacency, position, scores=scores, seeds=seeds)
[7]:
SVG(image)
[7]:
../../_images/tutorials_ranking_diffusion_9_0.svg

Digraphs

[8]:
graph = painters(metadata=True)
adjacency = graph.adjacency
position = graph.position
names = graph.names
[9]:
picasso = 0
manet = 3
[10]:
diffusion = Diffusion()
seeds = {picasso: 1, manet: 1}
scores = diffusion.fit_transform(adjacency, seeds, init=0)
[11]:
image = svg_digraph(adjacency, position, names, scores=scores, seeds=seeds)
[12]:
SVG(image)
[12]:
../../_images/tutorials_ranking_diffusion_15_0.svg

Bigraphs

[13]:
graph = movie_actor(metadata=True)
biadjacency = graph.biadjacency
names_row = graph.names_row
names_col = graph.names_col
[14]:
drive = 3
aviator = 9
[15]:
bidiffusion = BiDiffusion()
seeds_row = {drive: 0, aviator: 1}
bidiffusion.fit(biadjacency, seeds_row=seeds_row)
scores_row = bidiffusion.scores_row_
scores_col = bidiffusion.scores_col_
[16]:
image = svg_bigraph(biadjacency, names_row, names_col, scores_row=scores_row, scores_col=scores_col,
                    seeds_row=seeds_row)
[17]:
SVG(image)
[17]:
../../_images/tutorials_ranking_diffusion_21_0.svg