generate_kernel_graph#
- graph_tool.generation.generate_kernel_graph(N, kernel_integral, kernel_root=None)[git][source]#
Generate a random graph from an inhomogeneous random graph model with a given kernel.
- Parameters:
- N
int Number of vertices.
- kernel_integralfunction
Function \(F(y, a, b) = \int_a^b\kappa(x, y)\,\mathrm{d}x\) of the symmetric kernel \(\kappa\).
- kernel_rootfunction (optional, default:
None) Function that returns \(b\) such that \(F(y, a, b) = r\), given \((y, a, r)\). If not given, it is computed numerically with
scipy.optimize.brentq().
- N
- Returns:
- g
Graph The generated undirected graph.
- g
See also
generate_chung_luGraphs with given expected degrees
generate_random_dot_productRandom dot product graph
generate_maxent_sbmMaximum-entropy stochastic block model
Notes
In the inhomogeneous random graph model of Bollobás, Janson, and Riordan [bollobas-phase-2007], in the version of Hagberg and Lemons [hagberg-fast-2015], the vertex with index \(i-1\), for \(i=1,\dots,N\), has the type \(x_i = i/N\), and every pair \(i < j\) is connected independently with probability
\[p_{ij} = 1 - \exp\left(-\int_{x_{j-1}}^{x_j}\kappa(x, x_i)\, \mathrm{d}x\right) = 1 - e^{-F(x_i, x_{j-1}, x_j)},\]which approaches \(\kappa(x_i, x_j)/N\) for large \(N\) if the kernel is continuous and bounded. No self-loops or parallel edges are formed. For every \(i\), the algorithm jumps from one neighbor \(j\) to the next by drawing \(r\) from the exponential distribution with unit mean and solving \(F(x_i, x_j, b) = r\) for \(b\), which gives the next neighbor \(\lceil Nb\rceil\) (there is none if \(F(x_i, x_j, 1) \le r\)), so that the time is \(O(N + E)\) calls to the kernel functions. These are Python functions, which dominate the running time.
References
[bollobas-phase-2007]Béla Bollobás, Svante Janson and Oliver Riordan, “The phase transition in inhomogeneous random graphs”, Random Structures & Algorithms 31, 3-122 (2007), DOI: 10.1002/rsa.20168 [sci-hub, @tor], arXiv: math/0504589
[hagberg-fast-2015]Aric Hagberg and Nathan Lemons, “Fast generation of sparse random kernel graphs”, PLoS ONE 10, e0135177 (2015), DOI: 10.1371/journal.pone.0135177 [sci-hub, @tor]
Examples
The Erdős-Rényi graph with average degree \(c\) has constant kernel \(\kappa = c\):
>>> c = 3 >>> g = gt.generate_kernel_graph(1000, lambda y, a, b: c * (b - a), ... lambda y, a, r: a + r / c) >>> print(g.num_edges()) 1472
A smaller instance is drawn as follows:
>>> g = gt.generate_kernel_graph(200, lambda y, a, b: c * (b - a), ... lambda y, a, r: a + r / c) >>> gt.graph_draw(g, pos=gt.sfdp_layout(g), ... output="generate_kernel_graph-small.pdf") <...>
Inhomogeneous random graph with \(N=200\) and the constant kernel \(\kappa=3\).#