random_rewire_lattice

random_rewire_lattice#

graph_tool.generation.random_rewire_lattice(g, niter=5, connected=True)[git][source]#

Return a degree-preserving rewiring of a simple undirected graph towards a ring lattice.

Parameters:
gGraph

Undirected graph. Self-loops and parallel edges are removed.

niterint (optional, default: 5)

Number of edge swaps per edge.

connectedbool (optional, default: True)

If True, swaps that would disconnect the graph are undone.

Returns:
hGraph

The rewired graph, with the same degrees.

See also

random_rewire_connected

Degree-preserving randomization

graph_tool.structure.small_world_omega

Small-world coefficient omega

random_rewire

General edge rewiring

Notes

The moves are the same as in random_rewire_connected(), including the reduction to a simple graph with vertices \(0,\dots,V-1\), the number of swaps and the connectivity constraint, but a swap \((a, b), (c, d) \to (a, d), (c, b)\) is done only if

\[D_{ad} + D_{cb} \le D_{ab} + D_{cd},\]

where \(D_{ij} = \min(|i-j|, V - |i-j|)\) is the distance between \(i\) and \(j\) on a ring with the vertices in index order. The total distance of the edges from the diagonal of the adjacency matrix never increases, so that the graph approaches a ring lattice with the same degrees [sporns-small-2004]. It is the lattice reference of small_world_omega().

References

[sporns-small-2004]

Olaf Sporns and Jonathan D. Zwi, “The small world of the cerebral cortex”, Neuroinformatics 2, 145-162 (2004), DOI: 10.1385/NI:2:2:145 [sci-hub, @tor]

Examples

>>> g = gt.collection.data["karate"]
>>> h = gt.random_rewire_lattice(g)
>>> print(gt.global_clustering(g)[0] < gt.global_clustering(h)[0])
True

A random regular graph and its rewiring towards a ring lattice are drawn as follows, with the vertices placed on a circle in the order of their indices:

>>> g = gt.random_graph(40, lambda: 4, directed=False)
>>> h = gt.random_rewire_lattice(g)
>>> x = 2 * np.pi * np.arange(40) / 40
>>> pos = g.new_vp("vector<double>",
...                vals=np.array([np.cos(x), np.sin(x)]).T)
>>> gt.graph_draw(g, pos=pos, output="random_rewire_lattice-orig.pdf")
<...>
>>> gt.graph_draw(h, pos=h.own_property(pos),
...               output="random_rewire_lattice-rewired.pdf")
<...>
../_images/random_rewire_lattice-orig.png

Random 4-regular graph with 40 vertices, placed on a circle in the order of their indices.#

../_images/random_rewire_lattice-rewired.png

The same graph after the rewiring towards a ring lattice, with the same vertex positions.#