如何在python-igraph中播种图生成器? [英] How to seed graph generator in python-igraph?
本文介绍了如何在python-igraph中播种图生成器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有任何方法可以播种以下使用python-igraph生成的Watts-Strogatz图,以便每次运行脚本时都获得相同的SW图实现?
Is there any way to seed the following Watts-Strogatz graph generated using python-igraph, so that each time I run the script I get the same realization of SW graph ?
import igraph
graph = igraph.Graph.Watts_Strogatz(1, N, nei, p)
其中N
是节点数,nei
所连接的邻居数,以及p
的重新布线概率.
where N
is the number of nodes, nei
the number of connected neighbors, and p
the rewiring probability.
推荐答案
igraph使用Python的内置RNG,因此您可以播种该种子:
igraph uses the built-in RNG of Python so you can seed that:
In [1]: import random
In [2]: random.seed(1234)
In [3]: g=Graph.Watts_Strogatz(1, 100, 2, 0.25)
In [4]: random.seed(1234)
In [5]: g2=Graph.Watts_Strogatz(1, 100, 2, 0.25)
In [6]: g.get_edgelist() == g2.get_edgelist()
Out[6]: True
这篇关于如何在python-igraph中播种图生成器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文