Repository navigation
Cho2017: demean each trial block by its own fixation period, document the per-class tiled layout (#1340) - #1341
Merged
bruAristimunha merged 1 commit intoNov 8, 2026
Conversation
…hXgh-1340) The GigaDB files store each class as a stream of tiled 7-s blocks (2 s fixation, cue, 5 s after the cue). The loader removed the mean of each class stream as a whole; with a sustained class-locked eye movement after the cue, that mean differs by class and put a class-dependent offset on the pre-cue segment of every trial when no high-pass was used. Each block is now demeaned by its own fixation period. Document the per-class tiled layout in the Cho2017 docstring: with fmin below a few Hz the filter itself puts a class-dependent offset before the cue, so use the default fmin or a pre-cue baseline. The default 8-32 Hz band, interval and paradigm behaviour are unchanged. Add an offline regression test on a synthetic tiled file.
bruAristimunha
force-pushed
the
cho2017-per-block-baseline
branch
from
November 8, 2026 13:14
54459c9 to
935fffe
Compare
bruAristimunha
approved these changes
Nov 8, 2026
bruAristimunha
left a comment
Collaborator
There was a problem hiding this comment.
Lean already. Ship.
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 changes
Closes part of #1340 (items 1 and 2 of the proposed fix; the paradigm warning, item 3, is left out of this PR).
The GigaDB files store each class as one stream of 100 (or 120) tiled 7-s blocks: 2 s of fixation, the cue, then 5 s.
Cho2017._get_single_subject_dataremoved the mean of each class stream as a whole. In participants with a sustained eye movement toward the imagined hand after the cue, that mean differs by class, so the pre-cue segment of every trial got a class-dependent offset of about half the post-cue step, with the opposite sign.moabb/datasets/gigadb.py: a small helper_demean_blocksremoves from each block the mean of its own fixation period. Block boundaries come fromimagery_event: the first cue sample is also the fixation length of every block. The stacking (left stream, 500 zeros, right stream), scaling, events and channel layout are unchanged.Cho2017docstring: a new Data layout section. It says the trials are per-class tiled streams, that the per-block demeaning makes the unfiltered pre-cue segment class-neutral, and that withfminbelow a few Hz the band-pass filter itself spreads the post-cue deviation into the pre-cue samples. It recommends the defaultfminor a pre-cuebaseline(e.g.baseline=(-1, 0)withtmin=-1). The existinglog.warningpoints to this section.moabb/tests/test_cho2017_baseline.py: an offline test. It builds a tiny synthetic per-class tiled file (68 channels, 10 blocks per class, a class-locked step after the cue, a random DC level per block), monkeypatchesloadmatanddata_path, and checks that after the loader every block's fixation period is zero-mean in both classes and the post-cue class difference is kept. It also checks that the former per-stream demeaning gave the pre-cue segment a class-dependent offset. The test fails ondevelopand passes with this change.docs/source/whats_new.rst: Bugs entry.What does not change
LeftRightImagery()/MotorImagery()(8-32 Hz, 0-3 s) return identical data: subject 5 values below are the same before and after.moabb/paradigms/. No new dependency.fmin=Noneget different (cleaner) data. Their pre-cue segment loses the class offset, and slow block-to-block DC steps are removed.A correction to the issue
The issue said the per-block demeaning would remove the class offset "for users with no / very low high-pass". It only does so for
fmin=None. A 0.1-Hz high-pass removes the mean of the periodic block pattern ("flat, then deviation to the end of the block") whatever the loader did before. So the 0.1-Hz offset comes back at almost the same size. The 0.5-Hz pre-ringing also stays, as the issue already said. For those cutoffs the docstring note (and a pre-cue baseline or a higherfmin) is the remedy, not the loader.Numbers (subject 5,
repro_issue.pyfrom the issue plusfmin=Noneand 1-40 Hz)LeftRightImagery(fmin, fmax, tmin=-1.0, tmax=3.0). F8-F7 mean over the second before the cue (file units), and 5-fold LDA accuracy on that single feature. Before =develop@bed9f0fa, after = this branch.With no filter the pre-cue LDA was already at chance before the fix, because slow drift between blocks does not generalise across folds. The fix removes the -4313 offset itself, and the same drift removal lets the real post-cue signal decode (0.500 to 0.995).
Checks
pre-commit run --fileson the three changed files: all hooks pass (ruff, ruff-format, codespell, whitespace).pytest moabb/tests -k "Cho2017 and not test_download": 22 passed, 4 skipped (need--dl-data, plotly, optuna, or have no second DOI to compare).pytest moabb/tests/test_cho2017_baseline.py test_metadata.py test_summary_trials.py test_dataset_metadata_regressions.py test_compilation.py: 696 passed.Possible follow-ups, not in this PR: the paradigm warning (item 3 of #1340), and docstring notes for
Weibo2014,Wang2016,Nakanishi2015,Chen2017, which also build their Raw from per-trial-demeaned blocks.