Skip to content

# Make _jitter() accept an optional random_state parameter #1217

@khushthecoder

Description

@khushthecoder

Problem

_jitter() in util.py calls np.random.uniform() using the global RNG, meaning results are non-reproducible even when the user passes random_seed to the calling function. The random_seed parameter exists in the public API (e.g., cohort_diversity_stats) but is never threaded through to _jitter().

util.py:903

def _jitter(a, fraction):
    r = a.max() - a.min()
    return a + fraction * np.random.uniform(-r, r, a.shape)  # global RNG!

Proposed Fix

Add an optional random_state parameter defaulting to np.random. Called from pca.py lines 403–509.

Impact

Makes PCA plots reproducible when users set random_seed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions