Repository navigation
Report cleaning criteria and accept a RANSAC seed - #605
Conversation
return_diagnostics exposes the noise scores, correlations, flags, window offsets, and z-scores already computed by the cleaners. Default returns stay the same, and channels that are flagged but kept do not write an all-false clean_channel_mask. clean_channels seed defaults to 5489 with the existing RandomState draw order. Docs record which calls replace float32 samples and which leave the input unchanged. Co-authored-by: Suraj Ranganath <[email protected]>
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.
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.
Keep electrode-geometry validation and the recorded FIR design, and keep the optional cleaning diagnostics and the default RANSAC seed of 5489. Co-authored-by: Suraj Ranganath <[email protected]>
|
Claude finished @suraj-ranganath's task in 1m 29s —— View job Code review
BlockingNone. Important
Nits
Test gaps
EEGLAB parity notes
Checklist
I did not run the tests or |
| stored_mask = etc.get('clean_sample_mask') if isinstance(etc, dict) else None | ||
| if stored_mask is not None: | ||
| stored_mask = np.asarray(stored_mask, dtype=bool).copy() |
There was a problem hiding this comment.
Important (AGENTS.md: "defensive None checks for impossible states"): by this point etc is a dict (lines 247–257 already index it and assign into it), and every branch above leaves etc['clean_sample_mask'] set. So isinstance(etc, dict) and stored_mask is not None can never be false. The same applies to the isinstance(etc, dict) on line 245. These checks suggest a state that can't happen.
| stored_mask = etc.get('clean_sample_mask') if isinstance(etc, dict) else None | |
| if stored_mask is not None: | |
| stored_mask = np.asarray(stored_mask, dtype=bool).copy() | |
| stored_mask = np.asarray(etc['clean_sample_mask'], dtype=bool).copy() |
Also drop isinstance(etc, dict) and from line 245.
There was a problem hiding this comment.
🤖 Removed those checks. The mask is already stored on etc, so the report copies that mask directly.
|
|
||
| # replicate MATLAB's default randseed, for exact compatibility | ||
| stream = np.random.RandomState(5489) | ||
| # Replicate MATLAB's default randseed, for exact compatibility. |
There was a problem hiding this comment.
Nit: seed is now a parameter, so this comment is only true for the default. The parity note belongs on DEFAULT_RANSAC_SEED (line 23). There, say that 5489 is MATLAB's default Mersenne Twister seed, which keeps the RANSAC draws aligned with clean_channels.m. That note should replace "keeps the previous fixed draw sequence", which describes history rather than intent. Then delete this line.
| assert inspect.signature(clean_channels).parameters["seed"].default == 5489 | ||
| source = _recording() | ||
| kwargs = _channel_kwargs() | ||
| default = clean_channels(copy.deepcopy(source), **kwargs) | ||
| explicit, explicit_report = clean_channels( | ||
| copy.deepcopy(source), | ||
| **kwargs, | ||
| seed=5489, | ||
| return_diagnostics=True, | ||
| ) | ||
| other, other_report = clean_channels( | ||
| copy.deepcopy(source), | ||
| **kwargs, | ||
| seed=7, | ||
| return_diagnostics=True, | ||
| ) | ||
| np.testing.assert_array_equal(default["data"], explicit["data"]) | ||
| assert explicit_report["seed"] == 5489 | ||
| assert other_report["seed"] == 7 | ||
| expected_default = calc_projector( | ||
| explicit_report["usable_locations"], | ||
| explicit_report["criteria"]["num_samples"], | ||
| explicit_report["criteria"]["subset_count"], | ||
| stream=np.random.RandomState(5489), | ||
| ) | ||
| expected_other = calc_projector( | ||
| other_report["usable_locations"], | ||
| other_report["criteria"]["num_samples"], | ||
| other_report["criteria"]["subset_count"], | ||
| stream=np.random.RandomState(7), | ||
| ) | ||
| np.testing.assert_array_equal(explicit_report["projector"], expected_default) | ||
| np.testing.assert_array_equal(other_report["projector"], expected_other) | ||
| assert not np.array_equal(explicit_report["projector"], other_report["projector"]) |
There was a problem hiding this comment.
Test gap (AGENTS.md §Testing: "Do not write tautological tests that only assert types, constants, or implementation details"):
- Line 125 asserts a default constant through
inspect.signature. - Lines 144–157 rebuild the expected projector with the same
calc_projectorcall that the implementation makes. If seeding or the draw order regressed, both sides would change together and the test would still pass.
Suggested replacement, which tests the behavior users rely on:
- Run twice with
seed=7and assert thecorrelationsare identical (reproducibility). - Assert that
seed=7and the default seed give differentcorrelations(the seed reaches RANSAC). - Keep line 141 (default equals explicit 5489).
…agnostics-seed-f54d Co-authored-by: Suraj Ranganath <[email protected]>
Keep window_length as the sample count of each window, omit removal_suppressed from clean_channels, and copy the sample mask clean_windows already stored. Co-authored-by: Suraj Ranganath <[email protected]>
|
🤖 Dropped criteria window_len_samples. window_length is the sample count of each window in clean_channels, clean_channels_nolocs, and clean_windows. Dropped removal_suppressed from clean_channels, which raises when more than 75% of channels are flagged. clean_channels_nolocs and clean_flatlines still set that key when they keep every flagged channel. |
|
Claude finished @suraj-ranganath's task in 22s —— View job Review skipped: this PR already has a review
The The commits since that review ( One item from that review still needs your action. This PR changes core |
|
The 09:45 review's important code points are fixed in 2e1743f: window_len_samples is gone, removal_suppressed is gone from clean_channels, and the impossible-state checks in clean_windows are gone. I compared 8eb4a98..2e1743f, the branch commits after the develop merge, and the sample and channel mask logic and the RANSAC draws are unchanged, so I did not rerun jamming. The MATLAB-backed cleaning suite already passed on jamming at a2d500a. The leftover nits (the default-seed comment and the tautological seed test) are non-blocking. |
…agnostics-seed-f54d Co-authored-by: Suraj Ranganath <[email protected]> # Conflicts: # docs/source/changelog.rst
Optional return_diagnostics=True reports the noise scores, correlations, flags, window offsets, and z-scores these cleaners already compute. Default returns stay the same. Channels that are flagged and kept are reported separately and do not write an all-false clean_channel_mask. clean_channels seed defaults to 5489, uses RandomState, and is stored in the diagnostics. Docs record which calls replace float32 samples, which copy, and that preserving an original recording takes an explicit copy.
MATLAB is not available here, so MATLAB-backed tests were skipped. The EEGLAB reference suite was not run.
Fixes #535
Fixes #540
Fixes #541