GSVD

This notebook illustrates the embedding of a graph through the generalized singular value decomposition of the adjacency matrix.

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

Graphs

[4]:
graph = karate_club(metadata=True)
adjacency = graph.adjacency
labels = graph.labels
[5]:
gsvd = GSVD(2, normalized=False)
embedding = gsvd.fit_transform(adjacency)
[6]:
image = svg_graph(adjacency, embedding, labels=labels)
[7]:
SVG(image)
[7]:
../../_images/tutorials_embedding_gsvd_9_0.svg

Digraphs

[8]:
graph = painters(metadata=True)
adjacency = graph.adjacency
position = graph.position
names = graph.names
[9]:
gsvd = GSVD(2, normalized=False)
embedding = gsvd.fit_transform(adjacency)
[10]:
image = svg_digraph(adjacency, embedding, names=names)
[11]:
SVG(image)
[11]:
../../_images/tutorials_embedding_gsvd_14_0.svg

Bigraphs

[12]:
graph = movie_actor(metadata=True)
biadjacency = graph.biadjacency
names_row = graph.names_row
names_col = graph.names_col
[13]:
gsvd = GSVD(2, normalized=False)
gsvd.fit(biadjacency)
[13]:
GSVD(n_components=2, regularization=None, relative_regularization=True, factor_row=0.5, factor_col=0.5, factor_singular=0.0, normalized=False, solver=LanczosSVD(maxiter=None, tol=0.0))
[14]:
embedding_row = gsvd.embedding_row_
embedding_col = gsvd.embedding_col_
[15]:
image = svg_bigraph(biadjacency, names_row, names_col,
                    position_row=embedding_row, position_col=embedding_col,
                    color_row='blue', color_col='red')
[16]:
SVG(image)
[16]:
../../_images/tutorials_embedding_gsvd_20_0.svg