ó
ú£Õ\c           @   s=   d  Z  d d l Z d Z d g Z d d d „ Z d „  Z d S(   s   
Spectral bipartivity measure.
iÿÿÿÿNs   Aric Hagberg (hagberg@lanl.gov)t   spectral_bipartivityt   weightc         C   s"  y d d l  } Wn  t k
 r2 t d d ƒ ‚ n X|  j ƒ  } t j |  | d | ƒ} | j j | ƒ } | j j | ƒ } d | | } | d k r¶ | j ƒ  j	 ƒ  | j ƒ  j	 ƒ  St
 t | t t | ƒ ƒ ƒ ƒ }	 i  }
 x: | D]2 } |	 | } | | | f | | | f |
 | <qä W|
 Sd S(   sC  Returns the spectral bipartivity.

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

    nodes : list or container  optional(default is all nodes)
      Nodes to return value of spectral bipartivity contribution.

    weight : string or None  optional (default = 'weight')
      Edge data key to use for edge weights. If None, weights set to 1.

    Returns
    -------
    sb : float or dict
       A single number if the keyword nodes is not specified, or
       a dictionary keyed by node with the spectral bipartivity contribution
       of that node as the value.
       
    Examples
    --------
    >>> from networkx.algorithms import bipartite
    >>> G = nx.path_graph(4)
    >>> bipartite.spectral_bipartivity(G)
    1.0

    Notes
    -----
    This implementation uses Numpy (dense) matrices which are not efficient
    for storing large sparse graphs.  

    See Also
    --------
    color

    References
    ----------
    .. [1] E. Estrada and J. A. RodrÃ­guez-VelÃ¡zquez, "Spectral measures of
       bipartivity in complex networks", PhysRev E 72, 046105 (2005)
    iÿÿÿÿNs'   spectral_bipartivity() requires SciPy: s   http://scipy.org/R   g      à?(   t   scipy.linalgt   ImportErrort   nodest   nxt   to_numpy_matrixt   linalgt   expmt   Nonet   diagonalt   sumt   dictt   zipt   ranget   len(   t   GR   R   t   scipyt   nodelistt   At   expAt   expmAt   coshAt   indext   sbt   nt   i(    (    s^   /Users/dxp/prism/prism-games/prism-examples/smgs/car/networkx/algorithms/bipartite/spectral.pyR       s$    ) !
&c         C   s`   d d l  m } y d d l } Wn | d ƒ ‚ n Xy d d l } Wn | d ƒ ‚ n Xd S(   s   Fixture for nose tests.iÿÿÿÿ(   t   SkipTestNs   NumPy not availables   SciPy not available(   t   noseR   t   numpyR   (   t   moduleR   R   R   (    (    s^   /Users/dxp/prism/prism-games/prism-examples/smgs/car/networkx/algorithms/bipartite/spectral.pyt   setup_moduleN   s    (   t   __doc__t   networkxR   t
   __author__t   __all__R	   R    R   (    (    (    s^   /Users/dxp/prism/prism-games/prism-examples/smgs/car/networkx/algorithms/bipartite/spectral.pyt   <module>   s
   	?