This repository provides an implementation of separation distances and s/c-metrics for causal graphs as introduced in the paper 'Separation-based distance metrics for causal graphs'.
You can install it as a package using pip install sep-distances. The test suite is not part of the package on pypi, but it is still available on the official github repo.
Below is a short description of the important source files and how to use them.
Usage
-
from sep_distances.mixed_graph import ...- Contains the
LabelledMixedGraphclass: a compact representation for directed, undirected, bidirected and semidirected edges. Useful helpers include conversion to/from NetworkX, adding/removing edges, methods to compute skeletons and CPDAGs, finding v-structures, computing Markov blankets, BayesBall, minimal d-separators and several converters (get_canonical_directed_graph,get_acyclification, etc.). This is the main graph data structure used by the metrics.
- Contains the
-
from sep_distances.metrics import ...- Implements the distance/metric functions comparing two graphs. Major groups of functions:
- SHD (Structural Hamming Distance) for DAGs/CPDAGs/MAGs:
SHD_DAGs,SHD_CPDAGs,SHD_MAGs. - AID (Adjustment Identification Distances) wrappers using
gadjid(e.g.parent_AID_DAGs). - Separation distances (SD) for DAGs, CPDAGs, and mixed graphs:
SD_DAGs,SD_CPDAGs,SD_mixed_graphs. - s/c-metrics and variants (s-metric, c-metric, sc-metric) for DAGs, CPDAGs, mixed graphs and
graphs with cycles (
metric_DAGs,metric_CPDAGs,metric_mixed_graphs,metric_directed_cyclic_graphs). - Utilities:
generate_triples(create separation statements) and several helper wrappers.
- SHD (Structural Hamming Distance) for DAGs/CPDAGs/MAGs:
- Implements the distance/metric functions comparing two graphs. Major groups of functions:
Quick example
Basic usage pattern (import, construct graphs, compute a metric):
from sep_distances import mixed_graph as mg
from sep_distances import metrics as metrics
# create two simple DAGs
G1 = mg.LabelledMixedGraph(nodes={"A", "B", "C"})
G1.add_directed("A", "B")
G1.add_directed("B", "C")
G2 = mg.LabelledMixedGraph(nodes={"A", "B", "C"})
G2.add_directed("A", "B")
G2.add_directed("A", "C")
# Compute SHD (Structural Hamming Distance) between DAGs
shd = metrics.SHD_DAGs(G1, G2, normalized=True)
print("SHD (normalized):", shd)
# Compute separation distance (SD) using parent separation
sd = metrics.SD_DAGs(G1, G2, type='parent', normalized=True)
print("SD (parent, normalized):", sd)
# Compute an sc-metric between DAGs (default uses all orders)
sc = metrics.metric_DAGs(G1, G2, type='sc', normalized=True)
print("sc-metric:", sc)
Notes:
- Many metric functions expect the same node set in both graphs. They typically check
graph1.nodes == graph2.nodes. - For CPDAGs some functions compute or require a representative DAG of the MEC (see
get_representative_of_MEC). - AID functions rely on the external
gadjidpackage; install it to use those functions.
Installation / requirements
- Python 3.10+ is required (see
setup.py). - The project depends on packages listed in
requirements.txt/setup.py. Notable dependencies:networkx,numpy,scipy,gadjid(optional but required for AID functions).
License
This project is released under the GNU General Public License v3 (GPLv3). See LICENSE.txt for the full text.
Contact & attribution
Original research and initial code: Jonas Wahl & Jakob Runge.
Package implementation and maintenance: Muhammad Haris Owais Ahmed.
If you have questions, bug reports, or performance suggestions, please open an issue or contact the maintainers listed in setup.py.
CHANGELOG:
[1.0.2] - 18-11-2025
Fixed
- Accidentally pushed the wrong build onto pypi. This one has the test suite removed as described for v1.0.1. Also removed utils.py, a legacy file that served no purpose.
[1.0.1] - 18-11-2025
Fixed
- Tests included in the package would not work, missing ground truths. Incorporating test suite into package would have required major overhaul of files and project structure. Removed test suite from package because it's not that important. Tests are still available on the official git repo.
Metadata
Release files for sep-distances 1.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sep_distances-1.0.2.tar.gz | 39.2 kB | Without provenance | Details for sep_distances-1.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sep_distances-1.0.2-py3-none-any.whl | Python 3 | none | any | Details for sep_distances-1.0.2-py3-none-any.whl |
Total release size: 70.7 kB
Release files / sep_distances-1.0.2.tar.gz
| Download URL | sep_distances-1.0.2.tar.gz |
|---|---|
| Size | 39.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
93f2c3716cdfa2edf03b4d771ae57283f708ed66509f2ca9c12f76666c9e13fe
|
|
BLAKE2b-256 checksum How to use checksums |
a76e8c184ce2dec0ece88983d91dcc1ea25f1537a30b44d05e21de03f37f0172
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Release files / sep_distances-1.0.2-py3-none-any.whl
| Download URL | sep_distances-1.0.2-py3-none-any.whl |
|---|---|
| Size | 31.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
27d5e9ef7072c279400dc00de892aa307e5935b0c71d1ade8c036d35d5c17d49
|
|
BLAKE2b-256 checksum How to use checksums |
68101003475d6f51f2d30381acea6095bc62f84200e11eb16e21da48c57e2a3a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Security for sep-distances 1.0.2
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.