This documents an unmaintained version of NetworkX. Please upgrade to a maintained version and see the current NetworkX documentation.
- watts_strogatz_graph(n, k, p, seed=None)¶
Return a Watts-Strogatz small-world graph.
n : int
The number of nodes
k : int
Each node is connected to k nearest neighbors in ring topology
p : float
The probability of rewiring each edge
seed : int, optional
Seed for random number generator (default=None)
First create a ring over n nodes. Then each node in the ring is connected with its k nearest neighbors (k-1 neighbors if k is odd). Then shortcuts are created by replacing some edges as follows: for each edge u-v in the underlying “n-ring with k nearest neighbors” with probability p replace it with a new edge u-w with uniformly random choice of existing node w.
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 in connected_watts_strogatz_graph().
[R313] Duncan J. Watts and Steven H. Strogatz, Collective dynamics of small-world networks, Nature, 393, pp. 440–442, 1998.