FixedInDegree#
- class braintools.conn.FixedInDegree(k, *, allow_self_connections=True, with_replacement=False, weight=None, delay=None, seed=None, **kwargs)#
Connect every postsynaptic neuron to exactly
kpresynaptic neurons.The
ksources of each postsynaptic neuron are drawn uniformly from the presynaptic population, independently across postsynaptic neurons.- Parameters:
k (
int|float) – In-degree. An int is an absolute count; a float in(0, 1]is a fraction of the allowed sources, resolved asround(k * pre_num)(round(k * (pre_num - 1))when self-connections are excluded).allow_self_connections (
bool) – If False and the populations have equal size, neuronjnever receives from neuronj(sources are drawn from the otherpre_num - 1neurons). Ignored whenpre_num != post_num.with_replacement (
bool) – If True, sources are drawn with replacement, so a pair may appear more than once (duplicate edges) andkmay exceedpre_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. 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 sources (pre_num, orpre_num - 1without self-connections) andwith_replacement=False.
See also
FixedOutDegreeFixed number of outputs per presynaptic neuron.
FixedTotalNumFixed total number of edges.
ConnectionResult.to_fixed_num_per_postExport to
brainevent.FixedNumPerPost.NetworkPopulations and projections built from connectivities.
Notes
Uses the same sampler as
FixedOutDegreewith the roles of pre and post swapped; memory isO(post_num * k). Edges are returned grouped by postsynaptic neuron (sorted by post, then pre index), which is the layout ofbrainevent.FixedNumPerPost.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 jax.numpy as jnp >>> from braintools.conn import FixedInDegree >>> result = FixedInDegree(20, weight=0.1, seed=1)(pre_size=200, post_size=50) >>> np.unique(np.bincount(result.post_indices, minlength=50)) array([20]) >>> w = result.to_fixed_num_per_post() >>> w.shape, w.indices.shape ((200, 50), (50, 20)) >>> drive = jnp.ones(200) @ w # each post neuron sums 20 inputs of 0.1 >>> bool(jnp.allclose(drive, 2.0)) True