问题
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)
where N
is the number of nodes, nei
the number of connected neighbors, and p
the rewiring probability.
回答1:
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
来源:https://stackoverflow.com/questions/25718008/how-to-seed-graph-generator-in-python-igraph