Skip to content

[ICA] eeg_picard silently ignores random_state #431

Closed

Description

@suraj-ranganath

🤖 eeg_picard silently ignores random_state.

src/eegprep/functions/popfunc/eeg_picard.py sets params['w_init'] = np.eye(n_components) whenever the caller doesn't pass w_init. This makes the result deterministic and matches MATLAB. But picard only uses random_state to generate w_init, so eeg_picard(EEG, random_state=42) and eeg_picard(EEG, random_state=123) always return identical icaweights. The argument is accepted without any warning and has no effect.

A non-strict xfail test documented this (test_eeg_picard_different_random_states, which cited the Fable 5 epic #193). #429 removed it because a non-strict xfail can never fail.

Options:

  1. Default to w_init = I only when neither w_init nor random_state is given, so an explicit random_state is honored. Default runs keep MATLAB parity.
  2. Reject or warn on random_state, and document that w_init is the way to vary the starting point.

Whichever is chosen, write a failing test first: two runs with different random_state must either differ (option 1) or raise/warn (option 2). Keep TestEegPicard::test_picard_engines passing.

Activity

  1. added
    bug
    on Oct 7, 2026
  2. suraj-ranganath commented on Oct 7, 2026

    @suraj-ranganath
    MemberAuthor

    🤖

    Research

    Confirmed with actual Picard calls: seeds 42 and 123 produce exactly identical weights because EEGPrep always inserts identity w_init. Python Picard uses random_state only when w_init is None; the current upstream EEGLAB wrapper defaults to identity through picard_python_port, so honoring explicit Python seeds does not require changing the default path. No overlapping implementation PR was found.

    Relevant code

    Proposed Fix

    eeg_picard(random_state=...) → injected identity w_init → picard bypasses seeded initialization. Insert identity only when neither w_init nor random_state was supplied, preserving explicit w_init precedence and the existing default; write regressions first for repeatable/different seeds, reduced-rank PCA, and the unchanged identity path, then run the existing MATLAB engine comparison and document seed behavior.

  3. suraj-ranganath commented on Oct 7, 2026

    @suraj-ranganath
    MemberAuthor

    🤖 Fixed in draft PR #438 at ea26580: explicit Python Picard random_state now controls initialization, preserving default identity initialization and explicit w_init precedence. Full-rank/PCA regressions and the existing MATLAB engine comparison pass; the MATLAB comparison reports component correlations of 1.0000 (evidence).

    All four platform test jobs, pre-commit, Ruff/ty, and documentation CI passed. The automated Claude review failed immediately after initialization with is_error:true and zero model usage, producing no code findings; this limitation is tracked separately in eegprep-aug. The PR remains a draft.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions