Skip to content

[ICA] Record pAMICA rejection with EEGLAB defaults - #674

Merged
suraj-ranganath merged 2 commits into
developfrom
agent/20261123-fix-671
Nov 24, 2026
Merged

suraj-ranganath merged 2 commits into
developfrom
agent/20261123-fix-671

Conversation

@claude

@claude claude Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

eeg_pamica now copies pAMICA's rejection settings as the backend ran them (do_reject, rejsig, rejstart, rejint, maxrej) and their outcome (rejection_passes, n_good_samples, n_rejected_samples) into EEG.etc['pamica'], so pipelines that enable rejection can report how many samples were dropped. Adds a test that a rejecting fit records these values and still replays from its record.

Fixes #671

The sentence above this block is from the first draft and is wrong: the pass count is rejection_passes, not numrej. numrej is only the EEGLAB spelling of the maxrej setting.

eeg_pamica applies EEGLAB's AMICA rejection defaults and records the outcome under names that do not collide with those settings. do_reject=True allows 3 passes, EEGLAB's numrej, instead of pAMICA's own maxrej of 1. The passes that ran are rejection_passes. With rejection on, the weights are the last iterate, named returned_iter, and best_iter is omitted because those likelihoods were averaged over different samples.

Settings: do_reject, rejsig, rejstart, rejint, maxrej.
Outcome: rejection_passes, n_good_samples, n_rejected_samples. returned_iter is stored only when do_reject is on. Counts only, no per-sample mask.

EEGLAB runamica15.m pAMICA
do_reject (default 0) do_reject (flag, default False)
numrej (default 3) maxrej (pAMICA's own default is 1)
rejsig (default 3.0) rejsig
rejstart (default 2) rejstart (iterations counted from 1)
rejint (default 3) rejint (iterations counted from 1)

rejstart and rejint match Fortran AMICA. In pamica 0.4.0, schedule.rejection_due (schedule.py lines 136-149) adds 1 to the 0-based loop index and then uses the same predicate as amica15.f90 line 1136: do_reject and maxrej > 0 and (iter == rejstart or (mod(max(1, iter - rejstart), rejint) == 0 and the pass count < maxrej)). The first pass is iteration rejstart on both sides. Later passes are every rejint iterations. maxrej stops the count. The iter == rejstart arm does not consult the pass count, on both sides.

best_iter is omitted under do_reject, and keep_best is not written into the record. pAMICA leaves keep_best True and does not use it, then returns the last iterate. Storing keep_best: False would say the caller turned the safeguard off, and storing best_iter beside it would still present argmax of the likelihood history as the source of the weights. Those likelihoods are divided by that iteration's good-sample count, so the maximum is not where the weights came from.

Defaults test before this mapping, do_reject=True alone:
AssertionError: {'maxrej': 1} != {'maxrej': 3}
Omitting 4 identical items: do_reject True, rejsig 3.0, rejstart 2, rejint 3.

After, eeg_pamica(EEG, max_iter=4, do_reject=True):
{'do_reject': True, 'maxrej': 3, 'rejsig': 3.0, 'rejstart': 2, 'rejint': 3, 'rejection_passes': 1, 'returned_iter': 3, 'n_good_samples': 2954, 'n_rejected_samples': 46}
test_do_reject_alone_records_the_runamica_rejection_defaults PASSED

Fixes #671

Open in Web Open in Cursor 

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Code review skipped — your organization has no extra usage available to pay for this review.

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
claude Bot force-pushed the agent/20261123-fix-671 branch from 9d894bf to 607973e Compare November 23, 2026 19:18
@cursor
cursor Bot marked this pull request as draft November 23, 2026 22:57
Map do_reject, numrej, rejsig, rejstart and rejint so a rejecting fit
allows three passes. Record the passes that ran as rejection_passes,
and name the last iterate returned_iter instead of best_iter.

Co-authored-by: Suraj Ranganath <[email protected]>
@cursor cursor Bot changed the title [ICA] Record pAMICA sample rejection settings and counts [ICA] Record pAMICA rejection with EEGLAB defaults Nov 23, 2026
@suraj-ranganath
suraj-ranganath marked this pull request as ready for review November 24, 2026 00:11
@suraj-ranganath
suraj-ranganath marked this pull request as draft November 24, 2026 00:11
@suraj-ranganath
suraj-ranganath marked this pull request as ready for review November 24, 2026 00:12

Copy link
Copy Markdown
Member

claude review this

@suraj-ranganath
suraj-ranganath marked this pull request as draft November 24, 2026 01:54
@suraj-ranganath
suraj-ranganath marked this pull request as ready for review November 24, 2026 01:54

Copy link
Copy Markdown
Member

claude review this

@claude

claude Bot commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Code review

  • Overall assessment: Looks good.
  • Highest-risk area: None identified.
  • Merge recommendation: Safe to merge.

Blocking

None.

Important

None.

Nits

None.

Test gaps

None.

EEGLAB parity notes

None.

Checked for correctness bugs, EEGLAB parity, data structure compatibility, changed-behavior tests, and CLAUDE.md/AGENTS.md compliance. Specific areas checked: numrej → maxrej alias resolution and conflict error in eeg_pamica (including the lowercased pop_runica path), rejection defaults against runamica._AMICA_DEFAULTS (do_reject 0, numrej 3, rejsig 3.0, rejstart 2, rejint 3), recorded settings taken from the backend so the record replays, best_iter/best_ll omitted under rejection (no other consumers in the repo), RESULT_KEYS updated so outcome keys are not fed back into replay, scalar round-trip through pop_saveset/pop_loadset, epoched sample counts, and the docs/changelog sync.

@suraj-ranganath
suraj-ranganath merged commit 7e17c30 into develop Nov 24, 2026
15 checks passed
@cursor cursor Bot mentioned this pull request Nov 24, 2026
29 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

eeg_pamica: export rejected-sample counts (numrej, n_good_samples)

2 participants