Fix degenerate MSE loss on regression datasets (#42)#45
Merged
Conversation
Windowed regression targets are scalar-per-sample, so the collated batch target has shape (B,) while the regression model output is (B, 1). The default MSELoss silently broadcast (B, 1) against (B,) to (B, B), averaging over B^2 pairwise differences instead of the B element-wise ones. That broadcast loss equals the true element-wise MSE plus 2*cov(pred, target), i.e. it actively penalises prediction/target correlation and wrecks regression training, while the reported r2 metric (which ravels predictions) stayed correct — so the bug was silent. Give the SGD regression path an EEGRegressor subclass whose get_loss aligns the target's trailing dimension to the (B, 1) output. Classification (EEGClassifier) and ridge probing (already reshapes targets) are unaffected. Add tests/test_regression_loss.py guarding against the broadcast.
PierreGtch
marked this pull request as ready for review
July 9, 2026 15:51
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.
Fixes #42.
EEGRegressorsubclass whoseget_lossgives scalar regression targets a trailing dim(B,)→(B,1); classification and ridge paths untouched. Guarded bytests/test_regression_loss.py.Verified on REVE×seed_vig (before/after): ridge probe identical (−0.338, path unaffected), broadcast warnings 789→0. Caveat: the SGD linear-probe
test_r2stays bad on REVE for a separate reason — the 69,632-dim head diverges under SGD regardless of this fix — worth a follow-up.