<jupyter_start><jupyter_text>GSVD This notebook illustrates the embedding of a graph through the [generalized singular value decomposition](https://en.wikipedia.org/wiki/Generalized_singular_value_decomposition) of the adjacency matrix.<jupyter_code>from IPython.display import SVG
import numpy as np
from sknetwork.data import karate_club, painters, movie_actor
from sknetwork.embedding import GSVD, cosine_modularity
from sknetwork.visualization import svg_graph, svg_digraph, svg_bigraph<jupyter_output><empty_output><jupyter_text>Graphs<jupyter_code>graph = karate_club(metadata=True)
adjacency = graph.adjacency
labels = graph.labels<jupyter_output><empty_output><jupyter_text>**Embedding**<jupyter_code>gsvd = GSVD(3, normalized=False)
embedding = gsvd.fit_transform(adjacency)
embedding.shape
# skip first component
position = embedding[:,1:]
image = svg_graph(adjacency, position, labels=labels)
SVG(image)<jupyter_output>/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/networkx/drawing/nx_pylab.py:402: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
  if isinstance(alpha, collections.Iterable):
/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/networkx/drawing/nx_pylab.py:579: MatplotlibDeprecationWarning: 
The iterable function was deprecated in Matplotlib 3.1 and will be removed in 3.3. Use np.iterable instead.
  if not cb.iterable(width):<jupyter_text>**Metrics**<jupyter_code>cosine_modularity(adjacency, embedding)<jupyter_output><empty_output><jupyter_text>Digraphs<jupyter_code>graph = painters(metadata=True)
adjacency = graph.adjacency
position = graph.position
names = graph.names<jupyter_output><empty_output><jupyter_text>**Embedding**<jupyter_code>gsvd = GSVD(3, normalized=False)
embedding = gsvd.fit_transform(adjacency)
embedding.shape
# skip first component
position = embedding[:,1:]
image = svg_digraph(adjacency, position, names=names)
SVG(image)<jupyter_output>/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/networkx/drawing/nx_pylab.py:402: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
  if isinstance(alpha, collections.Iterable):
/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/networkx/drawing/nx_pylab.py:579: MatplotlibDeprecationWarning: 
The iterable function was deprecated in Matplotlib 3.1 and will be removed in 3.3. Use np.iterable instead.
  if not cb.iterable(width):<jupyter_text>**Metrics**<jupyter_code>cosine_modularity(adjacency, embedding)<jupyter_output><empty_output><jupyter_text>Bigraphs **Loading**<jupyter_code>graph = movie_actor(metadata=True)
biadjacency = graph.biadjacency
names_row = graph.names_row
names_col = graph.names_col<jupyter_output><empty_output><jupyter_text>**Embedding**<jupyter_code>gsvd = GSVD(3, normalized=False)
gsvd.fit(biadjacency)
embedding_row = gsvd.embedding_row_
embedding_row.shape
embedding_col = gsvd.embedding_col_
embedding_col.shape
# skip first component
position_row = embedding_row[:,1:]
position_col = embedding_col[:,1:]
image = svg_bigraph(biadjacency, names_row, names_col, 
                    position_row=embedding_row, position_col=embedding_col,
                    color_row='blue', color_col='red')
SVG(image)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10831234256926953, 'fraction_numerical': 0.017632241813602016, 'mean_word_length': 7.409411764705882, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 35, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '12359', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1286, 'n_tokens_neox': 1231, 'n_words': 212, 'path': 'docs/tutorials/embedding/gsvd.ipynb', 'repo_name': 'clbonet/scikit-network', 'size': '3573'}