Random

Random#

class braintools.conn.Random(prob, allow_self_connections=False, weight=None, delay=None, **kwargs)#

Random connectivity with fixed connection probability.

This is the fundamental random connectivity pattern for point neurons, where each potential connection is made with a fixed probability.

Parameters:
  • prob (float) – Connection probability between 0 and 1.

  • allow_self_connections (bool) – Whether to allow neurons to connect to themselves.

  • weight (Initialization | float | int | ndarray | Array | Quantity | None) –

    Weight initialization. Can be:

    • Initialization class (e.g., Normal, LogNormal, Constant)

    • Scalar value (float/int, will use nS units)

    • Quantity scalar or array

    • Array-like values

    If None, no weights are generated.

  • delay (Initialization | float | int | ndarray | Array | Quantity | None) –

    Delay initialization. Can be:

    • Initialization class (e.g., ConstantDelay, UniformDelay)

    • Scalar value (float/int, will use ms units)

    • Quantity scalar or array

    • Array-like values

    If None, no delays are generated.

  • seed (int, optional) – Random seed for reproducible results.

Examples

Basic random connectivity:

>>> import brainunit as u
>>> from braintools.conn import Random
>>> from braintools.init import Constant
>>>
>>> # With weights and delays
>>> conn = Random(
...     prob=0.1,
...     weight=Constant(2.0 * u.nS),
...     delay=Constant(1.0 * u.ms),
...     seed=42
... )
>>> result = conn(pre_size=1000, post_size=1000)
>>>
>>> # Topology only (no weights or delays)
>>> topology_only = Random(prob=0.1, seed=42)
>>> result = topology_only(pre_size=1000, post_size=1000)
>>>
>>> # Using scalar values (automatic units)
>>> simple_conn = Random(prob=0.1, weight=2.5, delay=1.0, seed=42)
>>> result = simple_conn(pre_size=1000, post_size=1000)

Random with realistic synaptic weights:

>>> from braintools.init import LogNormal, Normal
>>>
>>> # AMPA-like excitatory synapses
>>> ampa_conn = Random(
...     prob=0.05,
...     weight=LogNormal(mean=1.0 * u.nS, std=0.5 * u.nS),
...     delay=Normal(mean=1.5 * u.ms, std=0.3 * u.ms)
... )

Inhibitory connections with Dale’s principle:

>>> from braintools.init import Normal, Constant
>>>
>>> # GABA-like inhibitory synapses
>>> gaba_conn = Random(
...     prob=0.08,
...     weight=Normal(mean=-0.8 * u.nS, std=0.2 * u.nS),
...     delay=Constant(0.8 * u.ms)
... )
generate(pre_size, post_size, pre_positions=None, post_positions=None, **kwargs)[source]#

Generate random point neuron connections.

Return type:

ConnectionResult