Skip to main content

Rapid and exact partitioning algorithms for graphs embedded in one dimension.

Project description

dyvider is a small library implementing dynamic programming algorithms for exact linear clustering in networks. Its algorithms process networks whose nodes have positions in one dimension, and return their optimal partition.

The theory and experiments exploring this code can be found in the paper “Exact and rapid linear clustering of networks with dynamic programming”, by Alice Patania, Antoine Allard and Jean-Gabriel Young.

Dependencies

The only necessary dependency are networkx and numpy.

Quick tour

The following minimal example first assigns scores to nodes with a one-dimensional spectral embedding and then retrieves an optimal linear clustering from this embedding using dyvider.

import networkx as nx
import dyvider as dy
import numpy as np

# create a graph
g = nx.stochastic_block_model([10, 10], [[0.5, 0.05], [0.05, 0.5]], seed=42)

# generate a 1-d embedding with the leading eigenvector of the modularity matrix
eigenvals, eigvenvecs = np.linalg.eig(nx.linalg.adjacency_matrix(g).todense())
score = {v: float(eigvenvecs[v, 0]) for v in g.nodes()}

# set the node positions
nx.set_node_attributes(g, score, 'score')

# run dyvider
g = dy.utilities.preprocess(g)
objective_function = dy.objectives.Modularity()
solution, Q = dy.algorithms.run(g, objective_function)

print(solution)

The expected output is:

>>> [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; [10, 11, 12, 13, 14, 15, 16, 17, 18, 19]]

Our tutorial goes into more detail and demonstrates all the API calls.

Paper

If you use this code, please consider citing:

Exact and rapid linear clustering of networks with dynamic programmingAlice Patania, Antoine Allard and Jean-Gabriel Young. arXiv:2301.10403.

Author information

Code by Jean-Gabriel Young. Don’t hesitate to get in touch at jean-gabriel.young@uvm.edu, or via the issues!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dyvider-0.3.tar.gz (13.0 kB view details)

Uploaded Source

File details

Details for the file dyvider-0.3.tar.gz.

File metadata

  • Download URL: dyvider-0.3.tar.gz
  • Upload date:
  • Size: 13.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.9

File hashes

Hashes for dyvider-0.3.tar.gz
Algorithm Hash digest
SHA256 9b11df48ebb6bac594a5b22eca744c04ddf3f7f8237518f69ba8cb086bcc4236
MD5 88c07312695d3b34c0a01d5cf4730ea0
BLAKE2b-256 f99c973a0d2e32c9783c2dd96e952ee1b2508c774bc224f14d4068033ce03eaf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page