Skip to main content

nx-backbone

Backbone extraction algorithms for complex networks, built on NetworkX.

This library provides about 110 functions across 14 modules for extracting backbone structures from weighted, unweighted, bipartite, temporal, and higher-order (hypergraph) networks. The public API is type-annotated (py.typed), and the graph-in, graph-out functions dispatch to NetworkX backends such as nx-parallel.

Full documentation: https://www.brianckeegan.com/nx-backbone/

Installation

pip install nx-backbone

For full functionality (required for statistical tests, bipartite methods, and some structural methods):

pip install nx-backbone[full]

Or install from source:

git clone https://github.com/brianckeegan/nx-backbone.git
cd nx-backbone
pip install -e ".[full]"

Modules

Module Description Key Functions
statistical Hypothesis-testing methods disparity_filter, noise_corrected_filter, marginal_likelihood_filter, ecm_filter, lans_filter, multiple_linkage_analysis, polya_filter, gloss_filter
structural Topology-based methods global_threshold_filter, strongest_n_ties, global_sparsification, primary_linkage_analysis, edge_betweenness_filter, node_degree_filter, high_salience_skeleton, metric_backbone, ultrametric_backbone, doubly_stochastic_filter, h_backbone, modularity_backbone, planar_maximally_filtered_graph, maximum_spanning_tree_backbone
proximity Neighborhood-similarity scoring jaccard_backbone, dice_backbone, cosine_backbone, hub_promoted_index, hub_depressed_index, adamic_adar_index, resource_allocation_index, local_path_index, and more
hybrid Combined approaches glab_filter
bipartite Bipartite projection backbones simple_projection, hyper_projection, probs_projection, ycn_projection, sdsm, fdsm, fixedfill, fixedrow, fixedcol, backbone, backbone_from_projection, backbone_from_weighted, backbone_from_unweighted
hypergraph Higher-order (hypergraph) backbones mdl_hypergraph_backbone, local_mdl_hypergraph_backbone, hypergraph_compression_ratio, intersection_graph, maximal_hyperedges, order_filter, s_components, statistically_validated_hypergraph, statistically_validated_cores
hypergraph_io Hypergraph ingestion and interoperability hypergraph_to_bipartite, read_hif, write_hif, from_xgi/to_xgi, from_hypernetx/to_hypernetx, from_hypergraphx/to_hypergraphx, from_hat/to_hat
unweighted Sparsification for unweighted graphs sparsify, lspar, local_degree
convert Array and data-frame input to_graph (NumPy/SciPy sparse adjacency matrices, pandas edge lists)
filters Post-hoc filtering and preprocessing threshold_filter, fraction_filter, boolean_filter, consensus_backbone, adjust_pvalues, multigraph_to_weighted, transform_weights
temporal Temporal networks: snapshots, events, and spans temporal_form, convert_temporal, flatten_temporal, snapshots_from_events, snapshots_from_spans, events_from_snapshots, spans_from_snapshots, from_event_table, to_event_table
measures Evaluation and comparison node_fraction, edge_fraction, weight_fraction, reachability, ks_degree, ks_weight, compare_backbones
visualization Graph comparison plotting graph_difference, compare_graphs, save_graph_comparison
describe Methods text and citations describe_backbone

NetBone Core Coverage

Core method families used in netbone (Yassin et al., 2023) are represented here, including:

  • Statistical: disparity_filter, marginal_likelihood_filter, ecm_filter, noise_corrected_filter, lans_filter, multiple_linkage_analysis, polya_filter, gloss_filter
  • Structural: global_threshold_filter, global_sparsification, primary_linkage_analysis, edge_betweenness_filter, high_salience_skeleton, doubly_stochastic_filter, maximum_spanning_tree_backbone
  • Hybrid: glab_filter

docs/design/yassin-2025-coverage.md checks the package method by method against the two comparative studies by Yassin et al. (2025). It covers all 15 methods, including the Pólya urn and GloSS filters.

Every backbone model in Neal's Backbone 3.0 R package is also covered (disparity, mlf, lans, sdsm, fdsm, fixedfill/fixedrow/fixedcol, bicm, fastball, and the backbone_from_* wrappers), including its hypergraph-projection input via hypergraph_to_bipartite, plus its cross-cutting features: multiple-testing correction (adjust_pvalues, threshold_filter(mtc=...)), signed backbones (signed=True adds a sign edge attribute), and SDSM-EC edge constraints (sdsm(prohibited=, required=)). See docs/design/backbone-3.0-coverage.md for the full coverage analysis.

Quick Start

import networkx as nx
import nx_backbone as nb

