FixedTotalNum#
- class braintools.conn.FixedTotalNum(n, *, allow_self_connections=True, with_replacement=False, weight=None, delay=None, seed=None, **kwargs)#
Draw exactly
nedges uniformly over all allowed (pre, post) pairs.- Parameters:
n (
int|float) – Number of edges. An int is an absolute count; a float in(0, 1]is a fraction of the allowed pairs, resolved asround(n * pre_num * post_num)(round(n * pre_num * (post_num - 1))when self-connections are excluded).allow_self_connections (
bool) – If False and the populations have equal size, pairs(i, i)are never drawn. Ignored whenpre_num != post_num.with_replacement (
bool) – If True, thenpairs are drawn independently with replacement, so a pair may appear more than once andnmay exceed the number of pairs.weight (
Initialization|float|int|ndarray|Array|Quantity|None) – Weight initialization (initializer, scalar, Quantity or array), drawn once per edge throughbraintools.init.param(). 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
nis neither an int nor a float.ValueError – If
nis negative or a float outside(0, 1]; at generation time ifnexceeds the number of allowed pairs andwith_replacement=False.
See also
Notes
The pairs are
ndistinct flat indices into the (virtual)pre_num x post_nummatrix (pre_num x (post_num - 1)without self-connections, remapped by shifting), drawn by rejection of duplicates whennis at most half the pairs and by a permutation of at most2 nvalues otherwise, so memory isO(n). UnlikeFixedProb, the edge count is exact rather than binomial. Edges are returned sorted by presynaptic then postsynaptic index.metadatarecords'n'(the resolved int count),'with_replacement'and'allow_self_connections'.Generation is host-side NumPy and is not traceable by
jax.jit.Examples
>>> import numpy as np >>> from braintools.conn import FixedTotalNum >>> result = FixedTotalNum(500, allow_self_connections=False, seed=0)(100, 100) >>> result.n_connections 500 >>> codes = result.pre_indices * 100 + result.post_indices >>> np.unique(codes).size, bool(np.any(result.pre_indices == result.post_indices)) (500, False)