random_kernel_graph#
- random_kernel_graph(n, kernel_integral, kernel_root=None, seed=None, *, create_using=None)[source]#
Returns an random graph based on the specified kernel.
The algorithm chooses each of the
possible edges with probability specified by a kernel [1]. The kernel must be a symmetric (in ), non-negative, bounded function.- Parameters:
- nint
The number of nodes
- kernel_integralfunction
Function that returns the definite integral of the kernel
,- kernel_root: function (optional)
Function that returns the root
of the equation . If None, the root is found usingscipy.optimize.brentq()
(this requires SciPy).- seedinteger, random_state, or None (default)
Indicator of random number generation state. See Randomness.
- create_usingGraph constructor, optional (default=nx.Graph)
Graph type to create. If graph instance, then cleared before populated. Multigraph and directed types are not supported and raise a
NetworkXError
.
See also
gnp_random_graph
expected_degree_graph
Notes
The kernel is specified through its definite integral which must be provided as one of the arguments. If the integral and root of the kernel integral can be found in
time then this algorithm runs in time where m is the expected number of edges [2].The nodes are set to integers from
to .References
[1]Bollobás, Béla, Janson, S. and Riordan, O. “The phase transition in inhomogeneous random graphs”, Random Structures Algorithms, 31, 3–122, 2007.
[2]Hagberg A, Lemons N (2015), “Fast Generation of Sparse Random Kernel Graphs”. PLoS ONE 10(9): e0135177, 2015. doi:10.1371/journal.pone.0135177
Examples
Generate an Erdős–Rényi random graph
, with kernel where is the mean expected degree.>>> def integral(u, w, z): ... return c * (z - w) >>> def root(u, w, r): ... return r / c + w >>> c = 1 >>> graph = nx.random_kernel_graph(1000, integral, root)