Network_Generator.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:PhD 作者: wutaoadeny 项目源码 文件源码
def Degree_distribution(G):
    Nodes = G.nodes()
    Degree_List = []
    Degree_Dic = {}
    for i in Nodes:
        Degree_List.append(G.degree(i))
    Degree_List = sorted(Degree_List, reverse = False)
    Flag = Degree_List[0]
    Count = 1
    for i in Degree_List[1:]:
        if i !=Flag:
            Degree_Dic[Flag] = Count
            Count = 1
            Flag = i
        else:
            Count = Count + 1
    #end for
    #print Degree_Dic
    n = G.number_of_nodes()
    plt.figure(1)
    ax1 = plt.subplot(111)
    plt.sca(ax1)
    #x = list([(i+1) for i in range(0,len(Degree_List))])
    x = sorted(Degree_Dic.keys(), reverse = False)
    y = []
    for i in x:
        y.append(float(Degree_Dic[i])/n)
    #end for
    plt.plot(x, y, "rs-")
    plt.ylabel("Probability")
    plt.xlabel("Degree K")
    plt.title("Degree distribution of networks")
    plt.show()


#************************************************************************
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号