Multihop (effective) connectivity clustering in cf_cosine_plot - #59
Merged
Conversation
jefferis
force-pushed
the
feature/multihop-connectivity
branch
from
July 17, 2026 07:22
be37446 to
121b46f
Compare
New nhops/min_frac/remove_query arguments cluster neurons by their effective connectivity onto n-th order partners reached through intermediate interneuron layers, following Schlegel et al. 2021. Per dataset the walk fetches partners and input-normalises each hop (coconat::colScaleM), then advances a running query x frontier matrix one hop at a time via coconat::effective_connectivity(normalise=FALSE), which aligns partners by name so dead-end paths become zero. Between hops each intermediate layer is pruned to types receiving >= min_frac effective input (grouping-as-selection via coconat::grouping_matrix, keeping neurons at full resolution) before the next fetch, which bounds the walk. The terminal layer is grouped to types and fed through the existing cosine/heatmap machinery as a synthetic partner table, with match_types applied on that type layer. nhops=0 reproduces prior behaviour. Offline tests with a mocked cf_partners in tests/testthat/test-multihop.R.
jefferis
force-pushed
the
feature/multihop-connectivity
branch
from
July 17, 2026 12:50
121b46f to
a294f6f
Compare
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 multihop ("effective") connectivity clustering: instead of clustering neurons by their direct partners, cluster them by their effective connectivity onto n-th order partners reached through intermediate interneuron layers, following Schlegel et al. 2021 (10.7554/eLife.62576).
Important
Depends on natverse/coconat#12 (
effective_connectivity()/grouping_matrix()).be37446temporarily pins the coconat Remote to that feature branch so CI can install it — revert that commit once coconat#12 merges.API
nhops= number of intermediate interneuron layers.nhops=0(default) is the existing direct-partner behaviour;nhops=1is the paper's "one-hop" (2nd-order partners);nhops=2is 3rd-order. The docs carry the order↔hops mapping, since the conventions disagree.min_frac= per-type fractional threshold (scalar or one value per hop), applied at every hop including the terminal one.remove_query= exclude query neurons from partners at every hop.thresholdis unchanged: a single per-neuron-pair absolute synapse cut applied at each hop's fetch.How it works
Per dataset (effective connectivity is computed within a dataset, since interneurons are dataset-local):
threshold) and input-normalise the hop withcoconat::colScaleM(inputs to every postsynaptic cell sum to 1).coconat::effective_connectivity(list(running, step), normalise = FALSE), which aligns partners by name so dead-end paths become zero.min_fraceffective input, then fetch the next hop only from the survivors. This prune-before-fetch is what bounds the walk — hop 2 from an unpruned interneuron set is the thing to avoid.match_typesruns on that terminal type layer.Two design points worth noting for review:
(A1n·A2n)·G == A1n·(A2n·G)).multi_cosine_matrixnow passesstandardise_input = FALSE. This is safe becausecf_partnershas already standardised the data by that point, and it's required for the synthetic effective table (whose partner side holds cell types, not integer64 ids).nhops=0reproduces prior behaviour exactly.Testing
tests/testthat/test-multihop.R— 15 offline assertions with a mockedcf_partnersover a synthetic network: hand-computed one-hop values, frontier pruning,remove_query, the melt shape, and annhops=2dead-end case (an interneuron with no onward partners) covering name-based alignment.cosinetests confirm thenhops=0path still works through the modifiedmulti_cosine_matrix.cf_ids(hemibrain="/type:LAL00.+"):nhops=0andnhops=1both give valid 15×15 matrices over the same neuron set (mean off-diagonal cosine 0.10 → 0.21, as expected once connectivity flows through shared interneurons).Co-Authored-By: Claude Opus 4.8 noreply@anthropic.com
🤖 Generated with Claude Code