I want to generate a random graph using the edge distribution from the original graph. Is there a way in networkx module to do that?
1 Answer
I'm assuming you mean same degree distribution.
The command nx.configuration_model(degree_list) will do it.
So in your case, given an existing graph G:
H = nx.configuration_model([G.degree(node) for node in G])
4 Comments
namhsuya
Thanks! Also, is there any way I could fit it to a particular distribution? Say, if I wanted to fit it to a hypergeometric distribution.
Joel
As in the degree distribution be from a particular distribution? Yes - you generate a degree list using whatever distribution.
namhsuya
It would be great if you could probably add a code snippet on how to do that? I am just getting started with networkx. Cheers~
Joel
Instead of
[G.degree(node) for node in G] in the argument for nx.configuration_model, you'll need to create a list, say L whose entries come from whatever distribution you want. Depending on what that distribution is, you would need to generate L. Then you just use nx.configuration_model(L)