Steal connectivity gradient computation Fix #54#70
Conversation
|
Cant reproduce the mypy error locally... |
Coverage Report
|
reindervdw-cmi
left a comment
There was a problem hiding this comment.
No idea about the validity of changing the eig function. You could check results of this against BrainSpace's gradients to see if they produce similar values.
| then apply the kernel, then zero out negatives. | ||
|
|
||
| Args: | ||
| matrix: (n_rois, n_rois) correlation / connectivity matrix. |
There was a problem hiding this comment.
a square n-to-n matrix is by far the most common use-case, but there's no reason why it can't be n-to-m (as a matter of fact, I've done just that before)
| pairwise correlations, then applies diffusion map embedding (Coifman & | ||
| Lafon 2006) to recover low-dimensional gradients. | ||
|
|
||
| Vendored from BrainSpace (Vos de Wael et al. 2020) to avoid pulling in |
There was a problem hiding this comment.
Include a copy of the license; otherwise you're in breach of it :D
| raise ValueError(f"Need at least 2 ROIs, got {n}") | ||
|
|
||
| mat = np.array(matrix, dtype=np.float64) | ||
| mat_no_nan = np.nan_to_num(mat, nan=0.0) |
There was a problem hiding this comment.
Check for rows that are entirely zero and error
| d_alpha = d ** (-alpha) | ||
| affinity = affinity * d_alpha[:, None] * d_alpha[None, :] | ||
|
|
||
| # Form symmetric operator Ms = D^{-1/2} W_alpha D^{-1/2} |
There was a problem hiding this comment.
no idea if this is actually equivalent 🤷 been far too long since I was deep into the diffusion mapping maths
compute_gradientsand supporting functions (compute_affinity,diffusion_map_embedding) torbc.core.metrics.gradientsscipy.linalg.eighon the symmetrized operator instead ofeigshon the asymmetric transition matrix, for dense numerical stability (@reindervdw-cmi bad idea?)