0

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()
  • 1
    What are `eigvec_cent` and `betw_cent` ? – micro5 Apr 22 '22 at 05:52
  • @micro5 theyre the eigenvector and between centrality values from networkx library eigenvector centrality and between centrality functions – laurimikhael Apr 22 '22 at 07:59
  • 1
    centralities can hold negative values when you use negative weight of the edges. and it seems that you might have normalized these values. can you share the code used to calculated these centralities and sample graph. – micro5 Apr 22 '22 at 09:08
  • degr_cent = nx.degree_centrality(G) eigvec_cent = nx.eigenvector_centrality(G) betw_cent = nx.betweenness_centrality(G) #degree centrality histogram dc_degr_histogram = nx.degree_histogram(G) dc_degrees = range(len(dc_degr_histogram)) – laurimikhael Apr 22 '22 at 10:31
  • @mikro5 yeah that was what I figured out aswell, but when iterating through the values with sorting the smallest values were around 0.00000000012 with no negatives – laurimikhael Apr 22 '22 at 10:33
  • I have gone ahead and edited the original post with the information for clearer image, thank you for your time! – laurimikhael Apr 22 '22 at 10:33

0 Answers0