Domain-agnostic sparse network inference from tabular data
Project description
sparselink
Domain-agnostic sparse network inference from tabular data.
sparselink provides a unified Python interface for 20+ network inference algorithms — from LASSO and graphical models to causal discovery and deep learning approaches. All methods share a single fit(X) -> InferenceResult API, making it easy to swap algorithms, benchmark them on synthetic data, and compare results.
Installation
pip install sparselink
Optional extras:
pip install sparselink[causal] # PC, FCI (causal-learn)
pip install sparselink[deep] # DAG-GNN (PyTorch)
pip install sparselink[dev] # pytest, mypy, ruff
Quick Start
import numpy as np
from sparselink import get_method
X = np.random.default_rng(42).standard_normal((100, 20))
method = get_method("lasso")
result = method(alpha=0.01).fit(X)
print(result.adjacency_matrix.shape) # (20, 20)
print(result.edge_list[:5]) # [(src, tgt, weight), ...]
Available Methods
| Category | Methods |
|---|---|
| Regularization | Lasso, Elastic Net, Ridge, LSCO |
| Information-theoretic | CLR, Partial Correlation |
| Graphical models | Graphical LASSO, GLASSO+StARS, Neighborhood Selection |
| Tree / stability | GENIE3, TIGRESS |
| Causal (time-series) | PCMCI, Granger Causality, Transfer Entropy |
| Constraint-based | PC, FCI |
| Continuous optimization | NOTEARS, DAG-GNN |
| Bayesian | BDeu, BGe |
from sparselink import list_methods
print(list_methods())
Method Registry
Methods are registered via the @registry.register decorator and discovered automatically at import time. Use get_method(name) to retrieve any method by its string name — no direct imports needed in application code.
Benchmarking
sparselink includes a benchmarking suite with synthetic network/data generation and evaluation metrics for comparing algorithm performance.
Python API
from sparselink.bench import generate_network, generate_data, evaluate
from sparselink import get_method
net = generate_network(20, topology="scalefree", sparsity=0.1, seed=0)
X = generate_data(net, n_samples=100, noise_std=0.1, seed=0)
result = get_method("genie3")().fit(X)
metrics = evaluate(net, result.adjacency_matrix)
print(f"AUROC={metrics.auroc:.3f} F1={metrics.f1:.3f}")
CLI
# Interactive mode
sparselink
# Infer a network from data
sparselink infer data.csv --method lasso
# Run benchmark
sparselink bench --tier fast,medium --timeout 60
# List available methods
sparselink methods
# System status
sparselink status
# Show previous results
sparselink show benchmark_results.json
Evaluation Metrics
- AUROC, AUPR (threshold-free)
- Precision, Recall, F1, FDR, MCC (best over threshold sweep)
- R² (edge weight accuracy)
Project Structure
src/sparselink/
├── base.py # InferenceMethod ABC
├── types.py # AdjacencyMatrix, EdgeList, InferenceResult
├── registry.py # @registry.register decorator + discovery
├── accel.py # Optional MLX acceleration (Apple Silicon)
├── methods/ # One module per algorithm
└── bench/ # Synthetic data, metrics, runner, CLI
Development
pip install -e ".[dev]"
pytest # tests + coverage (80% gate)
mypy src/ # strict type checking
ruff check src/ tests/ # lint
ruff format src/ tests/ # format
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sparselink-1.0.0.tar.gz.
File metadata
- Download URL: sparselink-1.0.0.tar.gz
- Upload date:
- Size: 209.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e6273645e2075fb4f13051522e8e84083d285ca04c5400dc5dca49da5bd7ff1d
|
|
| MD5 |
413977d43301a466152584b5d5749aa0
|
|
| BLAKE2b-256 |
56239a77d103a74c5916421e73cef4c0b0f3896eac9ec1929d8fbd34f10ce38a
|
File details
Details for the file sparselink-1.0.0-py3-none-any.whl.
File metadata
- Download URL: sparselink-1.0.0-py3-none-any.whl
- Upload date:
- Size: 52.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
265fe21991a431a7a27085f60832d977a176a7d9fab44f0ab3edc65d0ace6c01
|
|
| MD5 |
817a60bf05484e6190470edee0b51b6e
|
|
| BLAKE2b-256 |
74f0098e339011d0b7be85946b9903a1b5e56d2ffc300d0f4d089c17fb9de934
|