def closeness_vitality(G, node=None, weight=None, wiener_index=None):
 if (wiener_index is None):
  wiener_index = nx.wiener_index(G, weight=weight)
 if (node is not None):
  after = nx.wiener_index(G.subgraph((set(G) - {node})), weight=weight)
  return (wiener_index - after)
 vitality = partial(closeness_vitality, G, weight=weight, wiener_index=wiener_index)
 return {v: vitality(node=v) for v in G}

def closeness_vitality ( G , node = None , weight = None , wiener_index = None ) : if ( wiener_index is None ) : wiener_index = nx . wiener_index ( G , weight = weight ) if ( node is not None ) : after = nx . wiener_index ( G . subgraph ( ( set ( G ) - { node } ) ) , weight = weight ) return ( wiener_index - after ) vitality = partial ( closeness_vitality , G , weight = weight , wiener_index = wiener_index ) return { v : vitality ( node = v ) for v in G }
returns the closeness vitality for nodes in the graph .