# Create a weighted graph
G = nx.les_miserables_graph()

# 1) Score edges
scored = nb.disparity_filter(G)

# 2) Filter edges
backbone = nb.threshold_filter(scored, "disparity_pvalue", 0.05)

# Compare backbone to original
print(f"Edges kept: {nb.edge_fraction(G, backbone):.1%}")
print(f"Nodes kept: {nb.node_fraction(G, backbone):.1%}")

Significance options: multiple-testing correction and signed backbones

# Correct p-values for the number of edges tested (Bonferroni, Holm, BH/FDR, BY)
backbone = nb.threshold_filter(scored, "disparity_pvalue", 0.05, mtc="bh")

# Signed backbone: keep significantly strong (+1) and significantly weak (-1)
# edges under a two-tailed test; read direction from the "sign" attribute
signed = nb.disparity_filter(G, signed=True)
strong = nb.threshold_filter(signed, "disparity_pvalue", 0.05, mtc="holm")
positives = [(u, v) for u, v, d in strong.edges(data=True) if d["sign"] == 1]

Reporting a backbone (methods text and citations)

describe_backbone writes a methods paragraph for the backbone you extracted: the method and its null model, the parameters, the multiple-testing correction, the share of nodes, edges and weight kept, and the citations (including this package and its version). It is the counterpart of Backbone 3.0's narrative option.

print(nb.describe_backbone("disparity_filter", alpha=0.05, mtc="bh",
                           original=G, backbone=backbone))
print(nb.describe_backbone("disparity_filter", style="bibtex"))  # BibTeX entries

See the Validating a backbone tutorial for multiple-testing correction, method comparison, consensus and signed backbones end to end. To cite the package itself, use CITATION.cff.

Disparity filter visualization

Disparity filter on Les Miserables

Proximity-based scoring

# Score edges by Jaccard similarity of endpoint neighborhoods
scored = nb.jaccard_backbone(G)

# Keep only the top 20% most structurally embedded edges
backbone = nb.fraction_filter(scored, "jaccard", 0.2, ascending=False)

Bipartite backbone

B = nx.davis_southern_women_graph()
women_nodes = [n for n, d in B.nodes(data=True) if d["bipartite"] == 0]
scored = nb.sdsm(B, agent_nodes=women_nodes, projection="hyper")
backbone = nb.threshold_filter(scored, "sdsm_pvalue", 0.05, mode="below")

Projection weights follow the simple/hyper/ProbS/YCN formulations compared by Coscia & Rossi (2019) (arXiv:1906.09081). Their "hyperbolic" weight is 1/d(z) per shared artifact; pass hyper_projection(..., newman=True) (or projection="newman") for Newman's (2001) 1/(d(z) - 1) collaboration weight, which matches nx.bipartite.collaboration_weighted_projected_graph.

Every bipartite function also takes an agents x artifacts incidence matrix (NumPy, SciPy sparse or pandas) instead of a graph, as R backbone does. The incidence stays sparse and pairs are scored in blocks of agent rows:

import scipy.sparse as sp

M = sp.random_array((20_000, 5_000), density=0.01, format="csr")
M.data[:] = 1
backbone = nb.backbone_from_projection(M, method="sdsm", alpha=0.01)

Hypergraph backbones

Backbone a hypergraph (a collection of arbitrary-size hyperedges) directly:

# Parameter-free MDL backbone -- prunes nested/redundant hyperedges
# (Kirkley, Felippe, Malizia & Battiston, 2026)
H = [(1, 2, 3, 4), (1, 2, 3), (2, 3, 4), (8, 9)]
result = nb.mdl_hypergraph_backbone(H)          # method="auto" runs both greedy
print(result.backbone)            # [frozenset({1, 2, 3, 4}), frozenset({8, 9})]
print(result.compression_ratio)   # inverse compression ratio eta
# method="edge" (fastest single pass) or "node" are also available

# Statistically validated hypergraph (Musciotto, Battiston & Mantegna, 2021)
events = [(1, 2)] * 5 + [(3, 4)] * 100          # repeats = interaction counts
svh = nb.statistically_validated_hypergraph(events, alpha=0.05)

Interoperate with the higher-order ecosystem (all optional, lazily imported), or reuse the bipartite projection backbones via the incidence graph:

B, nodes = nb.hypergraph_to_bipartite(H)        # -> NetworkX bipartite graph
scored = nb.sdsm(B, agent_nodes=nodes)          # projection backbone of a hypergraph

nb.write_hif(H, "graph.hif")                    # HIF interchange (xgi/HNX/HGX/HAT)
edges = nb.from_xgi(xgi_hypergraph)             # xgi / hypernetx / hypergraphx / hat

