python - How do you create a networkx function for eigenvector centralization for a whole network? (Freeman) -


the question is: how compute eigenvector centralization graph using networkx?

(as in, not individual nodes, whole graph comparing nodes, using freeman's method doing this).

i need compare number of different graphs , wish use 4 different centrality measures comparing them:

  • closeness
  • betweenness
  • degree
  • eigenvector

currently networkx doesn't have functions compute centralization whole network - of functions return dictionary of centrality each node.

note centralization distribution of centrality within network.

i've written function can compute centrality whole network first 3 of these, can't figure out how compute eigenvector centrality.

the theory ought sum(max centrality - centrality each node) divided theoretical maximum network of size n.

the closest can figuring out how eigenvector centrality seeing theory on slide 32 of this set of lecture notes looks this:

ce<-function(y) {     n<-nrow(y)     e<-evecc(y)     y.sgn<-matrix(0,n,n) ; y.sgn[1,-1]<-1 ; y.sgn<-y.sgn+t(y.sgn)     e.sgn<-evecc(y.sgn)     sum(max(e)-e)/ sum(max(e.sgn)-e.sgn) } 

this seems sum of (max eigen centrality minus each node eign centrality) divided makes no sense - it's denominator can't figure out.

my code in python far accounts other 3 types, have no idea code doing (the above). part of code can't figure out indicated. appreciated.

def getcentrality(centrality, c_type):      c_denominator = float(1)      n_val = float(len(centrality))      print (str(len(centrality)) + "," +  c_type + "\n")      if (c_type=="degree"):         c_denominator = (n_val-1)*(n_val-2)      if (c_type=="close"):         c_top = (n_val-1)*(n_val-2)         c_bottom = (2*n_val)-3           c_denominator = float(c_top/c_bottom)      if (c_type=="between"):         c_denominator = (n_val*n_val*(n_val-2))     if (c_type=="eigen"):         c_denominator = [this part can't figure out]         c_node_max = max(centrality.values())       c_sorted = sorted(centrality.values(),reverse=true)      print "max node" + str(c_node_max) + "\n"      c_numerator = 0      value in c_sorted:          if c_type == "degree":             #remove normalisation each value             c_numerator += (c_node_max*(n_val-1) - value*(n_val-1))         else:             c_numerator += (c_node_max - value)      print ('numerator:' + str(c_numerator)  + "\n")      print ('denominator:' + str(c_denominator)  + "\n")       network_centrality = float(c_numerator/c_denominator)      if c_type == "between":         network_centrality = network_centrality * 2      return network_centrality 

(note closeness , betweenness should not normalized when inputting function)

update: following answer code has been completed , posted gist function others use

just clear, looking (i think) eigenvector centralization network. centrality node-level index , defined nodes of network (as makes sense, given measure). (as recall, freeman calls centralization "graph centrality", term "centralization" has replaced, hence possible confusion in comments.)

the theoretical maximum eigenvector centralization network of same size 1 edge between 2 nodes. in case of directed network, n - 1. in case of undirected network, sqrt(2)/2 * (n - 2). (see butts, 2016, pg. 56)

so in mind:

from math import sqrt if (c_type=="eigen"):     c_denominator = sqrt(2)/2 * (n_val - 2) 

or:

if (c_type=="eigen"):     c_denominator = n_val - 1 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -