ó
|£*^c           @   sF   d  d l  Z d j d d g ƒ Z d g Z e d d „ Z d „  Z d S(	   iÿÿÿÿNs   
s   Ben Edwardss   Aric Hagberg <hagberg@lanl.gov>t   rich_club_coefficientid   c         C   sØ   |  j  ƒ  s |  j ƒ  r* t d d ƒ ‚ n  t |  j ƒ  ƒ d k rT t d d ƒ ‚ n  t |  ƒ } | rÔ |  j ƒ  } | j ƒ  } t j	 | | | d | | d ƒt | ƒ } x% | D] } | | c | | :<q³ Wn  | S(   s)  Return the rich-club coefficient of the graph G.

    The rich-club coefficient is the ratio, for every degree k, of the
    number of actual to the number of potential edges for nodes 
    with degree greater than k: 

    .. math::

        \phi(k) = \frac{2 Ek}{Nk(Nk-1)}

    where Nk is the number of nodes with degree larger than k, and Ek
    be the number of edges among those nodes.

    Parameters
    ----------
    G : NetworkX graph 
    normalized : bool (optional)
       Normalize using randomized network (see [1]_)
    Q : float (optional, default=100)
       If normalized=True build a random network by performing 
       Q*M double-edge swaps, where M is the number of edges in G,
       to use as a null-model for normalization.

    Returns
    -------       
    rc : dictionary 
       A dictionary, keyed by degree, with rich club coefficient values.

    Examples
    --------
    >>> G = nx.Graph([(0,1),(0,2),(1,2),(1,3),(1,4),(4,5)])
    >>> rc = nx.rich_club_coefficient(G,normalized=False)
    >>> rc[0] # doctest: +SKIP 
    0.4

    Notes
    -----
    The rich club definition and algorithm are found in [1]_.  This
    algorithm ignores any edge weights and is not defined for directed
    graphs or graphs with parallel edges or self loops.

    Estimates for appropriate values of Q are found in [2]_.

    References
    ----------
    .. [1] Julian J. McAuley, Luciano da Fontoura Costa, and TibÃ©rio S. Caetano,
       "The rich-club phenomenon across complex network hierarchies",
       Applied Physics Letters Vol 91 Issue 8, August 2007.
       http://arxiv.org/abs/physics/0701290
    .. [2] R. Milo, N. Kashtan, S. Itzkovitz, M. E. J. Newman, U. Alon,
       "Uniform generation of random graphs with arbitrary degree 
       sequences", 2006. http://arxiv.org/abs/cond-mat/0312028
    s-   rich_club_coefficient is not implemented for s   directed or multiedge graphs.i    s   graphs with self loops.t	   max_triesi
   (
   t   is_multigrapht   is_directedt	   Exceptiont   lent   selfloop_edgest   _compute_rct   copyt   number_of_edgest   nxt   double_edge_swap(   t   Gt
   normalizedt   Qt   rct   Rt   Et   rcrant   d(    (    sp   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/algorithms/richclub.pyR       s    6"c            s;  t  j |  ƒ } t | ƒ } g  t  j j | ƒ D]  } | | d k r. | | ^ q. } |  j ƒ  ‰  t ‡  f d †  |  j ƒ  Dƒ ƒ } |  j ƒ  } | j	 d ƒ \ } } i  }	 x‹ t
 t t | ƒ ƒ | ƒ D]n \ }
 } xE | |
 k rt | ƒ d k rö Pn  | j	 d ƒ \ } } | d 8} qÔ Wd | | | d |	 |
 <qÅ W|	 S(   Ni   c         3   s/   |  ]% \ } } t  ˆ  | ˆ  | f ƒ Vq d  S(   N(   t   sorted(   t   .0t   ut   v(   t   deg(    sp   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/algorithms/richclub.pys	   <genexpr>Y   s    i    g       @(   R
   t   degree_histogramt   sumt   utilst
   accumulatet   degreeR   t
   edges_iterR	   t   popt   zipt   rangeR   (   R   t   deghistt   totalt   cst   nkst   edge_degreest   ekt   k1t   k2R   R   t   nk(    (   R   sp   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/algorithms/richclub.pyR   R   s     9"((   t   networkxR
   t   joint
   __author__t   __all__t   TrueR    R   (    (    (    sp   /home/gitlab-runner/builds/8480fa44/0/bergerc/fluidmanager-web/art-framework/bin/networkx/algorithms/richclub.pyt   <module>   s
   		J