Support group=FALSE for multihop connectivity - #60
Open
jefferis wants to merge 2 commits into
Open
Conversation
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.
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.
Follow-up to #59.
nhops>0previously errored out unless a grouping column was supplied:That restriction was mine and it was artificial — the method needs some partition of each layer, not specifically cell types.
What changes
group=FALSEnow means each neuron is its own group:min_fracbecomes a per-neuron rather than a per-type cut;The surrounding plumbing already cooperated:
multi_cosine_matrixdoesgroupcol <- if(isFALSE(group)) "post_key" else group, andmulti_connection_tablealready skipsmatch_typeswhengroupisn't a character. So this is a small change — drop thestop(), use an identity grouping inmultihop_effective_matrix, and stop.mh_matrix2dfwriting a grouping column (the target key already lives inpost_key/pre_key).Why it matters
group=FALSEis 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 thenhops=0docs already call out.Caveat (documented, not enforced)
As at
nhops=0,group=FALSEonly really makes sense within a single dataset: individual neuron keys never match across datasets, so every cross-dataset cosine is 0 by construction. Measured onflywire+malecns:This is inherent to
group=FALSErather 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 smallermin_fracthan 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_matrix2dfomitting the grouping column.Live: single-dataset
nhops=1, group=FALSEonhemibrain "/type:LAL00.+"gives a valid 15x15 matrix;R CMD checkdependency checks clean.Co-Authored-By: Claude Opus 4.8 noreply@anthropic.com
🤖 Generated with Claude Code