Skip to content

[fuzz] pop_clean_rawdata ASR-only residual of 5.79e-12 against approved abs 0 #643

Closed

Description

@suraj-ranganath

The #640 validation run on jamming compared EEGPrep with MATLAB R2025b Update 7 at PR #640 head eaad381. The 4-example nightly-style survey with seed 20261118 found a confirmed numeric divergence on an ASR-only pop_clean_rawdata call.

Params: entry clean_rawdata, cutoff 10.0, ref_maxbadchannels 0.2, window_len 1.0. Other cleaning criteria were off, so the comparison uses the approved [clean_asr] tolerance (abs 0, rel 1e-6).

Spec: channels 17 through 31, start 324, length 564, decimate 1, flat_channel 11.

Max abs 5.787370582766016e-12, max rel 1.0, at finite index 3925.

Repro:

uv run python -m tests.fuzz reproduce /mnt/v1/arno/suraj3/pr640/fuzz-out/repros/pop_clean_rawdata-numeric-data.json

The repro JSON is on jamming at that path. The run used PR #640 at eaad381 with MATLAB R2025b. Replaying the saved case on the same machine reproduced the same numbers.

This should be investigated as a question of whether one side ought to produce an exact zero at that sample, which would make a 5.79e-12 residual fail under abs 0. The approved tolerance should stay as it is.

Unverified hypothesis: ASR leaves a near-zero residual on one side where the other side is 0, and the relative error is 1.0 for that reason. A flat channel on this short crop may be involved.

Activity

  1. added
    fuzz
    on Nov 18, 2026
  2. claude commented on Nov 18, 2026

    @claude
    Contributor

    🤖 Plan:

    • Rebuild the case from the issue spec with the PR Make fuzz draws independent of imported integer literals #640 harness (Python side only, no MATLAB on this runner)
    • Trace where the flat channel can pick up a nonzero value in ASR
    • Confirm the MATLAB side on jamming (needs MATLAB, see below)
    • Decide on a resolution (needs a maintainer decision, so no PR)

    Research

    The comparison fails on flat channel 11, not on the reported max-abs sample. Finite index 3925 is channel 6, sample 541. That sample is inside the window ASR repaired (samples 512–562). There, a 5.8e-12 gap passes rel 1e-6. max rel 1.0 means Python is exactly 0 where MATLAB is not. In Python, every sample on channel 11 stays exactly 0.0. The robust covariance med has an exactly zero row and column 11, because the geometric median of all-zero coordinates is 0. scipy.linalg.sqrtm keeps the Schur basis decoupled on that index, so M[11,:] is exactly 0. That makes R[11,:] = M[11,:] @ pinv(...) @ V' exactly 0, so the repaired flat channel is exactly 0. MATLAB's sqrtm/eig (MKL) evidently does not keep that row exactly zero. An eigendecomposition-based square root of the same med (np.linalg.eigh, then Q*sqrt(d)*Q') gives |M[11,:]| up to 5.4e-16, and eigh returns d_min = -2.9e-31. Multiplied through R*data (~50 µV), that gives a 1e-14 to 1e-12 residual on channel 11. abs 0 rejects that, at rel 1.0.

    So the exact zero is the mathematically correct value, and EEGPrep produces it. The MATLAB residual is rounding inside sqrtm on a singular covariance. Neither port has a numerical bug here.

    Relevant code

    Proposed Fix (needs a decision, no PR opened)

    1. Confirm on jamming: in the repro, run max(abs(state.M(12,:))) after asr_calibrate and max(abs(EEG.data(12,:))) on the MATLAB output. Expect a value around 1e-16, then around 1e-12.
    2. Recommended: add an oracle-defect classifier in the harness, like the existing _asr_*_is_known helpers. It would accept the case only when the input row is identically 0, the Python output row is exactly 0, and every other channel passes [clean_asr] unchanged. That leaves the approved abs 0 / rel 1e-6 tolerance alone. It does not loosen any channel that carries signal.
    3. Not recommended: making Python reproduce MATLAB's rounding, for example by swapping scipy.linalg.sqrtm for an eigh square root. It changes core ASR numerics for every dataset, it is unlikely to match MKL bit for bit, and it moves Python away from the exact answer.

    Related: #642 is also a flat_channel clean_asr finding from the same #640 run, but its divergence is 99 µV, so it has a different cause. No open PR overlaps this one.

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

    fuzz

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions