class brainpy.connect.SmallWorld(num_neighbor, prob, directed=False, include_self=False, seed=None, **kwargs)[source]#

Build a Watts–Strogatz small-world graph.

  • num_neighbor (int) – Each node is joined with its k nearest neighbors in a ring topology.

  • prob (float) – The probability of rewiring each edge

  • directed (bool) – Whether the graph is a directed graph.

  • include_self (bool) – Whether include the node self.


First create a ring over \(num\_node\) nodes [1]. Then each node in the ring is joined to its \(num\_neighbor\) nearest neighbors (or \(num\_neighbor - 1\) neighbors if \(num\_neighbor\) is odd). Then shortcuts are created by replacing some edges as follows: for each edge \((u, v)\) in the underlying “\(num\_node\)-ring with \(num\_neighbor\) nearest neighbors” with probability \(prob\) replace it with a new edge \((u, w)\) with uniformly random choice of existing node \(w\).



build connections with certain data type.

If users want to customize their connections, please provide one of the following functions:

  • build_mat(): build a matrix binary connection matrix.

  • build_csr(): build a csr sparse connection data.

  • build_coo(): build a coo sparse connection data.

  • build_conn(): deprecated.


conn – A tuple with two elements: connection type (str) and connection data. For example: return 'csr', (ind, indptr) Or a dict with three elements: csr, mat and coo. For example: return dict(csr=(ind, indptr), mat=None, coo=None)

Return type:

tuple, dict