NetworkX图形间与特征向量的中心性

发布于 2025-01-23 06:02:08 字数 2347 浏览 2 评论 0原文

在尝试绘制分布时,我在特征向量和中心融合中的价值方面遇到了麻烦。当前绘制时,当中心显然没有任何负值时,它显示的负值约为0.4至0.0。但是,我能够正确地绘制学度中心性。以下是目前出现的图像。

​/I.sstatic.net/aacwz.png“ alt =“在此处输入图像描述”>

目前代码看起来如下,我无法弄清楚为什么这个问题持续存在:

    degr_cent = nx.degree_centrality(G)
    eigvec_cent = nx.eigenvector_centrality(G)
    betw_cent = nx.betweenness_centrality(G)

    degree_sequence = sorted((d for n,d in G.degree()), reverse=True)
    fig = plt.figure("Degree of a random graph", figsize=(8, 8))
    axgrid = fig.add_gridspec(5, 4)
    ax = fig.add_subplot()
    ax.bar(*np.unique(degree_sequence, return_counts=True))
    ax.set_title("Degree histogram")
    ax.set_xlabel("Degree")
    ax.set_ylabel("# of Nodes")
    plt.savefig('degree_distribution.png')
    plt.show()

    #degree centrality histogram
    dc_degr_histogram = nx.degree_histogram(G)
    dc_degrees = range(len(dc_degr_histogram))
    dc_degr_histogram = nx.degree_histogram(G)
    dc_degrees = range(len(dc_degr_histogram))

   
    plt.figure(figsize=(12,8))
    plt.loglog(dc_degrees, dc_degr_histogram,'go-') 
    plt.xlabel('Degree')
    plt.ylabel('Frequency')
    plt.savefig('degree_distribution.png')
    plt.show()
    eigvec_values = eigvec_cent.values()
    eigvec_sequence = sorted(eigvec_values, reverse=True)
    
    fig = plt.figure("Degree of a random graph", figsize=(8, 8))
    axgrid = fig.add_gridspec(5, 4)
    ax = fig.add_subplot()
    ax.bar(*np.unique(eigvec_sequence, return_counts=True))
    ax.set_title("Eigenvec histogram")
    ax.set_xlabel("Eigenvec")
    ax.set_ylabel("# of Nodes")
    plt.savefig('eigvec_distribution.png')
    plt.show()
    
    betw_cent_values = betw_cent.values()

    
    betw_cent_values = sorted(betw_cent_values)
    fig = plt.figure("Degree of a random graph", figsize=(8, 8))
    axgrid = fig.add_gridspec(5, 4)
    ax = fig.add_subplot()
    ax.bar(*np.unique(betw_cent_values, return_counts=True))
    ax.set_title("betweenness")
    ax.set_xlabel("betw")
    ax.set_ylabel("# of Nodes")
    plt.savefig('betweenness_distribution.png')
    plt.show()

I am having trouble with the values coming out of eigenvector and betweenness centralities when trying to graph the distributions. Currently when graphing it shows negative values of around 0.4 to 0.0 when there clearly aren't any negative values in the centralities. However I am able to graph the degree centrality correctly. Below are images of what comes out currently.

enter image description here

enter image description here

enter image description here

The code looks like the following at the moment and I am unable to figure out why this problem persists:

    degr_cent = nx.degree_centrality(G)
    eigvec_cent = nx.eigenvector_centrality(G)
    betw_cent = nx.betweenness_centrality(G)

    degree_sequence = sorted((d for n,d in G.degree()), reverse=True)
    fig = plt.figure("Degree of a random graph", figsize=(8, 8))
    axgrid = fig.add_gridspec(5, 4)
    ax = fig.add_subplot()
    ax.bar(*np.unique(degree_sequence, return_counts=True))
    ax.set_title("Degree histogram")
    ax.set_xlabel("Degree")
    ax.set_ylabel("# of Nodes")
    plt.savefig('degree_distribution.png')
    plt.show()

    #degree centrality histogram
    dc_degr_histogram = nx.degree_histogram(G)
    dc_degrees = range(len(dc_degr_histogram))
    dc_degr_histogram = nx.degree_histogram(G)
    dc_degrees = range(len(dc_degr_histogram))

   
    plt.figure(figsize=(12,8))
    plt.loglog(dc_degrees, dc_degr_histogram,'go-') 
    plt.xlabel('Degree')
    plt.ylabel('Frequency')
    plt.savefig('degree_distribution.png')
    plt.show()
    eigvec_values = eigvec_cent.values()
    eigvec_sequence = sorted(eigvec_values, reverse=True)
    
    fig = plt.figure("Degree of a random graph", figsize=(8, 8))
    axgrid = fig.add_gridspec(5, 4)
    ax = fig.add_subplot()
    ax.bar(*np.unique(eigvec_sequence, return_counts=True))
    ax.set_title("Eigenvec histogram")
    ax.set_xlabel("Eigenvec")
    ax.set_ylabel("# of Nodes")
    plt.savefig('eigvec_distribution.png')
    plt.show()
    
    betw_cent_values = betw_cent.values()

    
    betw_cent_values = sorted(betw_cent_values)
    fig = plt.figure("Degree of a random graph", figsize=(8, 8))
    axgrid = fig.add_gridspec(5, 4)
    ax = fig.add_subplot()
    ax.bar(*np.unique(betw_cent_values, return_counts=True))
    ax.set_title("betweenness")
    ax.set_xlabel("betw")
    ax.set_ylabel("# of Nodes")
    plt.savefig('betweenness_distribution.png')
    plt.show()

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文