Repository navigation
[pop_runica] Reduce rank-deficient runica to the estimated rank - #601
Conversation
Average-referenced data fails EEGLAB's covariance-eigenvalue rank check. Pass that rank as pca unless the caller set pca, and record it in history. 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.
EEGLAB's icawinv*icaweights*icasphere*data leaves its own PCA projector by 5.7e-8 after RMS scaling. EEGPrep stays on that projector. 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.
Keep the pop_runica rank changelog entry with the newer unreleased notes. Co-authored-by: Suraj Ranganath <[email protected]>
|
Claude finished @suraj-ranganath's task in 1m 38s —— View job Code review
BlockingNone. Important
Nits
Test gaps
EEGLAB parity notes
· Branch: |
| def _options_for_ica_backend(EEG, icatype, options): | ||
| if icatype != "runica": | ||
| return options | ||
| return apply_runica_data_rank(EEG["data"], options, pca_requested="pca" in options) |
There was a problem hiding this comment.
Important: the check for an explicit pca is case-sensitive.
_normalise_ica_options does not lowercase dict options. So pop_runica(EEG, icatype='runica', options={'PCA': 20}) misses this check, and the rank estimate adds pca=31. runica then lowercases keys through parse_key_value_args, and the later pca=31 overrides the user's 20. History records both keys. EEGLAB matches option names with strcmpi.
The same check exists in eeg_runica (if 'pca' not in kwargs), so eeg_runica(EEG, PCA=20) has the same problem.
Suggested fix: check the key case-insensitively in both places, and add a test with options={'PCA': 20}.
| return apply_runica_data_rank(EEG["data"], options, pca_requested="pca" in options) | |
| return apply_runica_data_rank( | |
| EEG["data"], options, pca_requested=any(str(key).lower() == "pca" for key in options) | |
| ) |
(eeg_runica.py needs the matching change.)
EEGLAB matches the pca option with strcmpi. An uppercase key is the caller's choice, so it is not replaced by the estimated rank. Co-authored-by: Suraj Ranganath <[email protected]>
|
Claude finished @suraj-ranganath's task in 1m 25s —— View job Code review
BlockingNone. Important
Nits
Test gapsNone. The tests cover:
EEGLAB parity notes
|
| def apply_runica_data_rank(data, options, *, pca_requested): | ||
| """Return ``options`` with ``pca`` set from :func:`eeglab_data_rank` when needed.""" | ||
| options = dict(options) | ||
| if pca_requested or _pca_option_key(options) is not None: | ||
| logger.warning( | ||
| "you have used PCA to reduce dimensionality so ICA " | ||
| "is not modeling the entire data, only the PCA-reduced data." | ||
| ) | ||
| eeglab_data_rank(data, pca_requested=True) | ||
| return options | ||
| rank = eeglab_data_rank(data, pca_requested=False) |
There was a problem hiding this comment.
Nit: pca_requested repeats what the function can already work out from options.
Both callers compute it from options. pop_runica._options_for_ica_backend passes _pca_option_key(options) is not None. eeg_runica passes False only when that key is absent. Line 67 then checks _pca_option_key(options) again. The flag never adds information, and AGENTS.md lists boolean dispatch as a pattern to avoid.
The explicit-pca branch also runs a full SVD and covariance eigendecomposition (line 72) and discards the result, only to maybe log EEGLAB's inconsistency warning.
Suggested fix: remove the parameter and branch on _pca_option_key(options) alone. Then change the callers to apply_runica_data_rank(EEG["data"], options) in pop_runica.py:248 and apply_runica_data_rank(data, kwargs) in eeg_runica.py:116. The if guard in eeg_runica becomes unnecessary.
There was a problem hiding this comment.
Non-blocking. The flag is redundant with _pca_option_key, and the extra SVD on an explicit pca only feeds the inconsistency warning. It does not change the stored pca or the fit. Leaving it as is.
pop_runica is not the only caller. eeg_runica applies the same estimate, and bids_preproc's runica stage calls eeg_runica. Co-authored-by: Suraj Ranganath <[email protected]>
|
Claude finished @suraj-ranganath's task in 1m 1s —— View job Code review
BlockingNone. Important
NitsThese were raised in the last review and are still open:
Test gapsNone. The tests cover:
EEGLAB parity notes
|
|
The latest review has no blocking points. The MATLAB parity tests that this PR asks for were run on jamming at e510e05, which is the same code as 0d9b165 except for docs. tests/test_runica.py::TestRunicaParity passed, including test_parity_average_reference_pop_runica_rank. The other runica and pop_runica tests also passed. The pca_requested flag, the second rank estimate on full-rank data, and test_matlab_eps_at_zero_is_eps_of_one are nits. They do not change the estimated rank or the recorded pca, so I am leaving them. |
pop_runica passes the estimated runica rank as pca and records it. An explicit pca is unchanged. Direct runica still spheres every channel and is ill-conditioned on an average-reference null. Reconstruction is compared with the rank-31 PCA projection at the existing sphere tolerance, rtol 1e-10 and atol 1e-12. Aligned maps use the existing 0.9999 correlation bound: their elementwise difference is 6.3e-7 because EEGLAB's scaled product leaves its projector by 5.7e-8. Please rerun tests/test_runica.py::TestRunicaParity::test_parity_average_reference_pop_runica_rank. The reference suite was not run here.
Fixes #567