graphy tutorial

Example

Here we find a high-modularity decomposition of the karate-club network.

graphy.partitions - Module to search over partitions implements search over decompositions. After getting a matrix, we need to create a cost function object (a subclass of graphy.qualityfuncs.QualityFunction), then use the find_optimal method. This returns a membership vector, which, for an N-dimensional system, is an N-dimensional integer-valued numpy array indicating the community each component belongs to.

import numpy as np
import networkx as nx
import graphy

G = nx.karate_club_graph()
qualityObj = graphy.qualityfuncs.Modularity(nx.to_numpy_array(G))
best_membership, q = qualityObj.find_optimal()
graphy.plotting.plot_graph(G, pos=nx.spring_layout(G), colors=best_membership)

(Source code, png, hires.png, pdf)

_images/karate.png