Commit b678e65a authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

Refactor random_rewire()

This extensively modifies the random_rewire() algorithm, so that only
either the source or the edge of each edge is rewired (not both, as
previously), and no parallel edges are created during the algorithm (if

The new version is much faster, and never gets stuck. However, more than
one run may be necessary in order to obtain a uniform shuffling.
parent 0a9f69de
This diff is collapsed.
......@@ -244,7 +244,8 @@ def random_rewire(g, strat= "uncorrelated", parallel_edges = False,
out) of each vertex are always the same, but otherwise the edges are
randomly placed. If `strat` == "correlated", the degree correlations are
also maintained: The new source and target of each edge both have the same
in and out-degree.
in and out-degree. If `strat` = "probabilistic", than edges are rewired
according to the degree correlation given by the parameter `deg_corr`.
......@@ -266,9 +267,21 @@ def random_rewire(g, strat= "uncorrelated", parallel_edges = False,
This algorithm iterates through all the edges in the network and tries to
swap its target our edge with another edge.
.. note::
If `parallel_edges` = False, parallel edges are not placed during
rewiring. In this case, for some special graphs it may be necessary to
call the function more than once to obtain a graph which corresponds to
a uniform sample from the ensemble. But typically, if the graph is
sufficiently large, a single call should be enough.
Each edge gets swapped at least once, so the overall complexity is
:math:`O(E)`. If `strat` = "probabilistic" the complexity is
:math:`O(E\log N_k)`, where :math:`N_k < V` is the number of different
degrees (or in,out-degree pairs).
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment