Skip to content

Let get_data return nested trials when recordings differ in channels or samples - #1327

Merged
bruAristimunha merged 4 commits into
NeuroTechX:developfrom
bruAristimunha:feat/ragged-trials
Oct 24, 2026
Merged

bruAristimunha merged 4 commits into
NeuroTechX:developfrom
bruAristimunha:feat/ragged-trials

Conversation

@bruAristimunha

Copy link
Copy Markdown
Collaborator

First of three steps from the review of #1305 (cross-system evaluation): make the existing API handle recordings of different shapes, so no new evaluation class is needed.

Where it broke. BaseParadigm.get_data ends with np.concatenate(X) (or mne.concatenate_epochs). Datasets with different montages or sampling rates pooled in a CompoundDataset failed there: "all the input array dimensions ... must match exactly".

Change (+40 lines of code):

  • same-shaped recordings still give a regular array; otherwise get_data returns a nested object array of shape (n_trials,) with each trial's (n_channels, n_times) array (logged at WARNING);
  • _get_nchan accepts nested arrays (largest channel count), the only evaluation code that read X.shape[1];
  • return_epochs=True on such recordings raises a clear error pointing to array output (mne.Epochs cannot hold them).

With it, leave-one-dataset-out runs with what exists: CrossSubjectEvaluation(datasets=[compound], cv_class=LeaveOneGroupOut, groups=...).

Tests: nested output and the regular case (test_paradigms.py), Epochs error, and a leave-one-system-out CrossSubjectEvaluation on two fake systems with different channels and rates (test_evaluations.py). test_evaluations.py and test_paradigms.py pass locally.

Next: a PR making the grouping explicit (a dataset metadata column for CompoundDataset, so groups="dataset"), then #1305 becomes a tutorial.

np.concatenate at the end of BaseParadigm.get_data was the only thing that
stopped datasets with different montages or sampling rates (pooled in a
CompoundDataset) from going through a paradigm and an evaluation. Return an
object array of per-trial arrays in that case; _get_nchan accepts it; the
Epochs path raises a clear error instead of MNE's nchan mismatch.
# Conflicts:
#	docs/source/whats_new.rst
@bruAristimunha
bruAristimunha merged commit a7175ed into NeuroTechX:develop Oct 24, 2026
13 of 15 checks passed
bruAristimunha added a commit to qbarthelemy/moabb that referenced this pull request Oct 25, 2026
Review of NeuroTechX#1305 (Bruno): no new evaluation. The example now pools the
devices in a CompoundDataset and holds out one device at a time with
CrossSubjectEvaluation(cv_class=LeaveOneGroupOut, groups='device'), on the
nested trials of NeuroTechX#1327 and the device column of NeuroTechX#1328.

- remove CrossSystemEvaluation, its tests and extra_fit_params;
- _evaluate_fold routes any metadata column of the training trials to the
  steps requesting it (set_fit_request(device=True)), replacing the
  cross-system-only 'systems' routing;
- FakeDataset takes a device;
- the example's ChannelUnion and MDMM read the device of each training
  trial and infer the held-out device, so every device can be the target;
- keep the duplicated-results fix of process() and its test.
bruAristimunha added a commit that referenced this pull request Oct 26, 2026
…(route metadata columns to pipelines) (#1305)

* Add CrossSystemEvaluation

* CrossSystemEvaluation: load the systems once, reject unknown targets and epoch pipelines

Review follow-ups: the systems were reloaded in full for every target (k^2
loads), a target_datasets entry outside datasets gave an empty result, and
pipelines needing mne.Epochs silently received arrays.

* Turn CrossSystemEvaluation into a tutorial on the existing API

Review of #1305 (Bruno): no new evaluation. The example now pools the
devices in a CompoundDataset and holds out one device at a time with
CrossSubjectEvaluation(cv_class=LeaveOneGroupOut, groups='device'), on the
nested trials of #1327 and the device column of #1328.

- remove CrossSystemEvaluation, its tests and extra_fit_params;
- _evaluate_fold routes any metadata column of the training trials to the
  steps requesting it (set_fit_request(device=True)), replacing the
  cross-system-only 'systems' routing;
- FakeDataset takes a device;
- the example's ChannelUnion and MDMM read the device of each training
  trial and infer the held-out device, so every device can be the target;
- keep the duplicated-results fix of process() and its test.

---------

Co-authored-by: Bru <[email protected]>
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