Skip to content

Fix FilterBankSSVEP reusing the first dataset's filter bands - #1368

Open
Srizdebnath wants to merge 2 commits into
NeuroTechX:developfrom
Srizdebnath:fix/filterbank-ssvep-filters-per-dataset
Open

Srizdebnath wants to merge 2 commits into
NeuroTechX:developfrom
Srizdebnath:fix/filterbank-ssvep-filters-per-dataset

Conversation

@Srizdebnath

Copy link
Copy Markdown

What was wrong

FilterBankSSVEP() (and BaseSSVEP(filters=None)) builds its filter bank from the event frequencies of the dataset, one [f - 0.5, f + 0.5] band per frequency. BaseSSVEP.prepare_process did this only while self.filters is None, and wrote the result into self.filters. So the first dataset a paradigm instance processed fixed the bands for good: every later dataset passed through the same instance (an evaluation over several datasets, or moabb.benchmark) was filtered at the first dataset's frequencies, with the first dataset's number of bands.

Reproduction with two fake datasets shaped like Kalunga2016 (13, 17, 21 Hz + rest) and Nakanishi2015 (12 frequencies, 9.25 to 14.75 Hz):

import moabb
moabb.set_log_level("ERROR")
from moabb.datasets.fake import FakeDataset
from moabb.paradigms import FilterBankSSVEP

kal = FakeDataset(event_list=["13", "17", "21", "rest"], paradigm="ssvep", n_subjects=1, code="FakeKalunga")
nak = FakeDataset(event_list=["9.25", "11.25", "13.25", "9.75", "11.75", "13.75", "10.25", "12.25", "14.25", "10.75", "12.75", "14.75"], paradigm="ssvep", n_subjects=1, code="FakeNakanishi")
paradigm = FilterBankSSVEP()
for d in (kal, nak):
    X, y, _ = paradigm.get_data(d, subjects=[1])
    print(d.code.split("-")[0], "classes:", len(set(y)), "bands:", X.shape[-1], [f[0] + 0.5 for f in paradigm.filters])

On develop:

FakeKalunga classes: 4 bands: 3 [13.0, 17.0, 21.0]
FakeNakanishi classes: 12 bands: 3 [13.0, 17.0, 21.0]

With this branch:

FakeKalunga classes: 4 bands: 3 [13.0, 17.0, 21.0]
FakeNakanishi classes: 12 bands: 12 [9.25, 11.25, 13.25, 9.75, 11.75, 13.75, 10.25, 12.25, 14.25, 10.75, 12.75, 14.75]

The second dataset is what a fresh FilterBankSSVEP() gives on it alone, so results depended on the order of the datasets in the run (this is the symptom reported in #659, alongside the first-band issue fixed in #1291).

The fix

BaseSSVEP.__init__ records whether the bands are to be derived from the events (filters is None), and prepare_process derives them again for every dataset in that case. Explicit filters and SSVEP(fmin, fmax) are unchanged.

Tests

  • test_FilterBankSSVEP_filters_follow_each_dataset runs one FilterBankSSVEP() on a 2-frequency and then a 3-frequency fake dataset and checks the bands and the last dimension of X for both. It fails on develop (the second dataset gets 2 bands at 13 and 15 Hz) and passes here.
  • pytest moabb/tests/test_paradigms.py passes; ruff check / ruff format --check are clean on the touched files.
  • Changelog entry under Bugs.

With filters=None, BaseSSVEP.prepare_process builds the bands around the
event frequencies of the dataset, but it stored them in self.filters and
only did so while self.filters was None. Every later dataset processed by
the same paradigm instance was filtered with the first dataset's bands.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-20T14:32:53.509323Z fbd9047 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant