<jupyter_start><jupyter_text>Connected components This notebook illustrates the search for [connected components](https://en.wikipedia.org/wiki/Component_(graph_theory)) in graphs.<jupyter_code>from IPython.display import SVG
import numpy as np
from sknetwork.data import karate_club, painters, movie_actor
from sknetwork.topology import get_connected_components
from sknetwork.visualization import svg_graph, svg_digraph, svg_bigraph
from sknetwork.utils.format import bipartite2undirected<jupyter_output><empty_output><jupyter_text>Graphs<jupyter_code>graph = karate_club(metadata=True)
adjacency = graph.adjacency
position = graph.position
# subgraph
k = 15
adjacency = adjacency[:k][:,:k]
position = position[:k]
# connected components
labels = get_connected_components(adjacency)
image = svg_graph(adjacency, position, labels=labels)
SVG(image)<jupyter_output><empty_output><jupyter_text>Directed graphs<jupyter_code>graph = painters(metadata=True)
adjacency = graph.adjacency
names = graph.names
position = graph.position
# weak connected components
labels = get_connected_components(adjacency)
image = svg_digraph(adjacency, position=position, names=names, labels=labels)
SVG(image)
# strong connected components
labels = get_connected_components(adjacency, connection='strong')
image = svg_digraph(adjacency, position, names, labels)
SVG(image)<jupyter_output>/Users/thomas/Documents/github/scikit-network/sknetwork/visualization/graphs.py:93: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison
  if name_position == 'left':
/Users/thomas/Documents/github/scikit-network/sknetwork/visualization/graphs.py:98: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison
  elif name_position == 'right':
/Users/thomas/Documents/github/scikit-network/sknetwork/visualization/graphs.py:109: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison
  if name_position == 'above':
/Users/thomas/Documents/github/scikit-network/sknetwork/visualization/graphs.py:340: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison
  if position == 'left':
/Users/thomas/Documents/github/scikit-n[...]<jupyter_text>Bipartite graphs<jupyter_code>graph = movie_actor(metadata=True)
biadjacency = graph.biadjacency
names_row = graph.names_row
names_col = graph.names_col
# subgraph
k = 5
biadjacency = biadjacency[k:]
names_row = names_row[k:]
adjacency = bipartite2undirected(biadjacency)
labels = get_connected_components(adjacency)
n_row, _ = biadjacency.shape
labels_row = labels[:n_row]
labels_col = labels[n_row:]
image = svg_bigraph(biadjacency, names_row, names_col, labels_row, labels_col)
SVG(image)<jupyter_output><empty_output>