CompartmentSpecific#
- class braintools.conn.CompartmentSpecific(compartment_mapping, connection_prob=0.1, weight=None, delay=None, morphology_info=None, allow_self_connections=False, **kwargs)#
General compartment-specific connectivity pattern.
This is the base class for targeting specific compartments in multi-compartment neurons. It provides flexible mapping from source compartments to target compartments with customizable connection rules.
- Parameters:
compartment_mapping (
Mapping[Any,int|str|Sequence[int|str]]) – Mapping from source compartment types to target compartment types. Keys and values can be compartment indices (int) or names (str).connection_prob (
float|Dict) – Connection probability. Can be global or per-compartment-pair.weight (
Initialization|float|int|ndarray|Array|Quantity|None) – Weight initializer (e.g.braintools.init.Normal).delay (
Initialization|float|int|ndarray|Array|Quantity|None) – Delay initializer (e.g.braintools.init.Uniform).morphology_info (
Dict|None) – Information about neuron morphology structure.allow_self_connections (
bool) – Whether a neuron may connect to itself (autapse). WhenFalseand the pre/post populations have the same size, connections withpre_idx == post_idxare dropped regardless of compartment. DefaultFalse.
Notes
Generation runs on the host with NumPy and cannot be traced by
jax.jit,jax.vmaporjax.grad.Changed in version 0.4.0: Connected pairs are sampled by drawing a binomial edge count and then that many distinct pairs, without a dense
pre_size x post_sizematrix, so time and memory grow with the number of edges. The edges for a givenseeddiffer from 0.3 (same distribution). This also applies to the subclasses that delegate to it (SomaToDendrite,AxonToSoma,BranchSpecific,AllToAllCompartmentsand the other targeting shortcuts).Examples
Axon-to-soma connections:
>>> import brainunit as u >>> import numpy as np >>> from braintools.conn import ( ... CompartmentSpecific, AXON, SOMA, BASAL_DENDRITE, APICAL_DENDRITE ... ) >>> from braintools.init import Normal >>> axon_soma = CompartmentSpecific( ... compartment_mapping={AXON: SOMA}, ... connection_prob=0.1, ... weight=Normal(mean=2.0 * u.nS, std=0.5 * u.nS), ... seed=0, ... ) >>> result = axon_soma(pre_size=100, post_size=100) >>> result.n_connections 993 >>> bool(np.all(result.post_compartments == SOMA)) True
Complex multi-compartment targeting:
>>> # Dendrites to soma, axon to dendrites >>> multi_target = CompartmentSpecific( ... compartment_mapping={ ... BASAL_DENDRITE: SOMA, ... APICAL_DENDRITE: SOMA, ... AXON: [BASAL_DENDRITE, APICAL_DENDRITE] ... }, ... connection_prob={ ... (BASAL_DENDRITE, SOMA): 0.3, ... (APICAL_DENDRITE, SOMA): 0.2, ... (AXON, BASAL_DENDRITE): 0.05, ... (AXON, APICAL_DENDRITE): 0.08 ... } ... )
Named compartment mapping:
>>> named_mapping = CompartmentSpecific( ... compartment_mapping={ ... 'axon': ['basal_dendrite', 'apical_dendrite'], ... 'basal_dendrite': 'soma' ... }, ... connection_prob=0.1 ... )