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 k presynaptic neurons.

The k sources 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 as round(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, neuron j never receives from neuron j (sources are drawn from the other pre_num - 1 neurons). Ignored when pre_num != post_num.

  • with_replacement (bool) – If True, sources are drawn with replacement, so a pair may appear more than once (duplicate edges) and k may exceed pre_num.

  • weight (Initialization | float | int | ndarray | Array | Quantity | None) – Weight initialization (initializer, scalar, Quantity or array), drawn once per edge through braintools.init.param(). When both position arrays are given, per-edge distances are passed to the initializer. If None, no weights are generated.

  • delay (Initialization | float | int | ndarray | Array | Quantity | None) – Delay initialization, handled like weight. If None, no delays.

  • seed (int | None) – Seed of the generator’s private np.random.RandomState.

  • **kwargs – Further arguments of Connectivity (pre_size, post_size).

Raises:
  • TypeError – If k is neither an int nor a float.

  • ValueError – If k is negative or a float outside (0, 1]; at generation time if k exceeds the available sources (pre_num, or pre_num - 1 without self-connections) and with_replacement=False.

See also

FixedOutDegree

Fixed number of outputs per presynaptic neuron.

FixedTotalNum

Fixed total number of edges.

ConnectionResult.to_fixed_num_per_post

Export to brainevent.FixedNumPerPost.

Network

Populations and projections built from connectivities.

Notes

Uses the same sampler as FixedOutDegree with the roles of pre and post swapped; memory is O(post_num * k). Edges are returned grouped by postsynaptic neuron (sorted by post, then pre index), which is the layout of brainevent.FixedNumPerPost. metadata records 'degree' (the resolved int k), '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
generate(pre_size, post_size, pre_positions=None, post_positions=None, **kwargs)[source]#

Generate the fixed in-degree connections.

Return type:

ConnectionResult

property k: int | float#

The in-degree as given (int count or fraction).