Skip to content

[fuzz] pop_clean_rawdata wide start=1202: MATLAB ASR calibration fails on 3 RMS windows, eegprep applies ASR (max abs 74.79) #651

Closed

Description

@suraj-ranganath

The wide bids pop_clean_rawdata fuzz case (all 32 channels, start=1202, length=1024, srate=128) still diverges on develop 8289770: max abs 74.79348223853694, max rel 2048.468151541101, finite index 8042. Tolerances and goldens are not involved.

Staged comparison (MATLAB R2025b, EEGLAB d0963be9, clean_rawdata 85eab7d2, jamming):

  • clean_flatlines is bit-identical.
  • clean_drifts (highpass) differs only by filter roundoff (max abs 1.85e-13, max rel 4.04e-11), which doesn't change any later decision.
  • clean_channels agrees: both remove EOG1 and T8 (32 to 30 channels).
  • The first material divergence is ASR.

clean_asr's calibration clean_windows (0.075, [-inf, 5.5], 1 s) keeps 118 of 1024 samples on both sides. asr_calibrate then forms 0.5 s RMS windows (N=64, overlap 0.66) and gets n=3 windows (starts 0, 22, 44). The only short-reference error in asr_calibrate.m is for length(rms)==1, so n=3 goes on into fit_eeg_distribution.

There the default quants are [0.022, 0.6], so min_width = 0.25*0.578 = 0.1445, and m = round(n*(max_width:-0.01:min_width)) includes m=0 when n is 2 or 3. MATLAB asr_calibrate.m line 395 indexes X(m,:) and errors with "Index in position 1 is invalid." eegprep's fit_eeg_distribution (private/stats.py) skips m <= 0, fits on the remaining widths (1 or 2 values), and applies ASR. ASRCalibrationError covers only S < N or fewer than 2 RMS windows.

clean_artifacts.m lines 270-275 catch any clean_asr error and return immediately, which also skips restoring srate and the final clean_windows stage. On this crop MATLAB's output is bit-identical to the post-channel, pre-ASR recording. eegprep applies ASR, and its final clean_windows is a no-op here. The 74.79 / 2048.47 at index 8042 is eegprep's ASR repair against MATLAB's unrepaired data.

Options:

  1. Raise ASRCalibrationError when the RMS window count is too small for the fit grid (any m <= 0), so eegprep also leaves the recording unrepaired by ASR, but still restores srate and runs the final clean_windows. MATLAB's early return would be documented as an EEGLAB bug, with a test locking in the difference.
  2. Keep skipping invalid widths (current behaviour) and document MATLAB's index error as an EEGLAB bug.

Repro on jamming: /mnt/v1/arno/suraj3/pr640/fuzz-out-wide/repros/pop_clean_rawdata-numeric-data.json

Activity

  1. claude commented on Nov 18, 2026

    @claude
    Contributor

    🤖 Plan:

    Research

    Option 2 is already the documented, intentional behavior from #526/#582: EEGPrep skips non-positive fit widths and still calibrates, and MATLAB's X(m,:) index error plus the early return in clean_artifacts.m is listed as an EEGLAB defect. So no core-code change is needed. The real gap is in the fuzz harness. Both known-defect classifiers only match case.function == "clean_asr" with entry == "clean_rawdata" and MATLAB output equal to the raw input. In the wide-bids pop_clean_rawdata target, the flatline/highpass/channel stages run first. MATLAB therefore returns the post-channel, pre-ASR recording rather than the input, so the case falls through to judge as a divergence.

    Relevant code

    Proposed Fix

    Keep option 2. Option 1 would reverse a decision already in the docs and changelog. It still would not match MATLAB, which also skips the final clean_windows and the srate restore.

    Extend the known-defect check in tests/fuzz/harness.py to the pop_clean_rawdata target. Run EEGPrep's pop_clean_rawdata with the same options but BurstCriterion='off' and WindowCriterion='off'. Classify the case as known #582 only when (a) the MATLAB oracle matches that pre-ASR output within the clean_asr tolerance, and (b) _fit_width_reaches_zero is true for the reference that clean_windows kept on the pre-ASR data. Add one harness test with a crop that leaves 3 calibration RMS windows. This touches test tooling only (about 40-60 lines) and changes no tolerances.

    Not opened as a PR: a human needs to confirm option 2 first. The classifier also has to be checked with MATLAB against the jamming repro (fuzz-out-wide/repros/pop_clean_rawdata-numeric-data.json), which this runner can't reach.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions