I want to do exactly the same thing as this post, but in python; aka given a list of natural integers, generate a random adjacency matrix whose degrees would match the list.
I had great hope as the solution proposed uses a function from igraph, sample_degseq. However it seems like this function does not exist in the python version of igraph, at least as far as looked into it.
I could program such a function myself but I'm not exactly smart enough to make it fast enough, and I would like this to be done in an efficient way.
The equivalent of R/igraph's sample_degseq()
in python-igraph is Graph.Degree_Sequence()
. Note that not all methods sample uniformly, and not all methods produce the same kind of graph (simple graph vs multigraph).
"configuration_simple"
and "edge_switching_simple"
sample simple graphs uniformly. The former is exactly uniform (but very slow for anything but small degrees) and the latter almost exactly uniform.
I recommend "edge_switching_simple"
. It basically generates a first graph using Graph.Realize_Degree_Sequence()
, then it rewires it using rewire()
, using 10 times as many steps as the number of edges.