Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions brainspace/null_models/moran.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,6 @@ def compute_mem(w, n_ring=1, spectrum='nonzero', tol=1e-10):
mask_zero = ev_abs < tol
n_zero = np.count_nonzero(mask_zero)

Copilot AI Feb 9, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the ValueError removed, spectrum='nonzero' now returns all eigenvectors when n_zero == 0 (i.e., nothing is filtered by mask_zero). That contradicts the function’s contract of removing the (at least one) zero/constant mode from the doubly-centered matrix and can change downstream behavior (e.g., component count becomes n_vertices instead of the expected <= n_vertices-1). Consider treating the smallest-|eigenvalue| entry as zero when n_zero == 0 (e.g., set mask_zero[ev_abs.argmin()] = True) so the constant mode is still removed even when numerical precision/tol prevents exact zeros.

Suggested change
# If no eigenvalue is below tolerance but spectrum=='nonzero', still
# remove at least one mode (the one with smallest |eigenvalue|),
# corresponding to the constant component of the doubly centered matrix.
if spectrum == 'nonzero' and n_zero == 0:
idx_min = ev_abs.argmin()
mask_zero[idx_min] = True
n_zero = 1

Copilot uses AI. Check for mistakes.
if n_zero == 0:
raise ValueError('Weight matrix has no zero eigenvalue.')

# Multiple zero eigenvalues
if spectrum == 'all':
if n_zero > 1:
Expand Down
Loading