Repository navigation
Fix cropped EEGRegressor loss broadcasting for a 1-D numpy y - #1198
Merged
bruAristimunha merged 1 commit intoOct 4, 2026
Merged
bruAristimunha merged 1 commit into
bruAristimunha merged 1 commit into
Conversation
In cropped mode, EEGRegressor.fit reshapes a 1-D numpy y to (n, 1), but CroppedLoss squeezed the time-averaged prediction to (batch,), so the criterion compared every prediction with every target of the batch. braindecode#1197 fixed the trialwise counterpart of this in EEGRegressor.get_loss. CroppedLoss now keeps the output dimension when the target is a 2-D tensor. 1-D targets, such as class labels and dataset regression targets, and Mixup's (y_a, y_b, lam) list are handled as before.
4 tasks done
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1198 +/- ##
=======================================
Coverage 87.78% 87.79%
=======================================
Files 149 149
Lines 17461 17462 +1
=======================================
+ Hits 15329 15330 +1
Misses 2132 2132 🚀 New features to boost your workflow:
|
bruAristimunha
approved these changes
Oct 4, 2026
Collaborator
|
Thank you so much @raghav-rathi, great addition |
bruAristimunha
added a commit
to lindicaphxag-tech/braindecode
that referenced
this pull request
Oct 5, 2026
Resolved docs/whats_new.rst conflict by keeping both the NeuroRVQ entry and master's new llms.txt/docs entry. All other paths auto-merged, including training/losses.py and test/unit_tests/training/test_losses.py, which now exactly match origin/master (the braindecode#1198 CroppedLoss fix and its regression test are restored).
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.
Summary
Follow-up to #1197, which fixed #1180 for trialwise training. Cropped training still compares every prediction with every target when
yis a 1-D numpy array.EEGRegressor.fitreshapes thatyto(n, 1), andCroppedLossthen squeezes the time-averaged prediction to(batch,), so the MSE runs over a(batch, batch)broadcast. Cropped training on a braindecode dataset is fine, since those targets are 1-D.Same data and seed as the training script in #1180, cropped ShallowFBCSPNet, 30 epochs:
fit(X, y), masterfit(X, y), this PRfit(dataset), master and this PRChanges
CroppedLosskeeps the output dimension when the target is a 2-D tensor, so(batch, 1)targets meet(batch, 1)predictions. 1-D targets (class labels, dataset regression targets) and Mixup's(y_a, y_b, lam)list are squeezed as before.Testing
test_eegregressor_cropped_loss_is_per_trial_mse[numpy]fails on master 55afc12 withExpected 0.18911918997764587 but got 0.2287747859954834and passes here. The[dataset]case passes on both.test_cropped_loss_accepts_mixup_targetpasses on both. Mixup givesCroppedLossa list, so a baretargets.ndimcheck would break cropped training with Mixup.pytest test/unit_tests/test_eegneuralnet.py test/unit_tests/training/ test/unit_tests/augmentation/ -n 8: 222 passed, 8 skipped.Full suite with the tests.yml command,
pytest -vv --durations=0 -n 16 --dist worksteal test/, CPU only (Linux, Python 3.12, torch 2.14): 4003 passed, 255 skipped, 0 failed.Only tested on Linux, so macOS, Windows and Python 3.13 weren't run, and I didn't build the docs.
New or changed behavior is covered by relevant regression tests (or N/A with reason)
Style checks recorded, e.g.
pre-commit run --files <changed files>(clean on the changed files)docs/whats_new.rstupdated (required by the changelog CI check)Notes for reviewers
CroppedLossis shared withEEGClassifier. Classification targets are 1-D, so they take the same path as before.