Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to seed graph generator in python-igraph?

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.

like image 427
ADK Avatar asked Oct 24 '25 05:10

ADK


1 Answers

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
like image 60
Tamás Avatar answered Oct 26 '25 22:10

Tamás



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!