ó
 ,µ[c           @   sN   d  Z  d d l m Z d d l m Z d d l Z d g Z d d d „ Z	 d S(   s;   Functions for computing the harmonic centrality of a graph.iÿÿÿÿ(   t   division(   t   partialNt   harmonic_centralityc            sP   |  j  ƒ  r |  j ƒ  }  n  t t j |  d | ƒ‰  ‡  f d †  |  j | ƒ Dƒ S(   sˆ  Compute harmonic centrality for nodes.

    Harmonic centrality [1]_ of a node `u` is the sum of the reciprocal
    of the shortest path distances from all other nodes to `u`

    .. math::

        C(u) = \sum_{v \neq u} \frac{1}{d(v, u)}

    where `d(v, u)` is the shortest-path distance between `v` and `u`.

    Notice that higher values indicate higher centrality.

    Parameters
    ----------
    G : graph
      A NetworkX graph

    nbunch : container
      Container of nodes. If provided harmonic centrality will be computed
      only over the nodes in nbunch.

    distance : edge attribute key, optional (default=None)
      Use the specified edge attribute as the edge distance in shortest
      path calculations.  If `None`, then each edge will have distance equal to 1.

    Returns
    -------
    nodes : dictionary
      Dictionary of nodes with harmonic centrality as the value.

    See Also
    --------
    betweenness_centrality, load_centrality, eigenvector_centrality,
    degree_centrality, closeness_centrality

    Notes
    -----
    If the 'distance' keyword is set to an edge attribute key then the
    shortest-path length will be computed using Dijkstra's algorithm with
    that edge attribute as the edge weight.

    References
    ----------
    .. [1] Boldi, Paolo, and Sebastiano Vigna. "Axioms for centrality."
           Internet Mathematics 10.3-4 (2014): 222-262.
    t   weightc            s8   i  |  ]. } t  d  „  ˆ  d | ƒ j ƒ  Dƒ ƒ | “ q S(   c         s   s1   |  ]' \ } } | d  k r% d | n d  Vq d S(   i    i   N(    (   t   .0t   vt   d(    (    sF   lib/python2.7/site-packages/networkx/algorithms/centrality/harmonic.pys	   <genexpr>D   s    t   source(   t   sumt   items(   R   t   u(   t   spl(    sF   lib/python2.7/site-packages/networkx/algorithms/centrality/harmonic.pys
   <dictcomp>D   s   	(   t   is_directedt   reverseR   t   nxt   shortest_path_lengtht   nbunch_iter(   t   Gt   nbuncht   distance(    (   R   sF   lib/python2.7/site-packages/networkx/algorithms/centrality/harmonic.pyR      s
    0(
   t   __doc__t
   __future__R    t	   functoolsR   t   networkxR   t   __all__t   NoneR   (    (    (    sF   lib/python2.7/site-packages/networkx/algorithms/centrality/harmonic.pyt   <module>   s
   	