generate_watts_strogatz

generate_watts_strogatz#

graph_tool.generation.generate_watts_strogatz(N, k, p, newman=False)[git][source]#

Generate a small-world graph with the Watts-Strogatz model.

Parameters:
Nint

Number of vertices.

kint

Number of nearest neighbors on each side to which every vertex of the initial ring is connected (so that the average degree is \(2k\)).

pfloat

Rewiring probability (or shortcut probability, if newman == True).

newmanbool (optional, default: False)

If True, the variant of Newman and Watts is generated, where shortcuts are added instead of rewired.

Returns:
gGraph

The generated undirected graph.

See also

circular_graph

Ring lattice

generate_navigable_small_world

Kleinberg’s small-world model

graph_tool.structure.small_world_sigma

Small-world coefficient

Notes

The graph starts from a ring of \(N\) vertices, each connected to its \(k\) nearest neighbors on each side, as given by circular_graph(). In the Watts–Strogatz model [watts-collective-1998], every edge \((i, i+j \bmod N)\), with \(j=1,\dots,k\), is selected independently with probability \(p\) and removed. Afterwards, for every selected edge, a new edge \((i, v)\) is added, with \(v\) chosen uniformly at random among the vertices other than \(i\) that are not yet adjacent to it, so that no self-loops or parallel edges are formed (and no edge is added if \(i\) is already adjacent to all other vertices). In the variant of Newman and Watts [newman-renormalization-1999], the selected edges are kept, and the new edges \((i, v)\) are added as shortcuts in the same way, so that the graph remains connected. The algorithm runs in time \(O(Nk)\) on average.

References

[watts-collective-1998]

Duncan J. Watts and Steven H. Strogatz, “Collective dynamics of ‘small-world’ networks”, Nature 393, 440-442 (1998), DOI: 10.1038/30918 [sci-hub, @tor]

[newman-renormalization-1999]

M. E. J. Newman and D. J. Watts, “Renormalization group analysis of the small-world network model”, Physics Letters A 263, 341-346 (1999), DOI: 10.1016/S0375-9601(99)00757-4 [sci-hub, @tor], arXiv: cond-mat/9903357

Examples

>>> g = gt.generate_watts_strogatz(1000, 3, 0.05)
>>> print(g.num_edges(), gt.global_clustering(g)[0])
3000 0.5198068...

A smaller instance, with the vertices placed on a circle in the order of the initial ring, is drawn as follows:

>>> g = gt.generate_watts_strogatz(30, 2, 0.1)
>>> x = 2 * np.pi * np.arange(g.num_vertices()) / g.num_vertices()
>>> pos = g.new_vp("vector<double>",
...                vals=np.array([np.cos(x), np.sin(x)]).T)
>>> gt.graph_draw(g, pos=pos,
...               output="generate_watts_strogatz-ring.pdf")
<...>
../_images/generate_watts_strogatz-ring.png

Watts–Strogatz graph with \(N=30\), \(k=2\), and \(p=0.1\), with the vertices placed on a circle in the order of their indices.#