An implementation of separation distances and s/c-metrics for causal graphs as introduced in the paper 'Separation-based distance metrics for causal graphs'.
Project description
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.
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 sep_distances-1.0.2.tar.gz.
File metadata
- Download URL: sep_distances-1.0.2.tar.gz
- Upload date:
- Size: 39.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
93f2c3716cdfa2edf03b4d771ae57283f708ed66509f2ca9c12f76666c9e13fe
|
|
| MD5 |
6ee110f9bf5350b0a2b4a032cebdc29a
|
|
| BLAKE2b-256 |
a76e8c184ce2dec0ece88983d91dcc1ea25f1537a30b44d05e21de03f37f0172
|
File details
Details for the file sep_distances-1.0.2-py3-none-any.whl.
File metadata
- Download URL: sep_distances-1.0.2-py3-none-any.whl
- Upload date:
- Size: 31.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
27d5e9ef7072c279400dc00de892aa307e5935b0c71d1ade8c036d35d5c17d49
|
|
| MD5 |
f9d3af943b0e0cc310aac04f7fafa5a5
|
|
| BLAKE2b-256 |
68101003475d6f51f2d30381acea6095bc62f84200e11eb16e21da48c57e2a3a
|