In [216]:
import networkx as nx
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt

In [217]:
R = nx.erdos_renyi_graph(n=1000,p=.3)
n = len(R.nodes())
e = len(R.edges())

print('nodes:',n)
print('edges:',e)


nodes: 1000
edges: 149539

In [218]:
k = np.array([ len(list(R.neighbors(n=n))) for n in R.nodes() ])

In [219]:
k_avg = np.mean(k)
k_var = np.var(k)
k_std = np.sqrt(k_var)

print("mean:",k_avg)
print("var:",k_var)
print("std:",k_std)


mean: 299.078
var: 211.429916
std: 14.5406298351

In [220]:
# plot distribution (binomial)
sns.set()

_ = plt.hist(k,bins=25,normed=True)
_ = plt.xlabel('degrees')
_ = plt.ylabel('%')

plt.margins(0.02)

plt.show()



In [221]:
# plot ecdf
x = np.sort(k)
y = np.arange(1,n+1)/n

sns.set()

_ = plt.plot(x,y, marker='.',linestyle='none')
_ = plt.xlabel('degree')
_ = plt.ylabel('ecdf')

plt.margins(0.02)
plt.show()



In [222]:
B = nx.barabasi_albert_graph(n=10000,m=1)

n = len(B.nodes())
e = len(B.edges())

print('nodes:',n)
print('edges:',e)


nodes: 10000
edges: 9999

In [223]:
k = np.array([ len(list(B.neighbors(n=n))) for n in B.nodes() ])

In [224]:
k_avg = np.mean(k)
k_var = np.var(k)
k_std = np.sqrt(k_var)

print("mean:",k_avg)
print("var:",k_var)
print("std:",k_std)


mean: 1.9998
var: 13.31259996
std: 3.6486435781

In [225]:
# plot distribution (Exponential)
sns.set()

_ = plt.hist(k,normed=True,log=True)
_ = plt.xlabel('degrees')
_ = plt.ylabel('%')

plt.margins(0.02)

plt.show()



In [239]:
# plot ecdf
x = np.sort(k)
y = np.arange(1,n+1)/n

sns.set()

_ = plt.plot(np.log(x),y,marker='.',linestyle='none')
_ = plt.xlabel('log of degree')
_ = plt.ylabel('ecdf')

plt.margins(0.02)
plt.show()



In [ ]: