Katz centrality

This notebook illustrates the ranking of the nodes of a graph by Katz centrality, a weighted average of number of paths of different lengths to each node.

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

Graphs

[4]:
graph = karate_club(metadata=True)
adjacency = graph.adjacency
position = graph.position
[5]:
katz = Katz()
scores = katz.fit_transform(adjacency)
[6]:
image = svg_graph(adjacency, position, scores=scores)
SVG(image)
[6]:
../../_images/tutorials_ranking_katz_8_0.svg

Directed graphs

[7]:
graph = painters(metadata=True)
adjacency = graph.adjacency
names = graph.names
position = graph.position
[8]:
katz = Katz()
scores = katz.fit_transform(adjacency)
[9]:
image = svg_digraph(adjacency, position, scores=scores, names=names)
SVG(image)
[9]:
../../_images/tutorials_ranking_katz_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]:
katz = Katz()
katz.fit(biadjacency)
scores_row = katz.scores_row_
scores_col = katz.scores_col_
[12]:
image = svg_bigraph(biadjacency, names_row, names_col, scores_row=scores_row, scores_col=scores_col)
SVG(image)
[12]:
../../_images/tutorials_ranking_katz_16_0.svg