DistanceDependent

DistanceDependent#

class braintools.conn.DistanceDependent(distance_profile, weight=None, delay=None, **kwargs)#

Distance-dependent connectivity for spatially arranged point neurons.

This class creates synaptic connections between neurons based on their spatial distances, where the connection probability is determined by a distance-dependent profile. The connectivity pattern enables modeling of local and distance-modulated neural circuits commonly observed in biological neural networks.

The connection generation process:

  1. Computes pairwise distances between pre- and post-synaptic neuron positions

  2. Calculates connection probabilities using the provided distance profile

  3. Stochastically generates connections based on these probabilities

  4. Assigns weights and delays to established connections using initializers

Parameters:
  • distance_profile (Array | ndarray | bool | number | bool | int | float | complex | Quantity | DistanceProfile) –

    A distance profile object that defines how connection probability varies with distance. Common profiles include:

    • GaussianProfile: Probability decreases as a Gaussian function of distance

    • ExponentialProfile: Probability decays exponentially with distance

    • Custom profiles implementing the DistanceProfile interface

    Alternatively, can be an array-like object specifying probabilities directly.

  • weight (Initialization | float | int | ndarray | Array | Quantity | None) –

    Initializer for synaptic weights. Can be:

    • A constant value (e.g., 1.0 * u.nS)

    • An initializer object (e.g., Normal(mean=1.0*u.nS, std=0.1*u.nS))

    • None to create unweighted connections

    Some initializers support distance-dependent weight generation.

  • delay (Initialization | float | int | ndarray | Array | Quantity | None) –

    Initializer for synaptic delays. Can be:

    • A constant value (e.g., 1.0 * u.ms)

    • An initializer object (e.g., Uniform(0.5*u.ms, 2.0*u.ms))

    • None to create connections without explicit delays

  • **kwargs – Additional keyword arguments passed to the parent PointConnectivity class, such as seed for reproducible random number generation.

Returns:

A connection result object containing:

  • pre_indices: Pre-synaptic neuron indices

  • post_indices: Post-synaptic neuron indices

  • weights: Connection weights (if weight initializer provided)

  • delays: Connection delays (if delay initializer provided)

  • metadata: Additional information about the connectivity pattern

Return type:

ConnectionResult

Notes

  • Requires neuron positions to be provided via pre_positions and post_positions arguments when calling the connector, or a pre-computed distances array

  • Position arrays should have shape (n_neurons, n_dimensions) with units

  • The actual number of connections is stochastic and depends on the distance profile and random sampling

  • Empty connection results are returned if no connections are established

See also

Gaussian

Specialized class for Gaussian distance-dependent connectivity

Exponential

Specialized class for exponential distance-dependent connectivity

braintools.init.GaussianProfile

Gaussian distance profile

braintools.init.ExponentialProfile

Exponential distance profile

Examples

Basic usage with Gaussian distance profile:

>>> import brainunit as u
>>> import numpy as np
>>> from braintools.conn import DistanceDependent
>>> from braintools.init import GaussianProfile, Normal, Constant
>>>
>>> # Create neuron positions in 2D space
>>> positions = np.random.uniform(0, 1000, (500, 2)) * u.um
>>>
>>> # Define Gaussian distance-dependent connectivity
>>> conn = DistanceDependent(
...     distance_profile=GaussianProfile(
...         sigma=100 * u.um,
...         max_distance=300 * u.um
...     ),
...     weight=Normal(mean=1.5*u.nS, std=0.3*u.nS),
...     delay=Constant(1.0 * u.ms),
...     seed=42
... )
>>>
>>> # Generate connections
>>> result = conn(
...     pre_size=500,
...     post_size=500,
...     pre_positions=positions,
...     post_positions=positions
... )
>>> print(f"Generated {len(result.pre_indices)} connections")

Using exponential distance profile:

>>> from braintools.init import ExponentialProfile
>>>
>>> conn = DistanceDependent(
...     distance_profile=ExponentialProfile(
...         scale=150 * u.um,
...         max_distance=500 * u.um
...     ),
...     weight=Constant(2.0 * u.nS)
... )

Pre-computed distances:

>>> # Use pre-computed distance matrix instead of positions
>>> from scipy.spatial.distance import cdist
>>> distances = cdist(positions.mantissa, positions.mantissa) * u.um
>>> result = conn(
...     pre_size=500,
...     post_size=500,
...     distances=distances
... )
generate(**kwargs)[source]#

Generate distance-dependent connections.

Return type:

ConnectionResult