Repository navigation
Add pop_runica icatype pamica through eeg_pamica - #617
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 @neuromechanist's task in 1m 35s —— View job Code review
BlockingNone. Important
Nits
Test gapsNone. The tests exercise real fits, and the replay through EEGLAB parity notes
Checked for correctness bugs, EEGLAB parity, data structure compatibility, changed-behavior tests, and CLAUDE.md/AGENTS.md compliance. |
| A setting you do not pass takes the value EEGLAB's ``runamica15`` uses, such as ``lrate=0.05`` and ``do_newton=True``. | ||
| The exception is ``block_size``, which is pAMICA's own 131072, because EEGLAB's 128 is the block each thread of the Fortran program processes. | ||
| Pass ``pcakeep`` to keep fewer components than channels. | ||
| ``icaweights @ icasphere`` is the unmixing pAMICA applies, and components stay in pAMICA's order unless ``reorder="on"`` sorts them by variance. |
There was a problem hiding this comment.
Nit (docs vs. behavior): pop_runica defaults to reorder='on' (
eegprep/src/eegprep/functions/popfunc/pop_runica.py
Lines 38 to 40 in 04e8de4
pop_runica(EEG, icatype="pamica", gui=False, max_iter=2000)) returns components sorted by variance, not in pAMICA's order. As written, this sentence suggests the opposite. pAMICA's own order is kept only through eeg_pamica directly (sortcomps='off') or with reorder="off".
| ``icaweights @ icasphere`` is the unmixing pAMICA applies, and components stay in pAMICA's order unless ``reorder="on"`` sorts them by variance. | |
| ``icaweights @ icasphere`` is the unmixing pAMICA applies. ``pop_runica`` sorts components by variance by default; pass ``reorder="off"`` to keep pAMICA's order. |
| def test_e1_pamica_matches_amica_on_the_sample_recording(capsys): | ||
| if not is_amica_available(): | ||
| if os.environ.get("EEGPREP_REQUIRE_AMICA") == "1": | ||
| pytest.fail("EEGPREP_REQUIRE_AMICA=1 but the shipped AMICA binary cannot run on this host") | ||
| pytest.skip("the shipped AMICA binary cannot run on this host") |
There was a problem hiding this comment.
Important (CI risk): CI runs pytest tests with no -m "not slow" filter, and the workflow now sets EEGPREP_REQUIRE_AMICA=1 on macOS (
eegprep/.github/workflows/test.yml
Lines 214 to 220 in 04e8de4
Suggested fix: wait for the macOS E1 line on this PR before merging. If it fails, don't keep a known-failing required check. Either move E1 to an opt-in job (e.g., workflow_dispatch or the reference workflow) or reconsider the defaults. Pre-registered thresholds must not be loosened.
…kend # Conflicts: # docs/source/changelog.rst
pop_runica(EEG, icatype='pamica')decomposes with pAMICA's PyTorch engine through the neweeg_pamica, fills the EEGLAB ICA fields, and records the run inEEG['etc']['pamica'].The fit runs in float64 on the CPU with one thread and seed 5489 by default, so the same seed gives identical weights (tested with
numpy.array_equal).icaweights @ icasphereis the unmixing pAMICA applies,icasphereisget_sphere(),icawinvis its pseudo-inverse, andpop_runicasorts components by variance by default, as for the other engines,reorder='off'keeps pAMICA's order, andeeg_pamicacalled directly keeps pAMICA's order by default.did_convergeis true exactly when pAMICA'sstop_reason_is neithermax_iternor degenerate, and it never readsconverged_; a degenerate fit raisesPamicaFitErrorand sets no ICA field.A missing
pamicaortorchraisesImportErrornamingpip install "eegprep[pamica]".New optional extra
pamica = ["pamica==0.4.0"], part ofall; the lock movestorch2.12.0 to 2.12.1 (pAMICA's floor) and addspamicaandjson5.Docs: the
pop_runicahelp, the ICA and installation user guide pages, and the changelog.Card: PX-03.
Interpretations to confirm:
runamica15defaults asrunamica._AMICA_DEFAULTSstates them, for every name pAMICA's torch backend takes whose value matters in a run without rejection: the nine named in the plan plusmax_decs(pAMICAmaxdecs),newtrate,rholratefact,invsigminandinvsigmax.block_sizestays pAMICA's 131072. Rank andpcadbare left topcakeep.icaactisicaweights @ icasphere @ dataas for the other engines, so it differs from pAMICA'stransformby one constant per component (pAMICA removes the channel mean). Withdo_mean=Falsethe two are equal within 1e-10, and the test checks both..github/workflows/test.ymlsetsEEGPREP_REQUIRE_AMICAon the macOS job, not the ubuntu job. The ubuntu-22.04 and Windows jobs skip every AMICA test today (AMICA binary not functional on this platform, in all six ubuntu jobs of the last four runs), while the macOS job runs them. Where the variable is set, the E1 test fails instead of skipping.Rule E1 is a test (
test_e1_reports_pamica_against_amica_on_the_sample_recording, marked slow, 2 hour timeout) that prints one lineE1 min=... median=... amari=... pamica_s=... amica_s=... | reference min>=0.95 median>=0.99 amari<=0.05and asserts nothing about the numbers (see "E1 is informational").It skips with "the shipped AMICA binary cannot run on this host" when the binary cannot run, and is not run locally: the shipped macOS binary is x86_64.
The macOS job of this pull request prints the E1 line.
Measured here, not E1: two pAMICA runs differing only in seed on
sample_data/eeglab_data.set(2000 iterations, 32 channels, about 6.5 minutes each, one thread) give min 0.526, median 0.936, Amari 1.51 with the EEGLAB-valued defaults, and min 0.944, median 0.999, Amari 0.234 with pAMICA's own defaults.E1 is informational:
E1 min=0.9966 median=1.0000 amari=0.0473, which meets the reference values, and the rerun printedE1 min=0.5339 median=0.9842 amari=0.9963, which does not.EEGPREP_REQUIRE_AMICAis set.pamicapackage, not by EEGLAB's AMICA binary, soEEG['etc']['pamica']now also recordsbackend(the pamica class that ran,AMICATorchNG) andpipeline(pamica.AMICA(backend='torch').fit) beside the version and the settings that reproduce the run. A test rebuilds the fit from the record and getsnumpy.array_equalweights.Review of 2026-11-14 (eegprep's Claude review, which saw head 04e8de4):
E1 report (macOS)(needs: lint,macos-latest, Python 3.12, the test job's checkout anduv sync --python 3.12 --all-extras --group dev,EEGPREP_REQUIRE_AMICA=1, running onlytest_e1_reports_pamica_against_amica_on_the_sample_recording). The test job deselects that test with--deselect, so the macOS test job is back to its old length (about 6 to 8 minutes in earlier runs, about 30 minutes with E1 inside), and every run still prints the E1 line. The thresholds, the statistics helper and the defaults are unchanged.On head 55ec52f (run 43630266238) the main macOS leg took 6 minutes (7 minutes 28 seconds, 8 minutes and 6 minutes 10 seconds in three earlier runs) and the E1 job took 28 minutes 36 seconds and printed
E1 min=0.9995 median=1.0000 amari=0.0218 pamica_s=690.2 amica_s=942.0 | reference min>=0.95 median>=0.99 amari<=0.05; every job of that run passed.pop_runicasorts components by variance by default,reorder="off"keeps pAMICA's order, andeeg_pamicacalled directly keeps it by default.runamica15settings with no counterpart in the mapping. Theeeg_pamicadocstring now lists them, checked against_AMICA_DEFAULTSand pAMICA 0.4.0's constructor:lratefact,rholrate,minrho,maxrhoandnewt_rampare pAMICA arguments whose values equal eegprep's;numrej(pAMICAmaxrej, 1 against 3),pcadb,blk_min,blk_stepandblk_maxdiffer and keep pAMICA's values;decwindowand 26 other names (write*,update_*,load_*and similar) have no pAMICA argument.Gates run on this branch:
uv sync --python 3.12 --all-extras --group devruff check .andruff format --check .ty checkuv lock --check./pre-commit.py --changed-from origin/developpytest tests/test_pop_runica_pamica.py tests/test_eeg_amica.py: 42 passed, 2 skipped (E1 and the AMICA binary tests)pytest tests/test_package_help.py tests/test_optional_extras.py tests/test_public_api_examples.py: 28 passed, 1 deselectedNot run: the full
pytest tests(CI runs it) and the EEGLAB reference suite (eeglab-reference.yml);pop_runicagains one branch and no existing path changes.tests/test_sample_data_pop_functions.pyhas four..._without_warning_noisefailures on the macOS development host from numpy'smatmulwarnings inclean_asr; they fail identically ondevelop.Not changed:
eeg_pamicais not in the lazy exports or the API autosummary, andEEG['etc']['pamica']is not copied back whenchanindor a dataset list is used (the same holds foretc['amica']).EEGLAB reference run (AGENTS.md)
AGENTS.md asks for one run of
.github/workflows/eeglab-reference.ymlon the branch of a core-function change;pop_runicagains one additive branch here.The run for this branch (https://github.com/sccn/eegprep/actions/runs/43633199456, on 55ec52f) was cancelled once the cause was known from the run of a sibling branch cut from the same
developcommit (https://github.com/sccn/eegprep/actions/runs/43631767812): all seven shards fail at test setup withFailed: EEGLAB is at 8ac485f654d6bbb1a6acb8dc9ef3f2eaf3d409ba; expected pinned d0963be9d81acc5b66e84f8d3d7c89e3ce127cc4(for examplecore: 2273 passed, 7 skipped, 127 errors).Cause: it is on
develop, not in this pull request:developrecords thesrc/eegprep/eeglabsubmodule at 8ac485f6 whiletests/eeglab_tests/__init__.pypins d0963be9 (issue #622). This pull request changes neither value.The owner, as the human approver, decided on 2026-11-14 to merge with this explanation recorded.