DistanceProfile#

class braintools.init.DistanceProfile#

Base class for distance-dependent connectivity profiles.

Distance profiles define how connection probability and weight strength vary with spatial distance between neurons. DistanceProfile supports composition through arithmetic operations and functional transformations, enabling the creation of complex distance-dependent patterns from simple ones.

Supported Operations#

  • Arithmetic: +, -, *, / (element-wise operations with other profiles, scalars, or quantities)

  • Composition: | (pipe operator for chaining transformations)

  • Transformations: .clip(), .apply()

Examples

>>> import numpy as np
>>> import brainunit as u
>>> from braintools.init import DistanceProfile
>>>
>>> class LinearDecayProfile(DistanceProfile):
...     def __init__(self, max_dist):
...         self.max_dist = max_dist
...
...     def probability(self, distances):
...         return np.maximum(0, 1 - distances / self.max_dist)
...
...     def weight_scaling(self, distances):
...         return self.probability(distances)

Composition Examples#

>>> from braintools.init import GaussianProfile, ExponentialProfile
>>>
>>> # Scale a Gaussian profile
>>> profile = GaussianProfile(50.0 * u.um) * 0.5
>>>
>>> # Combine two profiles
>>> combined = GaussianProfile(50.0 * u.um) + ExponentialProfile(100.0 * u.um) * 0.3
>>>
>>> # Clip profile values
>>> clipped_profile = GaussianProfile(50.0 * u.um).clip(0.1, 0.9)
>>>
>>> # Apply custom function
>>> transformed = GaussianProfile(50.0 * u.um).apply(lambda x: x ** 2)
>>>
>>> # Chain transformations with pipe operator
>>> chained = GaussianProfile(50.0 * u.um) | (lambda x: x * 2) | (lambda x: np.minimum(x, 1.0))
apply(func)[source]#

Apply an arbitrary function to the output.

Return type:

ApplyProfile

clip(min_val=None, max_val=None)[source]#

Clip values to a specified range.

Return type:

ClipProfile

abstractmethod probability(distances)[source]#

Calculate connection probability based on distance.

Parameters:

distances (Array | ndarray | bool | number | bool | int | float | complex | Quantity) – Array of distances between neuron pairs.

Returns:

probability – Connection probabilities (values between 0 and 1).

Return type:

ndarray

weight_scaling(distances)[source]#

Calculate weight scaling factor based on distance.

Parameters:

distances (Array | ndarray | bool | number | bool | int | float | complex | Quantity) – Array of distances between neuron pairs.

Returns:

scaling – Weight scaling factors (typically between 0 and 1).

Return type:

ndarray