Skip to content

Cho2017: per-class tiled streams + a low high-pass give a class-dependent pre-cue baseline (the second before the cue decodes left/right at up to 0.98) #1340

Open

Description

@YihengLi-1

What happens

Cho2017._get_single_subject_data (moabb/datasets/gigadb.py) builds one continuous Raw by demeaning each class
stream separately and stacking [all left trials, 500 zeros, all right trials]. The GigaDB files are not continuous
recordings: each class is 100 (or 120) tiled 7-s blocks (fixation 0-2 s, cue at 2 s, stored to 7 s).

About a quarter of the participants make a large, sustained horizontal gaze shift toward the imagined hand that starts
~0.55 s after the cue and has not returned by the end of the stored block (it is a real eye movement, see the F8-F7 /
AF8-AF7 / Fp2-Fp1 traces; details in a separate analysis). Because every block is "flat, then class-locked deviation
to the end", any demeaning or high-pass of these blocks, whether per class stream (what the loader does), per block,
or after re-ordering the blocks in session order, puts a class-dependent offset on the segment BEFORE the cue:

  • fmin=None (loader demeaning only) or fmin=0.1: the pre-cue level is about -0.45 x the real post-cue step, opposite sign.
  • fmin=0.5 or fmin=1 (method="iir" zero-phase, as get_filter_pipeline does): the DC part is gone but the filter's
    pre-ringing of the late step leaves a same-sign hump in the pre-cue second.

Consequences for users who epoch with tmin < 0 (relative to the cue) and a low fmin, which is common for deep-learning
pipelines: the second before the cue is not a class-neutral baseline. A trivial classifier on it beats chance, and any
model that sees that window can use it. The default LeftRightImagery() / MotorImagery() (8-32 Hz, interval 0-3 s)
is NOT affected.

Numbers (MOABB 1.7.2, LeftRightImagery(fmin, fmax, tmin=-1.0, tmax=3.0), 52 subjects, GigaDB files as downloaded)

F8-F7 mean over -1..0 s, right-hand minus left-hand trials, in the dataset's own units (what MOABB stores as uV):

fmin-fmax 13 strongest subjects all 52 pre-cue-only LDA (mean of F8-F7, AF8-AF7, Fp2-Fp1 in -1..0 s), 5x10-fold subjects above permutation 95th pct
8-32 (default) 0 0 0.50 (strong 0.50) 3/52
1-40 -15 -5 0.52 (strong 0.58) 7/52
0.5-100 +326 +82 0.57 (strong 0.79, max 0.98) 14/52
0.1-100 -3329 -851 0.60 (strong 0.84, max 1.00) 22/52
None (no filter) -3618 -906 drift-limited 6/52

The real post-cue step (raw file, each trial baseline-corrected by its own pre-cue second, F8-F7 1-3 s) is +7569 in the
strong group and +1964 over all subjects, so the no-filter / 0.1-Hz offset is ~45 % of the actual class signal, placed
before the cue with the wrong sign. At 0.5-100 Hz the second before the cue decodes the class better than 1-3 s after
it in several subjects (s05: 0.978 vs 0.791), because the 0.5-Hz IIR compresses the sustained shift into a ~1-s pulse
whose pre-ringing lands in the pre-cue window.

Things that do NOT fix it (all measured): reordering the blocks into session order with GigaDB's trial_sequence files
(+383 / 0.84 in the strong group), filtering each 7-s block separately (+308 / 0.80), EDGE annotations between blocks
(MOABB's SetRawAnnotations drops them before Raw.filter runs anyway). baseline=(-1, 0) in the paradigm zeroes the
pre-cue mean, but a class-dependent slope from the filter pre-ringing remains in the pre-cue second (slope-only LDA:
0.61 in the strong group vs 0.50 on the raw unfiltered file).

Minimal reproduction

import numpy as np
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis
from sklearn.model_selection import cross_val_score
from moabb.datasets import Cho2017
from moabb.paradigms import LeftRightImagery

ds = Cho2017()
for fmin, fmax in [(8, 32), (0.5, 100), (0.1, 100)]:
    p = LeftRightImagery(fmin=fmin, fmax=fmax, tmin=-1.0, tmax=3.0)   # -1..3 s around the cue
    ep, y, _ = p.get_data(ds, subjects=[5], return_epochs=True)
    y = np.asarray(y)
    x = ep.copy().pick(["F8", "F7"]).get_data() * 1e6
    heog = x[:, 0] - x[:, 1]
    pre = heog[:, ep.times < 0].mean(1)                              # the second BEFORE the cue
    post = heog[:, (ep.times >= 1) & (ep.times < 3)].mean(1)
    print(fmin, fmax, "pre-cue F8-F7 left/right:", pre[y == "left_hand"].mean(), pre[y == "right_hand"].mean(),
          "| LDA acc from pre-cue second:", cross_val_score(LinearDiscriminantAnalysis(), pre[:, None], y, cv=5).mean(),
          "| from 1-3 s:", cross_val_score(LinearDiscriminantAnalysis(), post[:, None], y, cv=5).mean())

Output on subject 5:

8 32 pre-cue F8-F7 left/right:    0.5     0.0 | LDA acc from pre-cue second: 0.480 | from 1-3 s: 0.505
0.5 100 pre-cue F8-F7 left/right: -185.4  344.4 | LDA acc from pre-cue second: 0.955 | from 1-3 s: 0.800
0.1 100 pre-cue F8-F7 left/right: 1161.5 -3048.3 | LDA acc from pre-cue second: 0.965 | from 1-3 s: 0.990

Proposed fix

  1. moabb/datasets/gigadb.py: document the layout hazard in the Cho2017 docstring and make the existing
    log.warning say it explicitly ("trials are tiled per class; with fmin below a few Hz the pre-cue segment has a
    class-dependent offset; use the default fmin=8 or pass baseline=(-1, 0); do not treat the pre-cue interval as a
    neutral baseline").
  2. moabb/datasets/gigadb.py: replace the per-class-stream demeaning by a per-block demeaning on each block's own
    2-s fixation period (imagery_event gives the block onsets). This removes the DC-level class offset for users
    with no / very low high-pass and changes nothing for fmin >= 0.5 or the default pipeline. It does not remove
    filter pre-ringing, which only a pre-cue baseline or a high enough fmin avoids.
  3. moabb/paradigms/base.py: warn when a dataset with METADATA.data_structure.trials_context == "per_class"
    (currently only Cho2017) is processed with fmin < 4 and baseline=None.

I can open a PR for 1-3 if the maintainers agree with the direction. Related loaders that build the Raw from pre-cut,
per-trial-demeaned blocks (Weibo2014, Wang2016, Nakanishi2015, Chen2017) share the per-block part of the
mechanism and may deserve a docstring note; not measured here.

Activity

  1. YihengLi-1 commented on Nov 4, 2026

    @YihengLi-1
    ContributorAuthor

    Opened #1341 for items 1 and 2. A correction to what I wrote above: the per-block demeaning removes the pre-cue class offset only for fmin=None. With a 0.1 Hz high-pass the offset comes back at almost the same size (subject 5: -4210 before, -4105 after), because the filter removes the mean of the periodic block pattern regardless of how the loader demeaned it. For low fmin the remedy is the default fmin or a pre-cue baseline, which the new docstring section says. Numbers for all five filter settings are in the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions