SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2206.02013 · NeurIPS · 2022

Causal Discovery in Heterogeneous Environments Under the Sparse Mechanism Shift Hypothesis

Bernhard Schölkopf, Julius Von Kügelgen, Ronan Perry

arXiv · PDF · Open in the Atlas

Code that ran

9 of 13 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (0 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 0 violated it and 9 have no contract verdict; 0 failures of our instrument; 4 no recorded run), measured 2026-11-22; repository links from the Papers with Code archive attributed under CC BY-SA, no affiliation; bodies inline only under a permissive licence as GitHub detects it. Not a reproduction of the paper's results.

"Ran" means the function executed on a synthesized input and returned a value. It is not a reproduction of the paper's results. This record, dated, as JSON: /api/ran/2206.02013.json · badge: /api/ran/2206.02013.svg

Each repository's role is a label: a classifier's output recorded on the link, or, where no role is recorded, what the Papers with Code archive marked. The line under it names its basis. Neither says who wrote the code.

RepositoryRoleRan
rflperry/sparse_shift canonical (classifier label)
classifier basis not recorded on the link
9 ran · 4 no recorded run
FunctionStatusWhere it lives
check_2d Ran
ran on a synthesized input
rflperry/sparse_shift/sparse_shift/utils.py
code served (permissive licence) · get_code("ebb3c0ef7ce41cdf")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned ndarray, ndim 2, dtype family int, shape (4, 1) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import numpy as np

torch.manual_seed(0)

# The function check_2d takes a single parameter X
# It checks if X is not None and has ndim == 1, then reshapes it to (-1, 1)
# X should be a numpy array or torch tensor with ndim attribute

# Create test cases for X
X_1d = np.array([1, 2, 3, 4])  # 1D array
X_2d = np.array([[1, 2], [3, 4], [5, 6]])  # 2D array
X_none = None  # None case

