Skip to main content

Diffusion Ordered Temporal Structure (DOTS)

This repository accompanies the paper "Causal Ordering for Structure Learning from Time Series" published in Transactions on Machine Learning Research (link to the paper).

See also: Time Series Causal Discovery Benchmark (used to run experiments).

Reproducing the paper? Use the tmlr-2025 release. It contains the exact code and conda environment used for the paper's results. The main branch holds the actively maintained dots-causal Python package, which may change over time.

Installation

pip install dots-causal

or, from a clone of this repository:

pip install -e .

Requirement: R with mgcv

The final pruning step of DOTS (CAM pruning) runs in R. You need:

  1. R installed, with Rscript on your PATH (CRAN).

  2. The mgcv R package:

    Rscript -e 'install.packages("mgcv", repos = "https://cloud.r-project.org")'
    

If R or mgcv is missing, DOTS.fit raises dots_causal.RNotFoundError with instructions.

Alternatively, conda can install Python, R and mgcv together. From the repository root:

conda env create -f environment.yml
conda activate dots

A GPU is used automatically when PyTorch detects CUDA; otherwise DOTS runs on CPU.

Quick start

Pass your time series as it is (one column per variable, rows in time order) and choose how many past time steps to consider:

import pandas as pd
from dots_causal import DOTS

data = pd.read_csv("data/samples.csv")                # columns: X1, X2, X3
graph = DOTS(max_lag=1, random_state=0).fit(data)

graph is a pandas DataFrame over the lagged variables (X1_lag0, X2_lag0, X3_lag0, X1_lag1, ..., where lag0 is the current time step and lag1 the previous one). graph.loc[cause, effect] == 1 means an estimated edge, e.g. graph.loc["X1_lag1", "X2_lag0"] is an effect of X1 on X2 one time step later. NumPy arrays work too (variables are then named X1, X2, ...). random_state is optional and makes runs reproducible.

Options

Parameter Default Meaning
max_lag 1 Number of past time steps considered as causes.
voting_threshold 0.0 DOTS combines several causal orderings by voting. A candidate edge must agree with more than this fraction of them (before pruning). 0.0 = any ordering (as in the paper); higher = sparser.
n_orderings 10 How many diffusion time steps are used to compute orderings (n_orderings + 1 orderings with the defaults).
normalize True Standardise each variable to zero mean and unit variance before training.
allow_instantaneous False Also allow edges within the same time step.
pruning_cutoff 0.001 Significance level of the final pruning step: a candidate parent is kept if its p-value is below this. Higher = more edges.
random_state None Seed for reproducible results.

Training settings (epochs, batch_size, learning_rate, ...) are listed in help(DOTS). To see the lagged data DOTS works with, use dots_causal.make_lagged(data, max_lag).

Evaluating against a known graph

from dots_causal import perform_eval, read_json

graphs_true = read_json("data/graphs_true.json")
print(perform_eval(graphs_true, graph))

Demo

From the repository root, run sh setup-run.sh to create the conda environment and run the demo in one step, or after installing:

python demo.py

There is also an interactive notebook demo.

Replicating Experiments

You can use the TSCD Benchmark to fully replicate our results in an end-to-end manner.

Cite Us

@article{sanchez2025causal,
title={Causal Ordering for Structure Learning from Time Series},
author={Pedro Sanchez and Damian Machlanski and Steven McDonagh and Sotirios A. Tsaftaris},
journal={Transactions on Machine Learning Research},
issn={2835-8856},
year={2025},
url={https://openreview.net/forum?id=hWuTzqggSd}}

Metadata

Release files for dots-causal 0.2.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 dots-causal 0.2.0
File Size Uploaded Provenance Actions
dots_causal-0.2.0.tar.gz 32.8 kB With provenance Details for dots_causal-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for dots-causal 0.2.0
File Interpreter ABI Platform Actions
dots_causal-0.2.0-py3-none-any.whl Python 3 none any Details for dots_causal-0.2.0-py3-none-any.whl

Total release size: 63.4 kB

Release files / dots_causal-0.2.0.tar.gz

Download URL dots_causal-0.2.0.tar.gz
Size 32.8 kB
Tags Source
SHA-256 checksum
How to use checksums
b7a93886b9623e38f3c08ee9305a32138738fadb111e95920eaed3b0e5d7c25e
BLAKE2b-256 checksum
How to use checksums
2fbcdd480c4617062bda329682050209583386550189ff4639569b1907fad361
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 28, 2026.

Transparency log

Release files / dots_causal-0.2.0-py3-none-any.whl

Download URL dots_causal-0.2.0-py3-none-any.whl
Size 30.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e92a2f8da95d721a2d2d273a5e4af8e3530eacaf0eff6ae06be5efe7089071c1
BLAKE2b-256 checksum
How to use checksums
36f3df0a17a8b8b51071a0523a4c2e4ab1028cff6ad3aefdcd0a65687958cef5
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 28, 2026.

Transparency log

Security for dots-causal 0.2.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

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for dots_causal-0.2.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 28, 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.

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