Allow spectrum='nonzero' with no zero eigenvalue (#112)#157
Merged
Conversation
The previous unconditional `if n_zero == 0: raise ValueError` blocked legitimate use cases like hippocampal-subfield analyses where the weight matrix has no kernel (no medial wall). Simply removing the guard, as proposed in #112, would silently corrupt the spectrum='all' branch (it would drop the largest eigenvalue instead of a zero one). Make the guard branch-aware: spectrum='all' still requires a zero eigenvalue and raises a clearer error pointing at spectrum='nonzero'; spectrum='nonzero' now accepts kernel-free matrices and returns all eigenvalues. Adds two regression tests covering both branches. Co-authored-by: Jordan DeKraker <jordandekraker@users.noreply.github.com>
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.
Supersedes #112.
@jordandekraker's bug report is real: a weight matrix with no kernel (e.g. hippocampal-subfield surfaces with no medial wall) shouldn't raise. The original PR removed the guard outright, but that silently corrupts the
spectrum='all'branch —mask_zero.argmax()returns0when nothing is True, so the code drops the largest eigenvalue instead of a zero one.This PR makes the guard branch-aware:
spectrum='all'still requiresn_zero >= 1and now raises a clearer message pointing atspectrum='nonzero'.spectrum='nonzero'accepts kernel-free matrices and returns all eigenvalues.Plus two regression tests covering both branches.
@jordandekraker is credited as Co-author on the squashed commit.
Test plan
pytest brainspace/tests/test_null_models.py→ 6 passed.