random_state=0 is ignored by MeanEmbeddingTest and SmoothCFTest

Open Beginner friendly
#450 0 comments 0 reactions 0 assignees View on GitHub

@dnncha is already working on this.

Since Sep 30, 2026.

  • #452 by @dnncha — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
numpy, python
Domain
data, testing

Research direction

Locate the MeanEmbeddingTest and SmoothCFTest test entry points and inspect how their public test(...) methods handle random_state. Run the focused regressions described in the issue, including the nonzero-seed control; done means random_state=0 is deterministic for both methods while None remains unseeded.

Written by the indexing model from the issue text.

Description

ELI5

Passing random_state=0 looks like it fixes hyppo's random test points, but zero is treated as “no seed.” The same data can therefore switch from significant to non-significant depending on unrelated NumPy calls made earlier.

Exact failure

With hyppo 0.5.2 and fixed 80×3 samples:

  • MeanEmbeddingTest(..., random_state=0): p=0.016226 after prior seed 31; p=0.794313 after prior seed 2.
  • SmoothCFTest(..., random_state=0): p=0.027979 after prior seed 6; p=0.997951 after prior seed 8.
  • random_state=1 is stable under the same control.

Both seed-zero pairs cross 0.05.

Reproduce

import numpy as np
from hyppo.ksample import MeanEmbeddingTest, SmoothCFTest

rng = np.random.default_rng(0)
x = rng.normal(size=(80, 3))
y = rng.normal(loc=0.18, size=(80, 3))

for cls, prior_seeds in [
    (MeanEmbeddingTest, (31, 2)),
    (SmoothCFTest, (6, 8)),
]:
    for prior_seed in prior_seeds:
        np.random.seed(prior_seed)
        result = cls(num_randfreq=5).test(x, y, random_state=0)
        print(cls.__name__, prior_seed, result.stat, result.pvalue)

Full baseline/fixed outputs, tests, patch and hashes are preserved in Cheerful Duck commit 358cc0e. Evidence archive SHA-256: 643181d679db2b238d99eaf913304f1bd61bf600bfb53c096e678196e18d4725.

Fix

Both methods use if random_state:, so integer zero skips np.random.seed(0).

-        if random_state:
+        if random_state is not None:
             np.random.seed(random_state)

This keeps nonzero seeds unchanged, leaves None unseeded, and makes zero deterministic. Four focused regressions pass across both public test(...) paths and the nonzero-seed control.

Pinned environment

  • hyppo 0.5.2, tag commit 2e4a8569b6cd56ffa85f2ac26dc35478af1f7ba9
  • current main checked at a3a2ac323c34b7c98adbf8486bf112afc82f6705
  • Python 3.12.14; NumPy 2.5.3; SciPy 1.18.1; scikit-learn 1.9.1
  • wheel SHA-256: 5cc18f9e158fe2cf1804c9a1e979e807118ee89a303f29dc5cb8891d92d44ef3

Limits

This demonstrates an inference and reproducibility defect for callers that explicitly use seed zero. I have not established that a specific publication used seed zero or that any published conclusion changes.

Dominant language
Python
Stars
253
Forks
103
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from neurodata/hyppo

All issues in neurodata/hyppo

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.