ó
ú£Õ\c           @   sP   d  Z  d d l m Z d d l Z d j d d g ƒ Z d g Z d d „ Z	 d S(	   s%   Node redundancy for bipartite graphs.iÿÿÿÿ(   t   combinationsNs   
s%   Jordi Torrents <jtorrents@milnou.net>s   Aric Hagberg (hagberg@lanl.gov)t   node_redundancyc   	      C   sã   | d k r |  } n  i  } xÁ | D]¹ } d } xe t |  | d ƒ D]P \ } } t t |  | ƒ t |  | ƒ @t | g ƒ ƒ d k rB | d 7} qB qB W| d k rÇ t |  | ƒ } d | | d } n d } | | | | <q" W| S(   s¢  Compute bipartite node redundancy coefficient.

    The redundancy coefficient of a node `v` is the fraction of pairs of 
    neighbors of `v` that are both linked to other nodes. In a one-mode
    projection these nodes would be linked together even if `v`  were 
    not there.
    
    .. math::

        rc(v) = \frac{|\{\{u,w\} \subseteq N(v),
        \: \exists v' \neq  v,\: (v',u) \in E\: 
        \mathrm{and}\: (v',w) \in E\}|}{ \frac{|N(v)|(|N(v)|-1)}{2}}

    where `N(v)` are the neighbors of `v` in `G`.

    Parameters
    ----------
    G : graph
        A bipartite graph

    nodes : list or iterable (optional)
        Compute redundancy for these nodes. The default is all nodes in G.

    Returns
    -------
    redundancy : dictionary
        A dictionary keyed by node with the node redundancy value.

    Examples
    --------
    >>> from networkx.algorithms import bipartite
    >>> G = nx.cycle_graph(4)
    >>> rc = bipartite.node_redundancy(G)
    >>> rc[0]
    1.0

    Compute the average redundancy for the graph:

    >>> sum(rc.values())/len(G)
    1.0

    Compute the average redundancy for a set of nodes:

    >>> nodes = [0, 2]
    >>> sum(rc[n] for n in nodes)/len(nodes)
    1.0

    References
    ----------
    .. [1] Latapy, Matthieu, ClÃ©mence Magnien, and Nathalie Del Vecchio (2008).
       Basic notions for the analysis of large two-mode networks. 
       Social Networks 30(1), 31--48.
    g        i   i    i   g       @g      ð?N(   t   NoneR    t   lent   set(	   t   Gt   nodest   rct   vt   overlapt   ut   wt   nt   norm(    (    s`   /Users/dxp/prism/prism-games/prism-examples/smgs/car/networkx/algorithms/bipartite/redundancy.pyR      s    6	 7(
   t   __doc__t	   itertoolsR    t   networkxt   nxt   joint
   __author__t   __all__R   R   (    (    (    s`   /Users/dxp/prism/prism-games/prism-examples/smgs/car/networkx/algorithms/bipartite/redundancy.pyt   <module>   s   		