random_kernel_graph(n, kernel_integral, kernel_root=None, seed=None)¶
Returns an random graph based on the specified kernel.
The algorithm chooses each of the \([n(n-1)]/2\) possible edges with probability specified by a kernel \(\kappa(x,y)\) 1. The kernel \(\kappa(x,y)\) must be a symmetric (in \(x,y\)), non-negative, bounded function.
n (int) – The number of nodes
kernal_integral (function) – Function that returns the definite integral of the kernel \(\kappa(x,y)\), \(F(y,a,b) := \int_a^b \kappa(x,y)dx\)
kernel_root (function (optional)) – Function that returns the root \(b\) of the equation \(F(y,a,b) = r\). If None, the root is found using
scipy.optimize.brentq()(this requires SciPy).
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 \(O(1)\) time then this algorithm runs in time \(O(n+m)\) where m is the expected number of edges 2.
The nodes are set to integers from \(0\) to \(n-1\).
Generate an Erdős–Rényi random graph \(G(n,c/n)\), with kernel \(\kappa(x,y)=c\) where \(c\) 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)