Dirichlet

This notebook illustrates a regression task as a solution of the Dirichlet problem (heat diffusion with constraints).

[1]:
from IPython.display import SVG
[2]:
from sknetwork.data import karate_club, painters, movie_actor
from sknetwork.regression import Dirichlet
from sknetwork.visualization import visualize_graph, visualize_bigraph

Graphs

[3]:
graph = karate_club(metadata=True)
adjacency = graph.adjacency
position = graph.position
labels_true = graph.labels
[4]:
# heat diffusion
dirichlet = Dirichlet()
values = {0: 0, 33: 1}
values_pred = dirichlet.fit_predict(adjacency, values)
[5]:
image = visualize_graph(adjacency, position, scores=values_pred, seeds=values)
SVG(image)
[5]:
../../_images/tutorials_regression_dirichlet_7_0.svg

Directed graphs

[6]:
graph = painters(metadata=True)
adjacency = graph.adjacency
position = graph.position
names = graph.names
[7]:
picasso = 0
monet = 1
[8]:
dirichlet = Dirichlet()
values = {picasso: 0, monet: 1}
values_pred = dirichlet.fit_predict(adjacency, values)
[9]:
image = visualize_graph(adjacency, position, names, scores=values_pred, seeds=values)
SVG(image)
[9]:
../../_images/tutorials_regression_dirichlet_12_0.svg

Bipartite graphs

[10]:
graph = movie_actor(metadata=True)
biadjacency = graph.biadjacency
names_row = graph.names_row
names_col = graph.names_col
[11]:
dirichlet = Dirichlet()
[12]:
drive = 3
aviator = 9
[13]:
values_row = {drive: 0, aviator: 1}
dirichlet.fit(biadjacency, values_row)
values_row_pred = dirichlet.values_row_
values_col_pred = dirichlet.values_col_
[14]:
image = visualize_bigraph(biadjacency, names_row, names_col, scores_row=values_row_pred, scores_col=values_col_pred,
                    seeds_row=values_row)
SVG(image)

[14]:
../../_images/tutorials_regression_dirichlet_18_0.svg