erdos_renyi_graph#

erdos_renyi_graph(n, p, seed=None, directed=False, *, create_using=None)#

返回一个\(G_{n,p}\)随机图,也称为Erdős-Rényi图或二项图。

\(G_{n,p}\)模型以概率\(p\)选择每一条可能的边。

参数:
nint

节点数。

pfloat

创建边的概率。

seedinteger, random_state, 或 None(默认)

随机数生成状态的指示器。参阅随机性

directedbool,可选(默认=False)

如果为 True,此函数返回一个有向图。

create_using图构造器,可选(默认=nx.Graph 或 nx.DiGraph)

要创建的图类型。如果是图实例,则在填充前会被清空。不支持多重图类型,会引发 NetworkXError 异常。默认情况下,根据 directed 参数使用 NetworkX Graph 或 DiGraph。

另请参阅

fast_gnp_random_graph

备注

此算法[2]的运行时间为\(O(n^2)\)。对于稀疏图(即\(p\)值较小的情况),fast_gnp_random_graph()是一种更快的算法。

binomial_graph()erdos_renyi_graph()gnp_random_graph() 的别名。

>>> nx.binomial_graph is nx.gnp_random_graph
True
>>> nx.erdos_renyi_graph is nx.gnp_random_graph
True

参考文献

[1]
  1. Erdős and A. Rényi, On Random Graphs, Publ. Math. 6, 290 (1959).

[2]
    1. Gilbert, Random Graphs, Ann. Math. Stat., 30, 1141 (1959).