def betweenness_centrality(G, nodes):
 top = set(nodes)
 bottom = (set(G) - top)
 n = float(len(top))
 m = float(len(bottom))
 s = ((n - 1) // m)
 t = ((n - 1) % m)
 bet_max_top = (((((m ** 2) * ((s + 1) ** 2)) + ((m * (s + 1)) * (((2 * t) - s) - 1))) - (t * (((2 * s) - t) + 3))) / 2.0)
 p = ((m - 1) // n)
 r = ((m - 1) % n)
 bet_max_bot = (((((n ** 2) * ((p + 1) ** 2)) + ((n * (p + 1)) * (((2 * r) - p) - 1))) - (r * (((2 * p) - r) + 3))) / 2.0)
 betweenness = nx.betweenness_centrality(G, normalized=False, weight=None)
 for node in top:
  betweenness[node] /= bet_max_top
 for node in bottom:
  betweenness[node] /= bet_max_bot
 return betweenness

def betweenness_centrality ( G , nodes ) : top = set ( nodes ) bottom = ( set ( G ) - top ) n = float ( len ( top ) ) m = float ( len ( bottom ) ) s = ( ( n - 1 ) // m ) t = ( ( n - 1 ) % m ) bet_max_top = ( ( ( ( ( m ** 2 ) * ( ( s + 1 ) ** 2 ) ) + ( ( m * ( s + 1 ) ) * ( ( ( 2 * t ) - s ) - 1 ) ) ) - ( t * ( ( ( 2 * s ) - t ) + 3 ) ) ) / 2.0 ) p = ( ( m - 1 ) // n ) r = ( ( m - 1 ) % n ) bet_max_bot = ( ( ( ( ( n ** 2 ) * ( ( p + 1 ) ** 2 ) ) + ( ( n * ( p + 1 ) ) * ( ( ( 2 * r ) - p ) - 1 ) ) ) - ( r * ( ( ( 2 * p ) - r ) + 3 ) ) ) / 2.0 ) betweenness = nx . betweenness_centrality ( G , normalized = False , weight = None ) for node in top : betweenness [ node ] /= bet_max_top for node in bottom : betweenness [ node ] /= bet_max_bot return betweenness
compute the shortest-path betweenness centrality for nodes .