graphscope.nx.generators.directed.gn_graph(n, kernel=None, create_using=None, seed=None)[source]

Returns the growing network (GN) digraph with n nodes.

The GN graph is built by adding nodes one at a time with a link to one previously added node. The target node for the link is chosen with probability based on degree. The default attachment kernel is a linear function of the degree of a node.

The graph is always a (directed) tree.

  • n (int) – The number of nodes for the generated graph.

  • kernel (function) – The attachment kernel.

  • create_using (NetworkX graph constructor, optional (default DiGraph)) – Graph type to create. If graph instance, then cleared before populated.

  • seed (integer, random_state, or None (default)) – Indicator of random number generation state. See Randomness.


To create the undirected GN graph, use the to_directed() method:

>>> D = nx.gn_graph(10)  # the GN graph
>>> G = D.to_undirected()  # the undirected version

To specify an attachment kernel, use the kernel keyword argument:

>>> D = nx.gn_graph(10, kernel=lambda x: x ** 1.5)  # A_k = k^1.5