ó
ú£Õ\c           @   sR   d  d l  Z d j d d g ƒ Z d g Z d d d „ Z d d d d d „ Z d S(	   iÿÿÿÿNs   
s%   Jordi Torrents <jtorrents@milnou.net>s   Aric Hagberg (hagberg@lanl.gov)t   average_neighbor_degreec            s½   i  } x° | | d ˆ ƒj  ƒ  D]– \ ‰ } | d k r@ d } n  | ˆ  ˆ ƒ } ˆ d  k r t | j ƒ  ƒ t | ƒ | ˆ <q t ‡  ‡ ‡ f d †  | j  ƒ  Dƒ ƒ t | ƒ | ˆ <q W| S(   Nt   weighti    i   c         3   s3   |  ]) \ } } ˆ  ˆ | j  ˆ d  ƒ | Vq d S(   i   N(   t   get(   t   .0t   nbrt   d(   t   Gt   nR   (    si   /Users/dxp/prism/prism-games/prism-examples/smgs/car/networkx/algorithms/assortativity/neighbor_degree.pys	   <genexpr>   s   (   t   itemst   Nonet   sumt   valuest   float(   R   t   source_degreet   target_degreet   nodesR   t   avgt   degt   nbrdeg(    (   R   R   R   si   /Users/dxp/prism/prism-games/prism-examples/smgs/car/networkx/algorithms/assortativity/neighbor_degree.pyt   _average_nbr_deg   s    %	#%t   outc         C   sk   |  j  } |  j  } |  j ƒ  rO i |  j d 6|  j d 6} | | } | | } n  t |  | | d | d | ƒS(   sé  Returns the average degree of the neighborhood of each node.

    The average degree of a node `i` is

    .. math::

        k_{nn,i} = \frac{1}{|N(i)|} \sum_{j \in N(i)} k_j

    where `N(i)` are the neighbors of node `i` and `k_j` is
    the degree of node `j` which belongs to `N(i)`. For weighted 
    graphs, an analogous measure can be defined [1]_,

    .. math::

        k_{nn,i}^{w} = \frac{1}{s_i} \sum_{j \in N(i)} w_{ij} k_j

    where `s_i` is the weighted degree of node `i`, `w_{ij}`
    is the weight of the edge that links `i` and `j` and
    `N(i)` are the neighbors of node `i`.


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

    source : string ("in"|"out")
       Directed graphs only.
       Use "in"- or "out"-degree for source node.  

    target : string ("in"|"out")
       Directed graphs only.
       Use "in"- or "out"-degree for target node.

    nodes : list or iterable, optional 
        Compute neighbor degree for specified nodes.  The default is
        all nodes in the graph.


    weight : string or None, optional (default=None)
       The edge attribute that holds the numerical value used as a weight.
       If None, then each edge has weight 1.

    Returns
    -------
    d: dict
       A dictionary keyed by node with average neighbors degree value.

    Examples
    --------
    >>> G=nx.path_graph(4)
    >>> G.edge[0][1]['weight'] = 5
    >>> G.edge[2][3]['weight'] = 3

    >>> nx.average_neighbor_degree(G)
    {0: 2.0, 1: 1.5, 2: 1.5, 3: 2.0}
    >>> nx.average_neighbor_degree(G, weight='weight')
    {0: 2.0, 1: 1.1666666666666667, 2: 1.25, 3: 2.0}

    >>> G=nx.DiGraph()
    >>> G.add_path([0,1,2,3])
    >>> nx.average_neighbor_degree(G, source='in', target='in')
    {0: 1.0, 1: 1.0, 2: 1.0, 3: 0.0}

    >>> nx.average_neighbor_degree(G, source='out', target='out')
    {0: 1.0, 1: 1.0, 2: 0.0, 3: 0.0}
 
    Notes
    -----
    For directed graphs you can also specify in-degree or out-degree 
    by passing keyword arguments.

    See Also
    --------
    average_degree_connectivity 
    
    References
    ----------    
    .. [1] A. Barrat, M. BarthÃ©lemy, R. Pastor-Satorras, and A. Vespignani, 
       "The architecture of complex weighted networks". 
       PNAS 101 (11): 3747â€“3752 (2004).
    R   t   inR   R   (   t   degreet   is_directedt
   out_degreet	   in_degreeR   (   R   t   sourcet   targetR   R   R   R   t	   direction(    (    si   /Users/dxp/prism/prism-games/prism-examples/smgs/car/networkx/algorithms/assortativity/neighbor_degree.pyR       s    S		
(   t   networkxt   nxt   joint
   __author__t   __all__R	   R   R    (    (    (    si   /Users/dxp/prism/prism-games/prism-examples/smgs/car/networkx/algorithms/assortativity/neighbor_degree.pyt   <module>   s   		