Skip to content

Add effective_connectivity() and grouping_matrix() - #12

Merged
jefferis merged 1 commit into
masterfrom
feature/effective-connectivity
Jul 17, 2026
Merged

Add effective_connectivity() and grouping_matrix()#12
jefferis merged 1 commit into
masterfrom
feature/effective-connectivity

Conversation

@jefferis

Copy link
Copy Markdown
Contributor

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). NA groups drop out.

Notes

  • group collapses 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.
  • The docs call out an iterative usage pattern (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

…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.
@jefferis
jefferis merged commit 5deacbc into master Jul 17, 2026
5 checks passed
@jefferis
jefferis deleted the feature/effective-connectivity branch July 17, 2026 17:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant