generate_chung_lu#
- graph_tool.generation.generate_chung_lu(out_weights, in_weights=None, self_loops=True, variant='original')[git][source]#
Generate a random graph with given expected degrees, with the Chung-Lu model or one of its variants.
- Parameters:
- out_weightsiterable of
float Vertex weights \(w_i\) (or out-weights \(w^+_i\), if
in_weightsis given).- in_weightsiterable of
float(optional, default:None) In-weights \(w^-_i\). If given, a directed graph is generated, and the sum of the in-weights must be equal to the sum of the out-weights.
- self_loops
bool(optional, default:True) If
True, self-loops are allowed.- variant
str(optional, default:"original") Connection probability as a function of \(q_{ij}\):
"original","maxent", or"nr"(see below).
- out_weightsiterable of
- Returns:
- g
Graph The generated graph, without parallel edges.
- g
See also
generate_static_fitnessStatic model with arbitrary fitnesses
generate_sbmPoisson degree-corrected stochastic block model
generate_maxent_sbmMaximum-entropy stochastic block model
random_graphRandom graph with a given degree sequence
generate_s1Geometric model with given expected degrees
Notes
Every pair of vertices \((i, j)\) is connected independently with a probability that depends on \(q_{ij} = w_iw_j/S\), where \(S = \sum_kw_k\) (or \(q_{ij} = w^+_iw^-_j/S\), with \(S = \sum_k w^+_k = \sum_kw^-_k\), for directed graphs, where \(i\) is the source). In the original model of Chung and Lu [chung-connected-2002] (
variant="original"), \(p_{ij} = \min(q_{ij}, 1)\), so that, if \(q_{ij}\le 1\) for all pairs and self-loops are allowed, the expected out- and in-degrees of a directed graph are exactly \(w^+_i\) and \(w^-_i\). In the undirected case, the self-loops have probability \(w_i^2/S\) and count twice in the degree, so that the expected degree is \(w_i(S + w_i)/S\) with self-loops and \(w_i(S - w_i)/S\) without them. Withvariant="maxent", \(p_{ij} = q_{ij}/(1 + q_{ij})\), which is the maximum-entropy ensemble with constrained expected degrees (an exponential random graph model) [park-statistical-2004], also called the generalized random graph [britton-generating-2006], and withvariant="nr", \(p_{ij} = 1 - e^{-q_{ij}}\), which is the simple graph underlying the Poisson multigraph of Norros and Reittu [norros-conditionally-2006]. The variants coincide in the sparse limit \(q_{ij}\to 0\), and the last two yield valid probabilities for any weights.The
"maxent"variant is the maximum-entropy stochastic block model with a single group, with fugacities \(\theta_i = w_i\) and \(\mu = 1/S\), and is generated withgenerate_maxent_sbm(). The Poisson multigraph of the"nr"variant is the degree-corrected stochastic block model with a single group, with \(\lambda = S\) and \(\theta_i = w_i/S\), and the graph is generated withgenerate_sbm(), discarding the multiplicities of the edges. In this case, the number of self-loops of a vertex in the multigraph has mean \(q_{ii}/2\), since each counts twice in the degree, so that a self-loop is present with probability \(1 - e^{-q_{ii}/2}\), and the expected degree of the multigraph is exactly \(w_i\). The multigraph itself, with its parallel edges and self-loops, is obtained by callinggenerate_sbm()directly.For
variant="original", the pairs are sampled with the algorithm of Miller and Hagberg [miller-efficient-2011], which visits the targets in decreasing order of weight and skips runs of absent edges geometrically, and is also used bygenerate_maxent_sbm(). The time is \(O(N\log N + E)\) for"original"and"maxent", and \(O(N + E)\) for"nr".References
[chung-connected-2002]Fan Chung and Linyuan Lu, “Connected components in random graphs with given expected degree sequences”, Annals of Combinatorics 6, 125-145 (2002), DOI: 10.1007/PL00012580 [sci-hub, @tor]
[park-statistical-2004]Juyong Park and M. E. J. Newman, “Statistical mechanics of networks”, Physical Review E 70, 066117 (2004), DOI: 10.1103/PhysRevE.70.066117 [sci-hub, @tor], arXiv: cond-mat/0405566
[britton-generating-2006]Tom Britton, Maria Deijfen and Anders Martin-Löf, “Generating simple random graphs with prescribed degree distribution”, Journal of Statistical Physics 124, 1377-1397 (2006), DOI: 10.1007/s10955-006-9168-x [sci-hub, @tor]
[norros-conditionally-2006]Ilkka Norros and Hannu Reittu, “On a conditionally Poissonian graph process”, Advances in Applied Probability 38, 59-75 (2006), DOI: 10.1239/aap/1143936140 [sci-hub, @tor]
[miller-efficient-2011]Joel C. Miller and Aric Hagberg, “Efficient generation of networks with given expected degrees”, in Algorithms and Models for the Web Graph (WAW 2011), Lecture Notes in Computer Science 6732, 115-126 (2011), DOI: 10.1007/978-3-642-21286-4_10 [sci-hub, @tor]
Examples
>>> w = np.arange(1, 1001) ** -.5 >>> w *= 5000 / w.sum() >>> g = gt.generate_chung_lu(w) >>> print(g.num_edges(), g.degree_property_map("total").a[:3]) 2461 [89 53 58]
A smaller instance is drawn as follows, with the vertex sizes increasing with the weights:
>>> w = np.arange(1, 201) ** -.5 >>> w *= 600 / w.sum() >>> g = gt.generate_chung_lu(w) >>> size = g.new_vp("double", vals=3 + 3 * np.sqrt(w)) >>> gt.graph_draw(g, pos=gt.sfdp_layout(g), vertex_size=size, ... output="generate_chung_lu-small.pdf") <...>
Chung–Lu graph with \(N=200\) and weights \(w_i \propto i^{-1/2}\) with sum 600. The vertex sizes increase with the weights.#