# Dirichlet¶

This notebook illustrates the ranking of the nodes of a graph through the Dirichlet problem (heat diffusion with constraints).

[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 Dirichlet, BiDirichlet
from sknetwork.visualization import svg_graph, svg_digraph, svg_bigraph


## Graphs¶

[4]:

graph = karate_club(metadata=True)
position = graph.position
labels_true = graph.labels

[5]:

diffusion = Dirichlet()
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]:


## Digraphs¶

[8]:

graph = painters(metadata=True)
position = graph.position
names = graph.names

[9]:

picasso = 0
monet = 1

[10]:

diffusion = Dirichlet()
seeds = {picasso: 0, monet: 1}
scores = diffusion.fit_transform(adjacency, seeds)

[11]:

image = svg_digraph(adjacency, position, names, scores=scores, seeds=seeds)

[12]:

SVG(image)

[12]:


## Bigraphs¶

[13]:

graph = movie_actor(metadata=True)
names_row = graph.names_row
names_col = graph.names_col

[14]:

bidiffusion = BiDirichlet()

[15]:

drive = 3
aviator = 9

[16]:

seeds_row = {drive: 0, aviator: 1}
scores_row = bidiffusion.scores_row_
scores_col = bidiffusion.scores_col_

[17]:

image = svg_bigraph(biadjacency, names_row, names_col, scores_row=scores_row, scores_col=scores_col,
seeds_row=seeds_row)

[18]:

SVG(image)

[18]: