calculate indegree centralization of graph with python networkx -
i have graph , want calculate indegree , outdegree centralization. tried using python networkx, there can find method calculate indegree , outdegree centrality each node. there way calculate in- , outdegree centralization of graph in networkx?
here's code. i'm assuming in-degree centralization defined describe below...
n=g.order() indegrees = g.in_degree().values() max_in = max(indegrees) centralization = float((n*max_in - sum(indegrees)))/(n-1)**2 note i've written assumption it's python 2, not 3. i've used float in division. can adapt needed.
begin definition
given network g, define let y node largest in-degree, , use d_i(u) denote in-degree of node u. define h_g (i don't know better way write mathematical formulae on stackoverflow - appreciate knows either edit or give comment)
h_g = \sum_{u} d_i(y) - d_i(u) = n d_i(u) - \sum_u d_i(u) where u iterates on nodes in g , n number of nodes of g.
the maximum possible value graph on n nodes comes when there single node other nodes point , no other nodes have edges them. h_g (n-1)^2.
so given network, define centralization it's value of h_g compared maximum. c(g) = h_g/ (n-1)^2.
end definition
Comments
Post a Comment