我已经从网络中采样了一些具有网络G
中节点度离散值的数据并计算了分布。
def degree_distribution(G):
vk = dict(G.degree())
vk = list(vk.values()) # we get only the degree values
maxk = np.max(vk)
mink = np.min(min)
kvalues= np.arange(0,maxk+1) # possible values of k
Pk = np.zeros(maxk+1) # P(k)
for k in vk:
Pk[k] = Pk[k] + 1
Pk = Pk/sum(Pk) # the sum of the elements of P(k) must to be equal to one
return kvalues,Pk
调用它:
kvalues, Pk = degree_distribution(G)
dict_prob = dict(zip(kvalues,Pk))
我得到:
{0: 0.0,
1: 0.0,
2: 0.0016146393972012918,
3: 0.004843918191603875,
4: 0.011840688912809472,
5: 0.03336921420882669,
6: 0.07319698600645856,
7: 0.10764262648008611,
8: 0.15177610333692143,
9: 0.16361679224973089,
10: 0.16254036598493002,
11: 0.11679224973089343,
12: 0.08880516684607104,
13: 0.052206673842841764,
14: 0.02099031216361679,
15: 0.006996770721205597,
16: 0.003767491926803014}
如何使用scipy
?