docs: add Geometry-Aware recentering example (cross-session double dissociation) - #1113
Open
rahimipour-meysam-NeurIPS wants to merge 5 commits into
Conversation
# Conflicts: # docs/source/whats_new.rst
The example constructed both CrossSessionEvaluation and WithinSessionEvaluation
with overwrite=True and no suffix=, so Results resolved them to the shared
suffix-less files
results/LeftRightImagery/CrossSessionEvaluation/results_.hdf5
results/LeftRightImagery/WithinSessionEvaluation/results_.hdf5
moabb/analysis/results.py:127-128 implements overwrite by opening that path
with h5py mode "w", which truncates the WHOLE file rather than just this
example expressions rows, and the Results object is built in
BaseEvaluation.__init__ (moabb/evaluations/base.py:465), so truncation happens
at construction time. Those two files are shared with
tutorial_2_using_mulitple_datasets.py, tutorial_3_benchmarking_multiple_pipelines.py
(both overwrite=False; tutorial_3 prose explicitly relies on reusing them) and
advanced_examples/plot_pre_processing_steps.py:140. sphinx-gallery runs examples
in parallel on a warm cache (docs/source/conf.py:209 + .github/workflows/docs.yml:182)
and BaseEvaluation.process returns the frame read back out of the HDF5, so a
mid-flight truncation hands another example an empty frame and, with neither
expected_failing_examples nor only_warn_on_example_error set, takes the whole
gallery down.
Adding suffix="geometry_aware" is the fix already used by
plot_riemannian_artifact_rejection.py (suffix="rar_tutorial"),
plot_select_electrodes_resample.py (suffix="resample") and
plot_use_an_X_y_dataset.py (suffix="motan").
Verified: the example now writes results_geometry_aware.hdf5 and a marker
planted in the shared results_.hdf5 survives the run; scores are unchanged.
Cosmetic only, no behaviour change (scores byte-identical before and after): - Rename make_geometry_aware -> make_ts_pipeline and give it a docstring. The old name was actively misleading: make_geometry_aware(tsupdate=False) returns the pipeline that is NOT geometry-aware. - Index within_means[name] / cross_means[name] directly instead of .get(name, np.nan), so a pipeline missing from the results raises a loud KeyError instead of silently rendering a blank bar. - Reuse the cross_means already bound three lines earlier for the final print instead of recomputing the same groupby, matching the within_means line above. - whats_new.rst: use a double-backtick literal for the example path instead of the :file: role. :file: appears nowhere else in whats_new.rst on develop; the established form is the literal, cf. the plot_riemannian_artifact_rejection.py bullet four lines above.
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.
What this adds
A single reproducible example,
examples/advanced_examples/plot_geometry_aware_recentering.py, demonstrating unsupervised test-time tangent-space recentering (TangentSpace(tsupdate=True)) for cross-session EEG motor-imagery decoding.The example reproduces a within/cross double dissociation: recentering gives a clear advantage under
CrossSessionEvaluation(there is a between-session covariance shift to correct), while the same two pipelines (recenter on vs. off) are close to indistinguishable underWithinSessionEvaluation(no such shift exists there). This isolates recentering — rather than the choice of final classifier — as the mechanism behind the cross-session gain.This follows the same pattern as
plot_euclidean_alignment.py(#1109): no new class or module is introduced (the mechanism already exists inpyriemannviaTangentSpace(tsupdate=True)and, more generally,pyriemann.transfer.TLCenter), just a documented, runnable demonstration using MOABB's own evaluation classes.Background
The result reproduced here is from a manuscript currently in preparation:
The full study benchmarks this recentering pipeline against classical Riemannian baselines and deep sequence models (a bidirectional Mamba mixture-of-experts, an SPDNet-style network) across eight public MOABB datasets, with full statistical validation (Friedman omnibus, FDR/Holm-corrected Wilcoxon, Cohen's d, bootstrap CIs, Critical-Difference analysis). This PR only reproduces the core within/cross mechanism on a single dataset, as a self-contained gallery example — not the full benchmark.
I reached out to Sylvain Chevallier by email about this direction and he mentioned PRs to MOABB are welcome, which is what prompted this contribution.
Checklist
BNCI2014_001, bothCrossSessionEvaluationandWithinSessionEvaluation)docs/source/whats_new.rstupdated under "Enhancements"pyriemannandmoabbevaluation classes only)