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 isbase_weights * distance_profile(distances)evaluated element-wise.- Parameters:
base_dist (
Initialization) – Base weight distribution.distance_profile (
DistanceProfile) – Distance modulation function. Itsweight_scaling()output multiplies the base weights.
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
0produces a weight of exactly0(a present-but-silent synapse), not an absent connection. Distance-dependent connectivity (deciding which pairs are connected at all) belongs to thebraintools.connmodule, where the profile’sprobabilityis consumed by a sampler.The connection distances can be supplied directly via the
distanceskeyword, or computed from neuron coordinates viapre_positionsandpost_positions. Coordinates may be given either as a 2-D(N, d)array (Nneurons ind-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)