Ollivier-Ricci Curvature (ORC) Lower Bounds via Residual-Shell Measures
Project description
ORC-Bound
ORC (Ollivier–Ricci Curvature) Lower Bounds via residual-shell Wasserstein-1 measures with k-hop lazy random walks.
Overview
This package implements lower bound algorithms for Ollivier–Ricci Curvature (ORC) on graph edges. For each edge (u, v) in a graph, it computes:
κ_lb(u, v) = 1 - W̄₁(μ_u, μ_v) / dist(u, v)
where μ_u is the k-hop lazy random walk measure at u and W̄₁ is the residual-shell upper bound on the 1-Wasserstein distance.
Features
- Residual-shell Ricci curvature with k-hop random walk support
- Multi-threaded edge processing — leverage all CPU cores for large graphs
- Sparse matrix output — memory efficient for large graphs
- Truncated APSP — avoids full all-pairs shortest path computation
Installation
pip install .
For development:
pip install -e ".[dev]"
For SerpAPI support:
pip install -e ".[serpapi]"
Quick Start
import networkx as nx
from orc_bound import residual_shell_ricci_approximation
# Build a graph
G = nx.watts_strogatz_graph(200, 6, 0.2, seed=0)
# Compute curvature with k=1-hop measures and 4 threads
C = residual_shell_ricci_approximation(
G,
G.number_of_nodes(),
k=1,
n_jobs=4,
)
# Average curvature over all edges
avg_curv = C.sum() / C.nnz
print(f"Average curvature: {avg_curv:.4f}")
API Reference
residual_shell_ricci_approximation
def residual_shell_ricci_approximation(
graph: nx.Graph,
num_nodes: int,
k: int = 1,
alpha_lazy: float = 0.0,
l_shell: int = 3,
rbar_mode: str = "local-max",
tol: float = 1e-12,
symmetric: bool = False,
n_jobs: int | None = None,
) -> csr_matrix:
| Parameter | Type | Default | Description |
|---|---|---|---|
graph |
nx.Graph |
— | Input graph |
num_nodes |
int |
— | Number of nodes (must match graph) |
k |
int |
1 |
Number of random walk steps (k-hop neighborhood) |
alpha_lazy |
float |
0.0 |
Lazy mixing parameter [0, 1] |
l_shell |
int |
3 |
Maximum shell distance for bucket matching |
rbar_mode |
str |
"local-max" |
Residual distance estimation method |
tol |
float |
1e-12 |
Numerical tolerance for mass pruning |
symmetric |
bool |
False |
Whether to populate both (u,v) and (v,u) entries |
n_jobs |
int | None |
None |
Number of parallel workers (None=all cores) |
Core Functions
build_lazy_measures_k(G, alpha_lazy, k)— Build k-hop lazy random walk measuresall_pairs_shortest_path_matrix_cutoff(G, cutoff)— Truncated APSP matrixresidual_shell_upper_bound(mu_x, mu_y, D, idx, l, ...)— W1 upper bound
Multi-Threading
The most expensive step — computing curvature for each edge — is fully parallelizable because each edge's computation is independent.
# Use all CPU cores (default)
C = residual_shell_ricci_approximation(G, n, k=10)
# Use exactly 8 workers
C = residual_shell_ricci_approximation(G, n, k=10, n_jobs=8)
# Use all but one core
C = residual_shell_ricci_approximation(G, n, k=10, n_jobs=-1)
Threading vs Multiprocessing
The algorithm is memory-bandwidth bound (dominated by numpy array operations on the precomputed distance matrix), not CPU-bound. Threading avoids the GIL for numpy operations and sidesteps the serialization overhead of multiprocessing, making ThreadPoolExecutor the natural choice.
Web Search via SerpAPI
The package includes a utility for fetching related literature:
from orc_bound.utils.search import search_orc_literature
# Search for ORC-related papers
results = search_orc_literature(
query="Ollivier Ricci curvature graph networks",
num_results=10,
serpapi_key="your-serpapi-key",
)
License
MIT License
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 orc_bound-0.1.1.tar.gz.
File metadata
- Download URL: orc_bound-0.1.1.tar.gz
- Upload date:
- Size: 15.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
df31123c95bf2c9348829b121f989ca154b3535704b25fcf411672cde9d04280
|
|
| MD5 |
2e9f468789a173eecb3dc1d17edf9ab6
|
|
| BLAKE2b-256 |
a6b3d9b1d999d875c938f1df0e55f29f5dda3baf3ec42b6e932eb57af52cc8d7
|
File details
Details for the file orc_bound-0.1.1-py3-none-any.whl.
File metadata
- Download URL: orc_bound-0.1.1-py3-none-any.whl
- Upload date:
- Size: 14.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3bb6e87ec0789348983beb47155275313bba3f40f32dcead4c65b83ef08c5618
|
|
| MD5 |
b6b4848223548ff1762b37532039e980
|
|
| BLAKE2b-256 |
7c731d5f1a9468643fe1d734bf40ba1252aa79d87cc5b30fd1222220947c84cd
|