SmallWorld

SmallWorld#

class braintools.conn.SmallWorld(k=6, p=0.3, weight=None, delay=None, **kwargs)#

Watts-Strogatz small-world network topology.

This class implements the Watts-Strogatz model for generating small-world networks, which exhibit both high clustering coefficient (like regular lattices) and short average path length (like random graphs). The algorithm starts with a regular ring lattice where each node connects to its k nearest neighbors, then randomly rewires each edge with probability p.

The small-world property is characteristic of many real-world networks, including neural networks, social networks, and power grids, making this a biologically plausible connectivity pattern for neural simulations.

Parameters:
  • k (int) – Number of nearest neighbors each node connects to in the initial ring lattice. Must be an even number. Higher values create more local connections and increase the clustering coefficient.

  • p (float) – Rewiring probability for each edge. Valid range is [0, 1]. - p=0: Regular ring lattice with high clustering, long path length - p=1: Random graph with low clustering, short path length - 0<p<1: Small-world network with high clustering and short path length

  • weight (Initialization | float | int | ndarray | Array | Quantity | None) – Weight initialization for each connection. Can be a scalar value, array, or an Initializer instance for more complex initialization patterns. If None, no weights are generated.

  • delay (Initialization | float | int | ndarray | Array | Quantity | None) – Delay initialization for each connection. Can be a scalar value, array, or an Initializer instance for more complex initialization patterns. If None, no delays are generated.

  • **kwargs – Additional keyword arguments passed to the parent PointConnectivity class, such as ‘seed’ for random number generation.

Notes

  • This connectivity pattern requires pre_size == post_size (recurrent connectivity)

  • Self-connections are automatically avoided during rewiring

  • The resulting network maintains exactly n*k connections where n is the network size

  • The algorithm is vectorized for efficient generation of large networks

References

Examples

Create a small-world network with default parameters:

>>> import brainunit as u
>>> from braintools.conn import SmallWorld
>>> sw = SmallWorld(k=6, p=0.3, weight=0.8 * u.nS)
>>> result = sw(pre_size=1000, post_size=1000)

Create a small-world network with higher rewiring probability:

>>> sw = SmallWorld(k=10, p=0.5, weight=1.0 * u.nS, delay=2.0 * u.ms)
>>> result = sw(pre_size=500, post_size=500)

Use with a custom weight initializer:

>>> from braintools.init import Normal
>>> sw = SmallWorld(k=8, p=0.2, weight=Normal(mean=1.0, std=0.1))
>>> result = sw(pre_size=1000, post_size=1000)
generate(**kwargs)[source]#

Generate small-world network connections.

Return type:

ConnectionResult