Bases: Algorithm
Implementation of IM-CB proposed in “Parallel and I/O-efficient Randomisation of Massive Networks using Global Curveball Trades”, Carstens et al., ESA 2018.
The algorithm perturbs an undirected and unweighted input graph, by iteratively randomizing the neighbourhoods of node pairs. For a large number of trades this process is shown to produce an uniform sample from the set of all graphs with the same degree sequence as the input graph.
If you do not want to explicitly control the trade sequence, we recommend using GlobalCurveball rather than Curveball since GlobalCurveball is typically faster and exhibits a smaller memory footprint.
Observe that this algorithm does not support the run() method, since it requires the trade sequence to be passed. It is possible to invoke run(trades) several times, e.g. to reduce the memory footprint which increases linearly with the number of trades performed in a run.
G (networkit.Graph) – The graph to be randomized. For a given degree sequence, e.g. generators.HavelHakimi can be used to obtain this graph.
Get randomized graph after invocation of run().
The randomized graph.
networkit.Graph
Return number of affected edges.
Number of edges affected by randomization.
int
Compute the randomization of the input by given node pairs.
trades (list(tuple(int, int))) – List of pairs of nodes used for randomization of the graph.
Bases: object
Generates a trade sequence consisting of num_global_trades global trades targeting node ids from the range [0, num_nods).
If you are only using this generator, consider using the GlobalCurveball algorithm directly as it has a better performance / memory footprint.
num_global_trades (int) – Number of global trades to generate (i.e. the resulting sequence contains num_global_trades * floor(num_nodes / 2) trades)
num_nodes (int) – Number of node indices to draw from
Generate randomized graph.
The randomized graph.
networkit.Graph
Bases: object
Generates a trade sequence consisting of num_trades many single trades. Each trade contains two different node indices drawn uniformly at random from the interval [0, num_nodes).
num_trades (int) – Number of trades to generate.
num_nodes (int) – Number of node indices to draw from
Bases: Algorithm
Implementation of the preprocessing step proposed in “Smaller Universes for Uniform Sampling of 0,1-matrices with fixed row and column sums” by Annabell Berger, Corrie Jacobien Carstens [https://arxiv.org/abs/1803.02624]
The algorithms randomizes a graph without changing its topology simply by renaming nodes. For any degree d (in case of an directed graph it’s a degree pair) consider the set X_d of node ids which have this degree. Then shuffle the ids in X_d.
Hence the algorithm satisfies: For all x in Ginput:
Ginput.degreeIn(x) = Goutput.degreeIn(x)
Ginput.degreeOut(x) = Goutput.degreeOut(x)
The authors argue that applying this preprocessing step before executing (Global)Curveball leads to a faster mixing time. If you want to use it as a preprocessing step to GlobalCurveball, it’s more efficient to set degreePreservingShufflePreprocessing in GlobalCurveball’s constructor.
G (networkit.Graph) – The graph to be randomized. For a given degree sequence, e.g. generators.HavelHakimi can be used to obtain this graph.
Get randomized graph after invocation of run().
The randomized graph.
networkit.Graph
Returns the permutation used for shuffling.
List of nodes.
list(int)
Bases: Algorithm
The Edge Switching Markov Chain [“The markov chain simulation method for generating connected power law random graphs”, Mihail and Zegura] perturbs simple directed or undirected graphs while preserving their degrees. In each step, we select two edges uniformly at random, and exchange their endpoints. Swaps that introduce multi-edges or self-loops are rejected WITHOUT replacement – this is necessary to allow uniform sampling [see “Switching edges to randomize networks: what goes wrong and how to fix it”, Carstens and Horadam]. The number of successful swaps can be queried using getNumberOfAffectedEdges()/2.
We provide two implementations: EdgeSwitching takes a copy of the input graph and is more versatile; EdgeSwitchingInPlace works directly on the graph supplied but cannot carry-out an initial degreePreservingShufflePreprocessing.
In general, simple edge switching does not yield a uniform distribution on simple DIRECTED graphs because the orientation of directed triangles cannot be changed. Using DegreePreservingShuffle as a preprocessing step overcomes this limitation. The preprocessing can also jump-start the perturbation process, yielding to potentially faster mixing. It is performed by default for owned graphs.
G (networkit.Graph) – The graph to be randomized.
numberOfSwapsPerEdge (float, optional) – The average number of swaps to be carried out per edge. Has to be non-negative. Default: 10.0
degreePreservingShufflePreprocessing (bool, optional) – If true (default), in a preprocessing step jump starts the perturbation process. For undirected graph, this yields faster mixing; for directed graphs, it is necessary in order to obtain an unbiased sampling. Default: True
Perform edge switching. May be called multiple times.
Bases: Algorithm
The Edge Switching Markov Chain [“The markov chain simulation method for generating connected power law random graphs”, Mihail and Zegura] perturbs simple directed or undirected graphs while preserving their degrees. In each step, we select two edges uniformly at random, and exchange their endpoints. Swaps that introduce multi-edges or self-loops are rejected WITHOUT replacement – this is necessary to allow uniform sampling [see “Switching edges to randomize networks: what goes wrong and how to fix it”, Carstens and Horadam]. The number of successful swaps can be queried using getNumberOfAffectedEdges()/2.
We provide two implementations: EdgeSwitching takes a copy of the input graph and is more versatile; EdgeSwitchingInPlace works directly on the graph supplied but cannot carry-out an initial degreePreservingShufflePreprocessing.
In general, simple edge switching does not yield a uniform distribution on simple DIRECTED graphs because the orientation of directed triangles cannot be changed. Using DegreePreservingShuffle as a preprocessing step overcomes this limitation. The preprocessing can also jump-start the perturbation process, yielding to potentially faster mixing. It is only available for EdgeSwitching.
The implementation keeps a local reference (accessible via getGraph) to prevent premature garbage collection.
G (networkit.Graph) – The graph to be randomized.
numberOfSwitchesPerEdge (int, optional) – The average number of switches to be carried out per edge. Has to be non-negative. Default: 10
Return modified graph.
The graph after applying edge switches.
networkit.Graph
Return number of affected edges.
Number of edges affected by edge switches.
int
Return number of switches per edge.
Number of switches per edges.
list(int)
Bases: Algorithm
Implementation of EM-GCB proposed in “Parallel and I/O-efficient Randomisation of Massive Networks using Global Curveball Trades”, Carstens et al., ESA 2018.
The algorithm perturbs an unweighted input graph, by iteratively randomizing the neighbourhoods of node pairs. For a large number of global trades this process is shown to produce an uniform sample from the set of all graphs with the same degree sequence as the input graph.
If you do not want to explicitly control the trade sequence, we recommend using GlobalCurveball rather than Curveball since GlobalCurveball is typically faster and exhibits a smaller memory footprint.
G (networkit.Graph) – The graph to be randomized. For a given degree sequence, e.g. generators.HavelHakimi can be used to obtain this graph.
number_of_global_rounds (int, optional) – Number of global rounds to carry out. The runtime scales asymptotically linearly in this parameter. Default: 20, which yields good results experimentally (see Paper).
allowSelfLoops (bool, optional) – Has to be False for undirected graphs. For directed graphs the randomization Markov chain is only irreducible if self loops are allows. If they are forbidden, the degreePreservingShuffle preprocessing has to be enabled. Otherwise, not all topologies can be produced. Default: False
degreePreservingShufflePreprocessing (bool, optional) – Execute the DegreePreservingShuffle algorithm before executing Global Curveball. It’s more efficient than manually invoking the algorithm. Default: True
Note
For directed graphs at least one of allowSelfLoops or degreePreservingShufflePreprocessing should be set; for more details refer to “Switching edges to randomize networks: what goes wrong and how to fix it” by C. J. Carstens K. J. Horadam
Get randomized graph after invocation of run().
The randomized graph.
networkit.Graph