SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2304.04183 · AAAI · 2023

Nearest-Neighbor Sampling Based Conditional Independence Testing

Shuai Li, Christina Wang, Hongtu Zhu, Ziqi Chen, Wang Wen

arXiv · PDF · Open in the Atlas

Code that ran

14 of 17 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (1 of them constructed an object rather than computing a result; 2 honoured the contract we drafted, 1 violated it and 1 has no contract verdict; 10 failures of our instrument; 3 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/2304.04183.json · badge: /api/ran/2304.04183.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
LeeShuai-kenwitch/NNSCIT marked official in Papers with Code
Papers with Code archive
7 ran · 3 no recorded run
yanfeng-yang-0316/cdcit community
Papers with Code archive
7 ran · 0 no recorded run
FunctionStatusWhere it lives
Classifier_MI Ran
ran on a synthesized input · constructed an object; no result was computed
LeeShuai-kenwitch/NNSCIT/nnscit.py
code served (permissive licence) · get_code("c1217da7a5cae4e9")
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 an instance of its own class, Classifier_MI: the run constructed the object and did not call it, so no result was computed. 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
import tensorflow as tf

np.random.seed(0)
tf.compat.v1.set_random_seed(0)

# Create small synthetic data for training
# data_train shape: (n_samples, dx + dy)
# Split into X (first dx columns) and Y (remaining columns)
n_train = 16
dx = 4
dy = 3
data_train = np.random.randn(n_train, dx + dy).astype(np.float32)

# Create small synthetic data for evaluation
n_eval = 8
data_eval = np.random.randn(n_eval, dx + dy).astype(np.float32)

ARGS = {
    'data_train': data_train,
    'data_eval': data_eval,
    'dx': dx,
    'h_dim': 64,
    'actv': tf.nn.relu,
    'batch_size': 4,
    'optimizer': 'adam',
    'lr': 0.001,
    'max_ep': 2,
    'mon_freq': 5000,
    'metric': 'donsker_varadhan'
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, tensorflow — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Classifier_MI — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a Classifier_MI 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
NNCMI Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
yanfeng-yang-0316/cdcit/nnlscit.py
pointer only (licence: NONE) · get_code("f76c631904de0f95")
How it ran

The body of this sample is withheld: GitHub detected no licence in this paper's repository, yanfeng-yang-0316/cdcit when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

cmi Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
LeeShuai-kenwitch/NNSCIT/nnscit.py
code served (permissive licence) · get_code("a4d77d7acb32bcbd")
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
import pandas as pd
from scipy.special import digamma

# Create a small stand-in pandas DataFrame with numeric and categorical data
np.random.seed(0)
n_samples = 5
n_features = 4

data = pd.DataFrame({
    'var0': np.random.randn(n_samples),
    'var1': np.random.randn(n_samples),
    'var2': np.random.randn(n_samples),
    'var3': np.random.choice(['A', 'B', 'C'], n_samples)
})

# Define ARGS for the cmi function
ARGS = {
    'x': [0],  # index of first variable
    'y': [1],  # index of second variable
    'z': [2],  # index of conditioning variable
    'k': 2,    # number of nearest neighbors
    'data': data,
    'discrete_dist': 1,
    'minzero': 1
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, pandas, scipy — 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
cmiPoint Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
LeeShuai-kenwitch/NNSCIT/nnscit.py
code served (permissive licence) · get_code("ea70a8cbed456c11")
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
from scipy.special import digamma

# Create a small pairwise distance array
# The function expects distArray to be 3D with shape (p, n, n)
# where p is number of coordinates, n is number of points
# We'll make it small: 5 coordinates, 6 points
n_points = 6
n_coords = 5

# Create a 3D array of pairwise distances
# distArray[coord_idx, point_i, point_j] = distance between point_i and point_j in coordinate coord_idx
distArray = np.random.rand(n_coords, n_points, n_points)

# Make distances symmetric and zero on diagonal for realism
for c in range(n_coords):
    for i in range(n_points):
        for j in range(n_points):
            if i == j:
                distArray[c, i, j] = 0.0
            else:
                # Symmetric
                distArray[c, i, j] = distArray[c, j, i]

# Set a specific point index
point_i = 0

# Define x, y, z as lists of coordinate indices
# Let's use a small subset of coordinates
x = [0, 1]  # 2 coordinates for x
y = [2]     # 1 coordinate for y
z = [3, 4]  # 2 coordinates for z

# k value for k-nearest neighbors
k = 2

ARGS = {
    'point_i': point_i,
    'x': x,
    'y': y,
    'z': z,
    'k': k,
    'distArray': distArray
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, scipy — 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
countNeighbors Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
LeeShuai-kenwitch/NNSCIT/nnscit.py
code served (permissive licence) · get_code("f296fd45532342e3")
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 int64, 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 uses:
# - coord_dists: needs .shape attribute and supports indexing with [:, coords]
# - rho: a scalar value to compare distances against
# - coords: optional list of indices (defaults to empty list)

# Create a small coord_dists array
# Shape should be (n_points, n_coordinates) where we can index by coordinate columns
# Let's make it (5, 4) - 5 points, 4 coordinate dimensions
coord_dists = np.array([
    [0.0, 1.0, 2.0, 3.0],
    [0.5, 1.5, 2.5, 3.5],
    [1.0, 2.0, 3.0, 4.0],
    [0.2, 0.3, 0.4, 0.5],
    [2.0, 2.1, 2.2, 2.3]
], dtype=np.float32)

# rho is a distance threshold
rho = 1.5

# coords is optional - list of coordinate indices to consider
coords = [0, 2]

ARGS = {
    "coord_dists": coord_dists,
    "rho": rho,
    "coords": coords
}
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 int64, 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
getKnnDist Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
LeeShuai-kenwitch/NNSCIT/nnscit.py
code served (permissive licence) · get_code("4fcba4386338d35d")
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

# Create a sample distArray (2D numpy array of pairwise distances)
# Shape: (5, 4) - 5 samples, 4 features
distArray = np.array([
    [1.2, 0.8, 1.5, 0.3],
    [2.1, 1.9, 0.5, 1.2],
    [0.6, 0.7, 0.9, 1.1],
    [1.5, 2.0, 1.8, 0.4],
    [0.3, 0.2, 0.8, 0.5]
])

k = 2

ARGS = {
    "distArray": distArray,
    "k": k
}
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 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
getPointCoordDists Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
LeeShuai-kenwitch/NNSCIT/nnscit.py
code served (permissive licence) · get_code("8ad2e4cb5226410c")
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 (7, 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

# Create a distArray with shape (p, n, n)
# where p is number of coordinates, n is number of observations
# The function accesses distArray[coords, :, ind_i]
p = 5  # number of coordinates
n = 7  # number of observations

distArray = np.random.randn(p, n, n)

ind_i = 3
coords = [0, 2, 4]

ARGS = {
    "distArray": distArray,
    "ind_i": ind_i,
    "coords": coords,
}
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 ndarray, ndim 2, dtype family float, shape (7, 3) — shape (7, 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
log_mean_exp_numpy Ran
ran; our contract draft was wrong, not the code
yanfeng-yang-0316/cdcit/nnlscit.py
pointer only (licence: NONE) · get_code("32a3583764c247db")
How it ran

The body of this sample is withheld: GitHub detected no licence in this paper's repository, yanfeng-yang-0316/cdcit when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

miPoint Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
LeeShuai-kenwitch/NNSCIT/nnscit.py
code served (permissive licence) · get_code("3be01708e9d6e355")
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, 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
from scipy.special import digamma

# Set random seed for reproducibility
np.random.seed(0)

# Create a small distArray (output of getPairwiseDistArray)
# distArray has shape (p, n, n) where p is number of coordinates, n is number of observations
# For this setup: p=4 (number of dimensions), n=3 (number of observations)
p = 4
n = 3
distArray = np.random.rand(p, n, n)

# Make it symmetric and non-negative for distances
for i in range(p):
    distArray[i] = (distArray[i] + distArray[i].T) / 2
    np.fill_diagonal(distArray[i], 0)

# point_i: current observation row index (0, 1, or 2)
point_i = 0

# x: list of indices for first variable set
x = [0, 1]

# y: list of indices for second variable set
y = [2, 3]

# k: positive integer scalar for k in knn
k = 1

ARGS = {
    "point_i": point_i,
    "x": x,
    "y": y,
    "k": k,
    "distArray": distArray
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, scipy — 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, 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
mimic_knn Ran
ran; our contract draft was wrong, not the code
yanfeng-yang-0316/cdcit/nnlscit.py
pointer only (licence: NONE) · get_code("574abf7fc64476b5")
How it ran

The body of this sample is withheld: GitHub detected no licence in this paper's repository, yanfeng-yang-0316/cdcit when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

normalize_data Ran
ran, honoured the contract we drafted
yanfeng-yang-0316/cdcit/nnlscit.py
pointer only (licence: NONE) · get_code("c6a3311cea14cc5a")
How it ran

The body of this sample is withheld: GitHub detected no licence in this paper's repository, yanfeng-yang-0316/cdcit when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

split_XYZ Ran
ran; our contract draft was wrong, not the code
yanfeng-yang-0316/cdcit/nnlscit.py
pointer only (licence: NONE) · get_code("99c16e627e3d00e2")
How it ran

The body of this sample is withheld: GitHub detected no licence in this paper's repository, yanfeng-yang-0316/cdcit when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

split_train_test Ran
ran, honoured the contract we drafted
yanfeng-yang-0316/cdcit/nnlscit.py
pointer only (licence: NONE) · get_code("aeb422e5bb499306")
How it ran

The body of this sample is withheld: GitHub detected no licence in this paper's repository, yanfeng-yang-0316/cdcit when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

xgb_classifier Ran
ran, violated the contract we drafted
yanfeng-yang-0316/cdcit/nnlscit.py
pointer only (licence: NONE) · get_code("ae462d71cbe417e2")
How it ran

The body of this sample is withheld: GitHub detected no licence in this paper's repository, yanfeng-yang-0316/cdcit when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

CCMI Not yet run
unverified (harvested, no recorded run)
LeeShuai-kenwitch/NNSCIT/nnscit.py
code served (permissive licence) · get_code("e2f76cd7cfe3762c")
How it ran

no invocation recorded.

GMCIT Not yet run
unverified (harvested, no recorded run)
LeeShuai-kenwitch/NNSCIT/nnscit.py
code served (permissive licence) · get_code("2bd870923dab2981")
How it ran

no invocation recorded.

getPairwiseDistArray Not yet run
unverified (harvested, no recorded run)
LeeShuai-kenwitch/NNSCIT/nnscit.py
code served (permissive licence) · get_code("8d372150d6881632")
How it ran

no invocation recorded.

Also present in other papers' code

Of 17 samples lifted from this paper's linked repositories, 17 carry a function identity and 0 do not. Of the 17 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 17 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

The conditional randomization test (CRT) was recently proposed to test whether two random variables X and Y are conditionally independent given random variables Z. The CRT assumes that the conditional distribution of X given Z is known under the null hypothesis and then it is compared to the distribution of the observed samples of the original data. The aim of this paper is to develop a novel alternative of CRT by using nearest-neighbor sampling without assuming the exact form of the distribution of X given Z. Specifically, we utilize the computationally efficient 1-nearest-neighbor to approximate the conditional distribution that encodes the null hypothesis. Then, theoretically, we show that the distribution of the generated samples is very close to the true conditional distribution in terms of total variation distance. Furthermore, we take the classifier-based conditional mutual information estimator as our test statistic. The test statistic as an empirical fundamental information theoretic quantity is able to well capture the conditional-dependence feature. We show that our proposed test is computationally very fast, while controlling type I and II errors quite well. Finally, we demonstrate the efficiency of our proposed test in both synthetic and real data analyses.

For agents

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

get_harvested_code_for_paper("2304.04183")
get_code_for_paper("2304.04183")
have("2304.04183")

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

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

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

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

Connect an agent — have() is free.