Repository navigation
Spatial cv - #14
Merged
Merged
Spatial cv#14
Conversation
Contributor
Author
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.
Pull Request: Add Temporal and Spatial Cross-Validation Solvers
Summary
This PR introduces two cross-validation strategies to select the optimal regularization parameter$\alpha$ (i.e., noise level $\lambda$ ) for Champagne and LowSNR-BSI models:
Both solvers inherit from a shared$\alpha$ values.
BaseCVSolverclass, follow scikit-learn conventions, and support parallel grid search over a configurable range ofBackground
Temporal Cross-Validation
In temporal CV, the data$\mathbf{Y} \in \mathbb{R}^{M \times T}$ are split into $k$ contiguous temporal folds. For each split, the model is trained on $k-1$ folds and evaluated on the remaining fold using the out-of-sample Type-II log-likelihood:
Here:
This quantity corresponds to the log-det Bregman divergence and is theoretically justified as a second-order comparison between model and empirical covariances.
Spatial Cross-Validation
In spatial CV, the sensor space is split into training and test sets. The model is trained on a subset of sensors and the predicted source activity$\mathbf{X}^{\text{train}}$ is mapped back to the test sensors using the corresponding lead field matrix. The Type-I log-likelihood is then computed as:
This metric corresponds to the MSE (first-order discrepancy) between observed and predicted data on the held-out sensors.
Implementation Highlights
BaseCVSolverdefines shared initialization,fit, andpredictlogic.SpatialCVSolverusesGridSearchCVwith MSE scoring to selectTemporalCVSolvermanually implements k-fold splitting and uses log-det Bregman divergence to select_logdet()— numerically stable log-determinant computationlogdet_bregman_div_distance_nll()— implements the divergence metric✅ Example Usage