FixedOutDegree#
- class braintools.conn.FixedOutDegree(k, *, allow_self_connections=True, with_replacement=False, weight=None, delay=None, seed=None, **kwargs)#
Connect every presynaptic neuron to exactly
kpostsynaptic neurons.The
ktargets of each presynaptic neuron are drawn uniformly from the postsynaptic population, independently across presynaptic neurons.- Parameters:
k (
int|float) – Out-degree. An int is an absolute count; a float in(0, 1]is a fraction of the allowed targets, resolved asround(k * post_num)(round(k * (post_num - 1))when self-connections are excluded).allow_self_connections (
bool) – If False and the populations have equal size, neuroninever targets neuroni(thektargets are drawn from the otherpost_num - 1neurons). Ignored whenpre_num != post_num.with_replacement (
bool) – If True, targets are drawn with replacement, so a pair may appear more than once (duplicate edges) andkmay exceedpost_num.weight (
Initialization|float|int|ndarray|Array|Quantity|None) – Weight initialization (initializer, scalar, Quantity or array), drawn once per edge throughbraintools.init.param(). When both position arrays are given, per-edgedistancesare passed to the initializer so distance-dependent weights work. If None, no weights are generated.delay (
Initialization|float|int|ndarray|Array|Quantity|None) – Delay initialization, handled likeweight. If None, no delays.seed (
int|None) – Seed of the generator’s privatenp.random.RandomState.**kwargs – Further arguments of
Connectivity(pre_size,post_size).
- Raises:
TypeError – If
kis neither an int nor a float.ValueError – If
kis negative or a float outside(0, 1]; at generation time ifkexceeds the available targets (post_num, orpost_num - 1without self-connections) andwith_replacement=False.
See also
FixedInDegreeFixed number of inputs per postsynaptic neuron.
FixedTotalNumFixed total number of edges.
FixedProbIndependent per-pair connection probability.
ConnectionResult.to_fixed_num_per_preExport to
brainevent.FixedNumPerPre.
Notes
Without replacement each row is a uniformly random
k-subset, drawn by a vectorised sampler that redraws only duplicated entries (or, whenk > post_num / 2, takes theksmallest of i.i.d. uniform keys in row chunks of at most2**22pairs). Memory isO(pre_num * k); time isO(pre_num * k), orO(pre_num * post_num)on the key path, wherekis already a large fraction ofpost_num. Edges are returned sorted by presynaptic then postsynaptic index.metadatarecords'degree'(the resolved intk),'with_replacement'and'allow_self_connections'.Generation is host-side NumPy and is not traceable by
jax.jit; the exported brainevent matrices are.Examples
>>> import numpy as np >>> import brainunit as u >>> from braintools.conn import FixedOutDegree >>> conn = FixedOutDegree(10, weight=0.5 * u.nS, seed=0) >>> result = conn(pre_size=100, post_size=200) >>> result.n_connections 1000 >>> np.unique(np.bincount(result.pre_indices, minlength=100)) array([10]) >>> w = result.to_fixed_num_per_pre() >>> w.indices.shape (100, 10) >>> # k as a fraction of post_num, no self-connections >>> result = FixedOutDegree(0.1, allow_self_connections=False, seed=0)(50, 50) >>> result.metadata['degree'] 5 >>> bool(np.any(result.pre_indices == result.post_indices)) False