Skip to content

Fix degenerate MSE loss on regression datasets (#42)#45

Merged
PierreGtch merged 1 commit into
mainfrom
fix/regression-mse-broadcast-issue-42
Jul 9, 2026
Merged

Fix degenerate MSE loss on regression datasets (#42)#45
PierreGtch merged 1 commit into
mainfrom
fix/regression-mse-broadcast-issue-42

Conversation

@PierreGtch

Copy link
Copy Markdown
Contributor

Fixes #42.

EEGRegressor subclass whose get_loss gives scalar regression targets a trailing dim (B,)→(B,1); classification and ridge paths untouched. Guarded by tests/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_r2 stays bad on REVE for a separate reason — the 69,632-dim head diverges under SGD regardless of this fix — worth a follow-up.

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
PierreGtch marked this pull request as ready for review July 9, 2026 15:51
@PierreGtch
PierreGtch merged commit 3e4d034 into main Jul 9, 2026
11 checks passed
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.

Regression datasets silently train on a degenerate MSE loss (target [B] vs output [B,1] broadcast)

1 participant