You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[fuzz] pop_clean_rawdata ASR-only residual of 5.79e-12 against approved abs 0 #643
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).
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.
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.
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.
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.
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.
Activity
claude commentedon Nov 18, 2026
🤖 Plan:
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.0means Python is exactly 0 where MATLAB is not. In Python, every sample on channel 11 stays exactly 0.0. The robust covariancemedhas an exactly zero row and column 11, because the geometric median of all-zero coordinates is 0.scipy.linalg.sqrtmkeeps the Schur basis decoupled on that index, soM[11,:]is exactly 0. That makesR[11,:] = M[11,:] @ pinv(...) @ V'exactly 0, so the repaired flat channel is exactly 0. MATLAB'ssqrtm/eig(MKL) evidently does not keep that row exactly zero. An eigendecomposition-based square root of the samemed(np.linalg.eigh, thenQ*sqrt(d)*Q') gives|M[11,:]|up to 5.4e-16, andeighreturnsd_min = -2.9e-31. Multiplied throughR*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
sqrtmon a singular covariance. Neither port has a numerical bug here.Relevant code
asr_calibrate.py#L257-L270-M = sqrtm(med),eigh(M)(asr_calibrate.m:186,196)private/riemann.py#L74-L83-R = M*pinv(keep.*(V'*M))*V'(asr_process.m:176)asr_process.py#L220-R @ segmentblend, the step that writes channel 11tests/fuzz/harness.pycompare_data-limit = abs + rel*|oracle|, which is 0 when the oracle is ~0Proposed Fix (needs a decision, no PR opened)
max(abs(state.M(12,:)))afterasr_calibrateandmax(abs(EEG.data(12,:)))on the MATLAB output. Expect a value around 1e-16, then around 1e-12._asr_*_is_knownhelpers. 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 approvedabs 0 / rel 1e-6tolerance alone. It does not loosen any channel that carries signal.scipy.linalg.sqrtmfor aneighsquare 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_channelclean_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.