# Test with 1D array (most interesting case - will be reshaped)
ARGS = {
    "X": X_1d
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type ndarray, ndim 2, dtype family int, shape (4, 1) — shape (4, 1) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
dag_false_orientations Ran
ran on a synthesized input
rflperry/sparse_shift/sparse_shift/metrics.py
code served (permissive licence) · get_code("6558d096cb46076e")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned float64, ndim 0, dtype family float; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import numpy as np

# Create small DAGs as numpy arrays
# A DAG is represented as an adjacency matrix where entry (i,j) = 1 means edge i->j

# true_dag: a small valid DAG (3 nodes)
# We'll create a simple DAG: 0->1, 0->2, 1->2
true_dag = np.array([
    [0, 1, 1],
    [0, 0, 1],
    [0, 0, 0]
], dtype=int)

# cpdag: a completed partially directed acyclic graph
# Same structure but represented differently for the computation
# The function computes: len(np.where(true_dag + cpdag.T - cpdag == 2)[0]) / np.sum(true_dag)
# cpdag should be a matrix of similar shape to true_dag
cpdag = np.array([
    [0, 1, 1],
    [0, 0, 1],
    [0, 0, 0]
], dtype=int)

ARGS = {
    "true_dag": true_dag,
    "cpdag": cpdag
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type float64, ndim 0, dtype family float — no output shape is stated: observe_signature.py recorded float ndim 0, which disagrees with the fixture run
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
dag_precision Ran
ran on a synthesized input
rflperry/sparse_shift/sparse_shift/metrics.py
code served (permissive licence) · get_code("663cfcf0d8a32ecb")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned int, ndim 0, dtype family int, shape () as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import numpy as np

# The function dag_precision expects:
# - true_dag: a numpy array (adjacency matrix for true DAG)
# - cpdag: a numpy array (CPDAG - completed partially directed acyclic graph)
#
# The function performs element-wise operations and comparisons on these matrices:
# - true_dag + cpdag - cpdag.T (looking for where == 2)
# - true_dag + cpdag.T - cpdag (looking for where == 2)
# 
# These are 2D numpy arrays representing directed graphs

# Create small example DAGs as binary adjacency matrices
# A valid DAG should be acyclic; we'll create simple cases

# true_dag: a simple DAG with 4 nodes
# Let's use a lower triangular structure to ensure acyclicity
true_dag = np.array([
    [0, 1, 0, 1],
    [0, 0, 1, 0],
    [0, 0, 0, 1],
    [0, 0, 0, 0]
], dtype=int)

# cpdag: completed PDAG - can have both directed and undirected edges
# For undirected edges, both (i,j) and (j,i) can be 1
cpdag = np.array([
    [0, 1, 1, 1],
    [1, 0, 1, 0],
    [0, 1, 0, 1],
    [1, 0, 1, 0]
], dtype=int)

ARGS = {
    "true_dag": true_dag,
    "cpdag": cpdag
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type int, ndim 0, dtype family int, shape () — shape () as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
dag_true_orientations Ran
ran on a synthesized input
rflperry/sparse_shift/sparse_shift/metrics.py
code served (permissive licence) · get_code("44aeee3d1759c4cf")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned float64, ndim 0, dtype family float; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import numpy as np

# Create a small DAG (directed acyclic graph) as adjacency matrix
# true_dag represents the ground truth graph structure
true_dag = np.array([
    [0, 1, 0, 1],
    [0, 0, 1, 0],
    [0, 0, 0, 1],
    [0, 0, 0, 0]
], dtype=int)

# Create a CPDAG (completed partially directed acyclic graph)
# This should have some correctly oriented edges matching true_dag
# and some undirected edges (represented by bidirectional entries)
cpdag = np.array([
    [0, 1, 0, 1],
    [0, 0, 1, 0],
    [0, 0, 0, 1],
    [0, 0, 0, 0]
], dtype=int)

ARGS = {
    "true_dag": true_dag,
    "cpdag": cpdag
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type float64, ndim 0, dtype family float — no output shape is stated: observe_signature.py recorded float ndim 0, which disagrees with the fixture run
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
dags2mechanisms Ran
ran on a synthesized input
rflperry/sparse_shift/sparse_shift/utils.py
code served (permissive licence) · get_code("695484581db8290c")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned dict. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import numpy as np

# Create sample DAGs as numpy arrays
# Each DAG should be a matrix where dags2mechanisms will transpose it
# The function does dag.T, so if we want m variables, we need shape (m, something)
# Let's create 3 DAGs with 4 variables each

dag1 = np.array([
    [1, 0, 0],
    [1, 1, 0],
    [0, 1, 1],
    [0, 0, 1]
])

dag2 = np.array([
    [1, 0, 0],
    [1, 1, 0],
    [0, 1, 1],
    [0, 0, 1]
])

dag3 = np.array([
    [1, 0, 0],
    [0, 1, 0],
    [0, 1, 1],
    [0, 0, 1]
])

dags = [dag1, dag2, dag3]

ARGS = {
    "dags": dags
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type dict — a dict output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a dict output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
invariant_residual_test Ran
ran on a synthesized input
rflperry/sparse_shift/sparse_shift/independence_tests.py
code served (permissive licence) · get_code("4a0e4c099e30b2a5")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned tuple, ndim 1, dtype family float; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import numpy as np

np.random.seed(0)

# Create small synthetic dataset
n_samples = 10
n_features = 4

X = np.random.randn(n_samples, n_features)
Y = np.random.randn(n_samples)
z = np.array([0, 1, 0, 1, 0, 1, 0, 1, 0, 1])

ARGS = {
    'X': X,
    'Y': Y,
    'z': z,
    'method': 'gam',
    'test': 'ks',
    'method_kwargs': {},
    'return_model': False,
    'combine_pvalues': True,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, scipy, sklearn — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple, ndim 1, dtype family float — a tuple output has no array shape of its own; none is stated
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
sample_cdnod_sim Ran
ran on a synthesized input
rflperry/sparse_shift/sparse_shift/datasets/simulations.py
code served (permissive licence) · get_code("79215bd3cdbd5127")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned ndarray, ndim 2, dtype family float, shape (10, 4) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import numpy as np
import networkx as nx
from functools import partial

# Create a small DAG (directed acyclic graph)
# 4 variables with some edges
dag = np.array([
    [0, 1, 0, 0],
    [0, 0, 1, 0],
    [0, 0, 0, 1],
    [0, 0, 0, 0]
], dtype=float)

# Parameters for sample_cdnod_sim
ARGS = {
    "dag": dag,
    "n_samples": 10,
    "functions": [np.tanh, np.sinc, lambda x: x ** 2, lambda x: x ** 3],
    "intervention_targets": None,
    "intervention_pct": 0.25,
    "base_random_state": 42,
    "domain_random_state": 123,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
networkx, numpy — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type ndarray, ndim 2, dtype family float, shape (10, 4) — shape (10, 4) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
sample_nonlinear_icp_sim Ran
ran on a synthesized input
rflperry/sparse_shift/sparse_shift/datasets/simulations.py
code served (permissive licence) · get_code("f42ebf028c5ec1ac")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned ndarray, ndim 2, dtype family float, shape (100, 4) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import numpy as np
import networkx as nx

# Create a simple DAG (directed acyclic graph) as a weighted adjacency matrix
# 4 variables with edges: 0->1, 0->2, 1->3
dag = np.array([
    [0.0, 0.5, 0.3, 0.0],
    [0.0, 0.0, 0.0, 0.7],
    [0.0, 0.0, 0.0, 0.4],
    [0.0, 0.0, 0.0, 0.0]
])

# Define a custom nonlinearity function
def custom_nonlinearity(X):
    return np.tanh(X)

ARGS = {
    'dag': dag,
    'n_samples': 100,
    'nonlinearity': 'relu',
    'noise_df': 5,
    'combination': 'additive',
    'intervention_targets': [1, 2],
    'intervention': 'soft',
    'intervention_shift': 0.5,
    'intervention_scale': 1.0,
    'intervention_pct': 0.3,
    'random_state': 42,
    'pre_intervention': False,
    'lambda_noise': None,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
networkx, numpy — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type ndarray, ndim 2, dtype family float, shape (100, 4) — shape (100, 4) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
sample_topological Ran
ran on a synthesized input
rflperry/sparse_shift/sparse_shift/datasets/simulations.py
code served (permissive licence) · get_code("65287b9d099a5288")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned ndarray, ndim 2, dtype family float, shape (10, 3) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import numpy as np
import networkx as nx

# Define a simple SCM with 3 variables where:
# X0 is exogenous (no parents)
# X1 depends on X0
# X2 depends on X1

# Create the DAG as an edge list
dag = [(0, 1), (1, 2)]

# Define structural equations
def equation_0(X, u):
    """X0 = u0 (exogenous)"""
    return u

def equation_1(X, u):
    """X1 = 2*X0 + u1"""
    return 2 * X[0] + u

def equation_2(X, u):
    """X2 = 0.5*X1 + u2"""
    return 0.5 * X[1] + u

equations = [equation_0, equation_1, equation_2]

# Define noise functions
def noise_fn():
    """Generate standard normal noise"""
    return np.random.normal(0, 1)

# Alternative: list of noise callables
noise_list = [
    lambda: np.random.normal(0, 1),
    lambda: np.random.normal(0, 1),
    lambda: np.random.normal(0, 1),
]

ARGS = {
    "n": 10,
    "equations": equations,
    "dag": dag,
    "noise": noise_fn,
    "random_state": 42,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
networkx, numpy — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type ndarray, ndim 2, dtype family float, shape (10, 3) — shape (10, 3) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
barabasi_albert_dag Not yet run
unverified (harvested, no recorded run)
rflperry/sparse_shift/sparse_shift/datasets/dags.py
code served (permissive licence) · get_code("f7644dd1aeb0743b")
How it ran

no invocation recorded.

connected_erdos_renyi_dag Not yet run
unverified (harvested, no recorded run)
rflperry/sparse_shift/sparse_shift/datasets/dags.py
code served (permissive licence) · get_code("f7acbd0b944b4a8f")
How it ran

no invocation recorded.

create_causal_learn_dag Not yet run
unverified (harvested, no recorded run)
rflperry/sparse_shift/sparse_shift/utils.py
code served (permissive licence) · get_code("512d1d9329fe5bfb")
How it ran

no invocation recorded.

erdos_renyi_dag Not yet run
unverified (harvested, no recorded run)
rflperry/sparse_shift/sparse_shift/datasets/dags.py
code served (permissive licence) · get_code("f3a29a6b0cda9be5")
How it ran

no invocation recorded.

Also present in other papers' code

Of 13 samples lifted from this paper's linked repositories, 13 carry a function identity and 0 do not. Of the 13 distinct functions with an identity, 0 are also present in other papers whose code we hold (0 with at least one paper dated earlier, 0 the same month, 0 later) and 13 are only here among the 52,977 papers whose code Syntology holds (as of 2026-09-26).

Only here means: among the 52,977 papers whose code Syntology holds (51,887 with lifted samples, 1,090 through their assemblies only), as of 2026-09-26, no other paper's lifted samples or current assembly bricks contain an identical function body after normalisation.

Presence, not direction: an identical function body in two papers' repositories does not say who wrote it, which came from which, or that either paper's method rests on it. Matching is exact after normalisation, so a renamed or edited function is not matched. Dates are when papers appeared, not when code was written. Only .py files the harvester lifted are covered; notebooks are not read. A new-style arXiv id YYMM.NNNN dates a paper to the month 20YY-MM; otherwise Paper.year dates it to the year; otherwise it is undated. Dates are when the paper appeared, not when the code was written. Read 2026-11-22.

Repositories linked to this paper

Some links come from the archived Papers with Code dataset (CC BY-SA 4.0): attribution and licence.

Abstract

Machine learning approaches commonly rely on the assumption of independent and identically distributed (i.i.d.) data. In reality, however, this assumption is almost always violated due to distribution shifts between environments. Although valuable learning signals can be provided by heterogeneous data from changing distributions, it is also known that learning under arbitrary (adversarial) changes is impossible. Causality provides a useful framework for modeling distribution shifts, since causal models encode both observational and interventional distributions. In this work, we explore the sparse mechanism shift hypothesis, which posits that distribution shifts occur due to a small number of changing causal conditionals. Motivated by this idea, we apply it to learning causal structure from heterogeneous environments, where i.i.d. data only allows for learning an equivalence class of graphs without restrictive assumptions. We propose the Mechanism Shift Score (MSS), a score-based approach amenable to various empirical estimators, which provably identifies the entire causal structure with high probability if the sparse mechanism shift hypothesis holds. Empirically, we verify behavior predicted by the theory and compare multiple estimators and score functions to identify the best approaches in practice. Compared to other methods, we show how MSS bridges a gap by both being nonparametric as well as explicitly leveraging sparse changes.

For agents

The same record, over MCP at https://syntology.ai/mcp:

get_harvested_code_for_paper("2206.02013")
get_code_for_paper("2206.02013")
have("2206.02013")

The run record, dated, one paper per request, free:

curl https://syntology.ai/api/ran/2206.02013.json

A badge for a README (the split and the date, never a ratio):

[![Syntology run record](https://syntology.ai/api/ran/2206.02013.svg)](https://syntology.ai/paper/2206.02013)

Connect an agent — have() is free.