DistanceModulated

DistanceModulated#

class braintools.init.DistanceModulated(base_dist, distance_profile)#

Initialization modulated by distance.

Generates weights from a base distribution and then multiplies them by a distance-dependent gain taken from a DistanceProfile (e.g. exponential decay, Gaussian). The result is base_weights * distance_profile(distances) evaluated element-wise.

Parameters:

Notes

This initializer is a deterministic weight modulator, not a stochastic connectivity mask. The distance profile scales the magnitude of every weight; it never performs Bernoulli sampling to drop connections. A profile value of 0 produces a weight of exactly 0 (a present-but-silent synapse), not an absent connection. Distance-dependent connectivity (deciding which pairs are connected at all) belongs to the braintools.conn module, where the profile’s probability is consumed by a sampler.

The connection distances can be supplied directly via the distances keyword, or computed from neuron coordinates via pre_positions and post_positions. Coordinates may be given either as a 2-D (N, d) array (N neurons in d-dimensional space) or, for one-dimensional layouts, as a flat (N,) vector that is promoted to (N, 1) automatically.

Examples

>>> import numpy as np
>>> import brainunit as u
>>> from braintools.init import DistanceModulated, GaussianProfile, Normal
>>>
>>> rng = np.random.default_rng(0)
>>> profile = GaussianProfile(sigma=100.0 * u.um)
>>> init = DistanceModulated(
...     base_dist=Normal(1.0 * u.nS, 0.2 * u.nS),
...     distance_profile=profile,
... )
>>>
>>> # Modulate using pre-computed pairwise distances.
>>> distances = np.array([0.0, 50.0, 100.0, 150.0]) * u.um
>>> weights = init(4, distances=distances, rng=rng)
>>>
>>> # ... or compute distances from neuron coordinates (flat 1-D layout).
>>> pre = np.array([0.0, 100.0, 200.0]) * u.um
>>> post = np.array([0.0, 100.0, 200.0]) * u.um
>>> matrix = init((3, 3), pre_positions=pre, post_positions=post, rng=rng)