Phase 2: multi-model exposure for MNE users#188
Merged
neuromechanist merged 7 commits intoJul 18, 2026
Merged
Conversation
Member
Author
Review (5 Sonnet reviewers: code, tests, comments, silent-failure, type-design)All actionable findings addressed in commits 0044c98 / fd500f9 / 0743b44. The code-reviewer found nothing above its confidence bar and independently confirmed the c-fold math, softmax stability, Correctness / robustness
Docs / comments
Tests (the reviewers' gaps)
Kept as intended design (with rationale)
Local gates green after fixes: ruff, |
neuromechanist
merged commit Jul 18, 2026
9f2d44f
into
feature/issue-139-epic-mne-compat
7 checks passed
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
Exposes multi-model AMICA through the MNE wrapper (
AMICAICA(n_models=...)). MNE'sICArepresents only one unmixing matrix, so we work with current MNE, not around it: each model is exported as its own single-modelmne.preprocessing.ICA, and the per-sample model dominance MNE cannot represent is exposed directly. No MNE fork or extension needed.Closes #141. Part of epic #139.
What's new
Backend (a public live posterior accessor):
AMICATorchNG.model_loglik(X)returns the per-model per-sample log-likelihoodLhtfor arbitrary data, scored through the stored sphere/mean (never re-preprocessing), andmodel_probability(X)is its column-wise softmax over models (P(model | sample)). Both are delegated on theAMICAwrapper. The training-data path is pinned bit-for-bit against the E-step's own_llt_lht(FortranLht, #155).Wrapper (
AMICAICA):n_modelsconstructor argument.to_mne_ica(model_idx=...)exports any model; the consumer methods (get_sources/apply/get_components/plot_components/plot_sources) all takemodel_idx. Per-model exports are cached separately.cintopca_mean_(mean + inv(sphere) @ c), the piece phase 1 could skip because single-modelcis zero. Verified:to_mne_ica(model_idx=h).get_sources(raw)reproducesAMICA.transform(raw, model_idx=h)for every model at ~6e-14, withcconfirmed nonzero.get_model_probability(inst)returns(n_models, n_samples)dominance;plot_model_probability(inst)draws per-model probability + best-model LL (srate defaults to the fitted recording's rate).viz:
pamica.viz.plot_model_probabilitynow also accepts a livelhtarray (not only a writtenAmicaOutput), reused by the wrapper's dominance plot. Backward compatible; all 34 existing viz tests pass.Test plan
pamica/tests/torch_tests/test_ng_model_posterior.py(base CI, real EEG) —model_loglikvs_llt_lhtbit-for-bit, posterior normalization, single-model all-ones, stored-sphere invariance, unfit guard,AMICA-wrapper delegation.lhtpath equals theAmicaOutputpath, exactly-one-source and 2-D guards.test-mnejob): per-model round trip with nonzeroc, distinct per-model exports, per-modelapply, dominance normalization, single-model all-ones, the dominance plot, out-of-rangemodel_idx.ty check .,mkdocs build --strict, typos, and the full backend/viz/mne suites.