feat(preprocessing): add EuclideanAlignment trial-level transformer#1109
Merged
Conversation
Add `moabb.datasets.preprocessing.EuclideanAlignment`, a trial-level
Euclidean Alignment transformer (He & Wu 2020; Junqueira et al. 2024)
that whitens each trial by the inverse square root of the Euclidean mean
covariance to remove per-domain covariance shift before a (deep) model
sees the data.
- Inductive and leakage-free by default: `fit` learns the reference from
training trials, `transform` re-applies it to unseen trials;
`fit_transform` gives the transductive per-recording form.
- Accepts an mne.Epochs or an (n_trials, n_channels, n_times) ndarray.
- Shrinkage covariance estimator ("lwf") for robustness; adds no new
dependency (pyriemann >= 0.11 already required).
- Distinct from pyriemann.transfer.TLCenter (covariance-matrix level).
Tests cover the alignment invariants, the inductive fit->transform
contract, Epochs/ndarray inputs, and the sklearn estimator contract.
Add API reference entry, whats_new note, and a cross-subject gallery
example demonstrating EA on CSP+LDA.
Closes #1108
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.
Closes #1108.
What
Adds
moabb.datasets.preprocessing.EuclideanAlignment, a generic, inductive, robust trial-level alignment transformer. Euclidean Alignment (He & Wu, 2020) whitens each trial by the inverse square root of the Euclidean (arithmetic) mean of the per-trial covariances, removing per-domain (subject/session/recording) covariance shift before a trial-input model sees the data.Why this shape
fitstoresinv_sqrt_ref_from train only;transformreuses it on test. The transductive form is justfit_transformon one recording — same object, no second class.estimator="lwf") +pyriemann.utils.base.invsqrtm+check_is_fitted. The Euclidean mean is the arithmetic mean of the per-trial covariances, so nomean_covariancecall is needed.mne.Epochs(viaget_data) or an(n_trials, n_channels, n_times)ndarray; returns an ndarray of the same shape.pyriemann >= 0.11is already a hard moabb requirement (imported lazily insidefitso the deprecation-warning paths are only paid by users of this class).pyriemann.transfer.TLCenter, which recenters covariance matrices for Riemannian pipelines rather than the raw trials a (deep) network ingests.Scoped to Euclidean alignment specifically (rather than a generic
metric=selector) so the name matches the behaviour; Riemannian/log-Euclidean siblings can be added later if needed.Tests
moabb/tests/test_preprocessing.py(all pass): exact whitening with the linearcovestimator; covariance-shift reduction acrosslwf/scm/oas; SPD whitener; inductive no-leakage;fit_transform == fit().transform(); Epochs ≡ ndarray; not-fitted + bad-ndim raises; sklearnclone/get_paramscontract.Docs
docs/source/api.rst(preprocessing.EuclideanAlignment).docs/source/whats_new.rstenhancement entry.examples/advanced_examples/plot_euclidean_alignment.py: a leave-one-subject-out cross-subject demo on BNCI2014_001 / LeftRightImagery showing (1) the between-subject covariance dispersion collapsing after EA and (2) CSP+LDA transfer improving with per-subject EA, grounded in Junqueira, Aristimunha, Chevallier & de Camargo (2024).References