Repository navigation
[clean_asr] Rank a zero-scale channel as +inf, matching EEGLAB's 241 calibration samples - #649
Conversation
There was a problem hiding this comment.
If your organization's extra usage balance is empty, an organization admin can add extra usage credits at claude.ai/admin-settings/usage. If its monthly spend limit was reached, an admin can raise it on the same page. If neither applies, contact Anthropic support.
Once extra usage is available, someone with write access to this repository can comment @claude review on this pull request to trigger a review.
|
Claude finished @suraj-ranganath's task in 1m 24s —— View job Code review
BlockingNone. Important
Nits
Test gaps
EEGLAB parity notes
Checked: the |
| finite = np.isfinite(candidate) & np.isfinite(oracle_data) | ||
| diff = np.abs(candidate - oracle_data) | ||
| limit = tolerance.abs + tolerance.rel * np.abs(oracle_data) | ||
| failed = finite & (diff > limit) | ||
| if not np.any(failed): | ||
| return False | ||
| return not np.any(np.any(failed, axis=1) & ~rows) |
There was a problem hiding this comment.
Important. This predicate accepts a failure of any size on the flat row. The docs and the #643 label call the MATLAB residual "roundoff", but nothing here limits how large it can be. If the oracle wrote 50 µV, or a reconstructed copy of another channel, into the dead channel, _flat_nullspace_roundoff_is_known would still classify it as a known roundoff difference and the fuzzer would not file it. _flat_nan_sort_is_known falls back to this same check.
Suggested fix: limit the residual on rows to roundoff relative to the signal scale. For example, also require np.max(np.abs(oracle_data[rows])) <= ROUNDOFF_REL * np.max(np.abs(oracle_data[~rows])), with a named constant such as 1e-9. Then add a case to test_flat_channel_roundoff_is_not_a_divergence where residual[11, 0] = 1.0 and assert that it is rejected.
A dead channel's window RMS is zero, so it sits below the lower power bound when another channel has energy. EEGLAB's 0/0 z-score sorts as the highest window and selects a different calibration reference. An all-zero channel stays exactly zero through ASR. Co-authored-by: Suraj Ranganath <[email protected]>
The fuzzer only treats a dead channel as MATLAB square-root roundoff when the oracle values there stay within 1e-9 of the live-channel scale. A reconstructed signal on that channel stays a divergence. Co-authored-by: Suraj Ranganath <[email protected]>
A channel whose window RMS values are all equal takes a high-amplitude bad-channel slot. On the reported crop the calibration reference keeps 241 samples. The fuzzer compares that result directly. Co-authored-by: Suraj Ranganath <[email protected]>
26ec0f1 to
7a593a2
Compare
|
Claude finished @suraj-ranganath's task in 1m 4s —— View job Code review
BlockingNone. Important
Nits
Test gapsNone. EEGLAB parity notes
Checked: the |
| * - Zero-variance channel in ASR reference selection | ||
| - A channel whose window RMS values are all equal has scale 0 and is the | ||
| highest score in every window, so it uses a high-amplitude bad-channel | ||
| slot. On the 17-channel crop starting at sample 4097, with cutoff 3, | ||
| ``ref_maxbadchannels`` 0.075, and a 1 s processing window, the | ||
| calibration reference keeps 241 samples (#642). An all-zero channel | ||
| that ASR repairs stays exactly zero. MATLAB's ``sqrtm`` leaves a | ||
| roundoff residual on that channel (#643). |
There was a problem hiding this comment.
Important (docs). This table is introduced as "These are intentional. EEGPrep does not reproduce the EEGLAB result." After the switch to +inf, the reference selection half of this row is no longer a deviation. In clean_windows.m, (X-mu)/sig on a zero-variance channel is NaN. MATLAB's sort places NaN last (the highest rank), and NaN > zmax is false, so EEGLAB also keeps 241 samples on this crop. The PR title says the same thing. A migrating user reading this row would conclude that EEGPrep picks a different calibration reference than EEGLAB.
Suggested fix: keep only the #643 part in this table, for example "All-zero channel after ASR: EEGPrep returns exactly zero. MATLAB's sqrtm leaves a roundoff residual (#643)." If the selection behavior needs documenting, describe it as matching EEGLAB in plugins.rst, which this PR already does.
The +inf ranking matches EEGLAB's NaN sort and keeps the same 241 calibration samples, so it does not belong in the known-differences table. Co-authored-by: Suraj Ranganath <[email protected]>
The SHA256 of the repaired samples changes across platforms. The test now locks the 241 kept indices, the +inf score, and the approved clean_asr tolerance against an explicit calibration reference. Co-authored-by: Suraj Ranganath <[email protected]>
Keep the zero-scale channel ranking from #649 alongside the ASRCalibrationError raised when a fit width rounds to zero. Co-authored-by: Suraj Ranganath <[email protected]>
A channel whose window RMS values are all equal is the highest score in every window, so it uses a high-amplitude bad-channel slot. On the reported 17-channel crop the calibration reference keeps 241 samples. An all-zero channel stays exactly zero through ASR, and MATLAB's sqrtm residual on that channel is roundoff.
Confirm on jamming with MATLAB R2025b: uv run python -m tests.fuzz reproduce /mnt/v1/arno/suraj3/pr640/fuzz-out-wide/repros/clean_asr-numeric-data.json and uv run python -m tests.fuzz reproduce /mnt/v1/arno/suraj3/pr640/fuzz-out/repros/pop_clean_rawdata-numeric-data.json.
Fixes #642
Fixes #643