Phase 1: core MNE wrapper (single-model)#187
Merged
neuromechanist merged 7 commits intoJul 18, 2026
Merged
Conversation
Member
Author
Review (5 Sonnet reviewers: code, tests, comments, silent-failure, type-design)All findings were real (no false positives); every one is addressed in commits 77bb814 / 9d8fff3 / 8365412. Reviewers confirmed the core mapping math is correct and independently re-derived it. Correctness / robustness (
|
neuromechanist
merged commit Jul 18, 2026
9a5933e
into
feature/issue-139-epic-mne-compat
7 checks passed
This was referenced Jul 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
pamica.mne_compat.AMICAICA, an MNE-Python-facing wrapper that fits AMICA directly from anmne.io.Raw/Epochsand interoperates with the standard MNE ICA consumer surface (get_sources,apply,get_components,plot_components). Its core value-add isto_mne_ica(), which maps pamica's fitted mean/sphere/unmixing into a fully-populatedmne.preprocessing.ICA; the other methods delegate to that object so MNE performs the export/plot/back-projection machinery unchanged.This is purely additive (issue #139 scope): the scikit-learn-style
AMICAAPI and the byte-identical EEGLAB I/O are untouched. MNE is an optional extra (pip install pamica[mne]), imported lazily exactly like themlxextra, soimport pamicanever requires it.Closes #140. Part of epic #139.
The mapping (single-model)
pamica computes
S = W_fort @ sphere @ (X - mean)(the per-model centercis exactly zero for one model). MNE computesS = unmixing_matrix_ @ pca_components_ @ (X - pca_mean_)with a unit pre-whitener. Writing the symmetric-ZCAsphereasV diag(1/sqrt(e)) V^TwithVorthonormal, the export setspca_components_ = V^T,unmixing_matrix_ = W_fort @ sphere @ V,pca_mean_ = mean. Keepingpca_components_orthonormal is what makes MNE'sget_components()(channel-space mapsinv(sphere) @ inv(W_fort)) come out right, since MNE assumes orthonormal PCA rows.Measured on real sample EEG:
get_sourcesvsAMICA.transformagree to 4e-14,apply()with no exclusions reconstructs to 1e-18, andget_components()matchesinv(sphere) @ inv(W_fort)to 3e-20.Test plan
pamica/tests/mne_tests/on the real bundledeeglab_data.set(no mocks), 11 tests: theget_sources == transformround trip (single-model crux), channel-space scalp maps,applyreconstruct/exclude, epochs and channel-subset fits, plotting, and unfitted/bad-input guards.mneextra (importorskip), so the basetestjob skips it; a dedicatedtest-mneCI job installspamica[mne]and runs it for real on Linux (mne is pip-installable there, unlike the Apple-only mlx extra).pamica/mne_compatis omitted from base coverage (base env has no mne), same treatment asmlx_impl.ruff check/format,ty check ., the 11 mne tests, andmkdocs build --strict.Docs
New
docs/api/mne-compat.md(usage +to_mne_icainterop + mkdocstrings), nav + API-index entries, and a## 0.3.0changelog section.