Ok, I figured that out as follows:
from networkx.utils import create_degree_sequence
import pylab as pl
import numpy as np
try:
import matplotlib.pyplot as plt
import matplotlib
except:
raise
from networkx import *
n=10000
print 'Creating powerlaw cluster with %d Nodes.' % n
gamma=2.2
powerlaw_gamma = lambda N: nx.utils.powerlaw_sequence(N, exponent=gamma)
z=nx.utils.create_degree_sequence(n,powerlaw_gamma,max_tries=100)
G=nx.configuration_model(z)
G = nx.connected_component_subgraphs(G)[0];
But something doesn't seem to be right. When I draw the Node Degree histogram, its not what it should be. Try this code:
degree_seq= list(degree(G).values());
uniques=np.unique(degree_seq);
uniques = np.append(uniques,uniques[-1]+1);
[y,x] = np.histogram(degree_seq,uniques);
x=x[:len(y)];
pl.loglog(x,y/float(sum(y)),'*r');
Alpha=gamma*-1;
XAxis = pl.unique(np.round(pl.logspace(0,pl.log10(n),25)));
YAxis = pl.unique(np.round(pl.logspace(0,pl.log10(n),25)))**(Alpha);
pl.loglog(XAxis,YAxis/float(sum(YAxis)),':b');
pl.xlabel('k,Degree');
pl.ylabel('P(k)');
pl.title('Node Degree Distribution');
pl.legend({'Expected (Alpha = -2.2)','Node Degree Distribution'});
pl.plot();
pl.show();
I have attached the resulting pdf in this post. The degree distribution doesn't appear to be quite right (or does it?)
Thanks!
-Hossein