# Dirichlet¶

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

:

from IPython.display import SVG

:

import numpy as np

:

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¶

:

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

:

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

:

image = svg_graph(adjacency, position, scores=scores, seeds=seeds)

:

SVG(image)

: ## Digraphs¶

:

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

:

picasso = 0
monet = 1

:

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

:

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

:

SVG(image)

: ## Bigraphs¶

:

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

:

bidiffusion = BiDirichlet()

:

drive = 3
aviator = 9

:

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

:

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

:

SVG(image)

: 