Temporal networks

A network observed over time can be a dict of snapshots, a MultiGraph of timestamped events, or a MultiGraph of spans with start/end. The temporal module converts between the three forms and collapses any of them into one static weighted graph for the methods above:

M = nb.from_event_table(df)                       # pandas: source, target, time
weekly = nb.snapshots_from_events(M, freq="7D")   # bin events into snapshots
H = nb.flatten_temporal(M, aggregate="count")     # one weighted edge per pair
backbone = nb.threshold_filter(nb.disparity_filter(H), "disparity_pvalue", 0.05)

Temporal backbone scores (observation_fraction, persistence, backbone_stability, weight_trend) and kalman_backbone, which smooths per-step significance over time with a Kalman filter, return one scored static graph; a persistence HMM is on the roadmap.

Comparing multiple methods

backbones = {
    "disparity": nb.threshold_filter(nb.disparity_filter(G), "disparity_pvalue", 0.05),
    "mst": nb.boolean_filter(nb.maximum_spanning_tree_backbone(G), "mst_keep"),
}
results = nb.compare_backbones(G, backbones)

Dependencies

  • Required: Python >= 3.12, networkx >= 3.4 (version floors match NetworkX's own)
  • Optional: numpy >= 2.2, scipy >= 1.15 ([full]: some statistical methods, bipartite null models, SVH/SVC, doubly_stochastic_filter, local_path_index, KS measures) and matplotlib >= 3.10 ([viz]: visualization helpers and the docs gallery). Calling a function whose optional dependency is missing raises ImportError; the pure-Python methods work with NetworkX alone.
  • pandas (optional, lazily imported): data-frame input (to_graph, bipartite incidence tables), pandas event tables (from_event_table, to_event_table), and frequency strings such as freq="1D" in the temporal module. Install it separately (pip install pandas). transform_weights accepts scikit-learn transformers by duck typing, so scikit-learn is never required.
  • Backends (optional): install a NetworkX backend such as nx-parallel and pass backend="parallel" (see the backends user-guide page).
  • Hypergraph interop (optional, lazily imported): xgi >= 0.9.1, hypernetx >= 2.3.10, hypergraphx >= 1.7.7, HypergraphAnalysisToolbox >= 1.1.18 (extras [xgi], [hypernetx], [hypergraphx], [hat], or all four with [interop])

Testing

pip install -e ".[dev]"
pytest --doctest-modules nx_backbone tests   # tests + docstring examples
ruff check nx_backbone tests && ruff format --check nx_backbone tests

Roadmap

Planned work, open gaps, and recently completed milestones are tracked in the roadmap (source).

Backbone visualizations in the docs are generated with Sphinx Gallery from example scripts under docs/examples/.

Build docs (including the graph comparison gallery and function-linked visualizations):

pip install -e ".[docs]"
sphinx-build -b html docs docs/_build/html

References

Key papers behind the implemented methods:

Other libraries and datasets:

License

BSD 3-Clause License. See LICENSE for details.

Metadata

Release files for nx-backbone 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nx-backbone 0.3.0
File Size Uploaded Provenance Actions
nx_backbone-0.3.0.tar.gz 750.1 kB With provenance Details for nx_backbone-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for nx-backbone 0.3.0
File Interpreter ABI Platform Actions
nx_backbone-0.3.0-py3-none-any.whl Python 3 none any Details for nx_backbone-0.3.0-py3-none-any.whl

Total release size: 991.0 kB

Release files / nx_backbone-0.3.0.tar.gz

Download URL nx_backbone-0.3.0.tar.gz
Size 750.1 kB
Tags Source
SHA-256 checksum
How to use checksums
b328a4684e556a9843b5afe8e152f413ad4c27a3c2b9cb55dbf35baae278f304
BLAKE2b-256 checksum
How to use checksums
558a1903d8455568a2b1172132058540bfad4fc06d01827455559e19bca43e64
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 2, 2026.

Transparency log

Release files / nx_backbone-0.3.0-py3-none-any.whl

Download URL nx_backbone-0.3.0-py3-none-any.whl
Size 240.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e2af927364fced6bc2cadc1ec840cf18ee00dfb6fe5f0c5cb91e960d05a59357
BLAKE2b-256 checksum
How to use checksums
68f5f9f3f52da0dbb4383e489bd6de683188d4d3a203fb1794ad7a4c93d0cdfc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 2, 2026.

Transparency log

Security for nx-backbone 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for nx_backbone-0.3.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 2, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page