Add effective_connectivity() and grouping_matrix() - #12
Merged
Conversation
…ctivity Compute effective connectivity through multi-step pathways by input-normalising each step (colScaleM) and multiplying the successive adjacency matrices, following Schlegel et al. 2021 (eLife). grouping_matrix() builds the sparse 0/1 aggregation used to collapse the final output dimension to cell types. Offline unit tests included.
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.
Adds two sparse-matrix primitives to support multihop ("effective") connectivity, as used by the companion coconatfly PR for multihop cosine clustering.
What
effective_connectivity(matrices, group = NULL, normalise = TRUE)— estimates connectivity through multi-step pathways by input-normalising each step (colScaleM, so inputs to every postsynaptic cell sum to 1) and multiplying the successive adjacency matrices, per Schlegel et al. 2021 (10.7554/eLife.62576). Consecutive matrices are chained by name, so an output absent from the next matrix's rows contributes a zero (dead-end) path rather than erroring.grouping_matrix(ids, group)— sparse 0/1 aggregation matrix; right-multiplying collapses columns within a group (e.g. partner neurons to cell types).NAgroups drop out.Notes
groupcollapses the final output dimension. Because grouping is applied after normalisation and multiplication, and matrix multiplication is associative, grouping the final product is identical to grouping the last matrix's columns first — the per-neuron normalisation is always preserved.effective_connectivity(list(running, step), normalise = FALSE)), which avoids materialising every hop's matrix at once and allows pruning the frontier between hops. This is how coconatfly's multihop clustering drives it.Testing
tests/testthat/test-effective-connectivity.R— 15 offline assertions against a hand-computed pathway, covering normalisation, grouping, the associativity property, name-based alignment / dead ends, and the single-matrix case.Co-Authored-By: Claude Opus 4.8 noreply@anthropic.com
🤖 Generated with Claude Code