NetworkX

Previous topic

networkx.newman_watts_strogatz_graph

Next topic

networkx.random_regular_graph

Quick search

networkx.watts_strogatz_graph

watts_strogatz_graph(n, k, p, seed=None)

Return a Watts-Strogatz small world graph.

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 rewiring existing edges as follows: for each edge u-v in the underlying “n-ring with k nearest neighbors” with probability p replace u-v with a new edge u-w with randomly-chosen existing node w. In contrast with newman_watts_strogatz_graph(), the random rewiring does not increase the number of edges.

Parameters:
  • n: the number of nodes
  • k: each node is connected to k neighbors in the ring topology
  • p: the probability of rewiring an edge
  • seed: seed for random number generator (default=None)