watts_strogatz_graph#
- watts_strogatz_graph(n, k, p, seed=None, *, create_using=None)[source]#
Returns a Watts–Strogatz small-world graph.
- Parameters:
- nint
The number of nodes
- kint
Each node is joined with its
k
nearest neighbors in a ring topology.- pfloat
The probability of rewiring each edge
- seedinteger, random_state, or None (default)
Indicator of random number generation state. See Randomness.
- create_usingGraph constructor, optional (default=nx.Graph)
Graph type to create. If graph instance, then cleared before populated. Multigraph and directed types are not supported and raise a
NetworkXError
.
Notes
First create a ring over
nodes [1]. Then each node in the ring is joined to its nearest neighbors (or neighbors if is odd). Then shortcuts are created by replacing some edges as follows: for each edge in the underlying “ -ring with nearest neighbors” with probability replace it with a new edge with uniformly random choice of existing node .In contrast with
newman_watts_strogatz_graph()
, the random rewiring does not increase the number of edges. The rewired graph is not guaranteed to be connected as inconnected_watts_strogatz_graph()
.References
[1]Duncan J. Watts and Steven H. Strogatz, Collective dynamics of small-world networks, Nature, 393, pp. 440–442, 1998.