Skip to content

Support group=FALSE for multihop connectivity - #60

Open
jefferis wants to merge 2 commits into
masterfrom
feature/multihop-group-false
Open

Support group=FALSE for multihop connectivity#60
jefferis wants to merge 2 commits into
masterfrom
feature/multihop-group-false

Conversation

@jefferis

Copy link
Copy Markdown
Contributor

Follow-up to #59. nhops>0 previously errored out unless a grouping column was supplied:

cf_cosine_plot(cf_ids(flywire="/type:LAL00.+"), nhops = 1, group = FALSE)
#> Error: Multihop connectivity (nhops>0) requires a grouping column ...

That restriction was mine and it was artificial — the method needs some partition of each layer, not specifically cell types.

What changes

group=FALSE now means each neuron is its own group:

  • the features become individual n-th order partner neurons rather than types;
  • min_frac becomes a per-neuron rather than a per-type cut;
  • the grouping degenerates to the identity, so the terminal layer is left ungrouped and the intermediate identity multiplication is skipped rather than performed wastefully.

The surrounding plumbing already cooperated: multi_cosine_matrix does groupcol <- if(isFALSE(group)) "post_key" else group, and multi_connection_table already skips match_types when group isn't a character. So this is a small change — drop the stop(), use an identity grouping in multihop_effective_matrix, and stop .mh_matrix2df writing a grouping column (the target key already lives in post_key/pre_key).

Why it matters

group=FALSE is the only option for datasets without metadata (e.g. FANC), and is useful for columnar neurons whose partners differ neuron-by-neuron — exactly the cases the nhops=0 docs already call out.

Caveat (documented, not enforced)

As at nhops=0, group=FALSE only really makes sense within a single dataset: individual neuron keys never match across datasets, so every cross-dataset cosine is 0 by construction. Measured on flywire + malecns:

cross-dataset block 24x21   mean: 0   max: 0
within-flywire  mean(off-diag): 0.054

This is inherent to group=FALSE rather than to multihop, so the docs say so instead of the code forbidding it. The docs also note that per-neuron effective weights are smaller than their per-type aggregates, so a smaller min_frac than the 0.005 default may be wanted.

Testing

Three new offline tests (23 assertions total in test-multihop.R): ungrouped targets stay at neuron resolution with the same hand-computed values as the grouped case, per-neuron frontier pruning, and .mh_matrix2df omitting the grouping column.

Live: single-dataset nhops=1, group=FALSE on hemibrain "/type:LAL00.+" gives a valid 15x15 matrix; R CMD check dependency checks clean.

Co-Authored-By: Claude Opus 4.8 noreply@anthropic.com

🤖 Generated with Claude Code

jefferis added 2 commits July 20, 2026 00:01
nhops>0 previously errored without a grouping column, but types are not
actually required by the method: group=FALSE simply treats each neuron as
its own group, so the features are individual n-th order partner neurons
and min_frac becomes a per-neuron rather than a per-type cut. The grouping
then degenerates to the identity, so the terminal layer is left ungrouped
and the intermediate identity multiplication is skipped.

This matters for datasets without metadata (e.g. FANC, where group=FALSE
is the only option) and for columnar neurons. As at nhops=0 it only makes
sense within a single dataset, since individual neurons do not correspond
across datasets; the docs say so rather than the code forbidding it.
Previously a partner with no group label (e.g. an untyped neuron with
group='type') was silently dropped from an intermediate layer, because
coconat::grouping_matrix discards NA groups and 'NA %in% keep_types' is
FALSE. That killed the whole path, so a well typed neuron two hops away
was unreachable if the interneuron between happened to be untyped -
defeating much of the point of looking beyond the first hop.

Untyped neurons in an intermediate layer now form their own singleton
groups, so they are thresholded per neuron rather than discarded and
connectivity propagates through a poorly typed layer. Untyped neurons in
the final layer are still dropped, since they cannot serve as a shared
feature; that matches the nhops=0 behaviour of
partner_summary2adjacency_matrix.
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