3
Md                 @   s    d Z ddlZdgZdddZdS )z
Spectral bipartivity measure.
    Nspectral_bipartivityweightc             C   s   yddl }W n. tk
r: } ztdd|W Y dd}~X nX t| }tj| ||d}|jj|}|jj| }d||  }	|dkr|	j j |j j  S t	t
|tt|}
i }x0|D ](}|
| }|	||f |||f  ||< qW |S dS )u9  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)
    r   Nz'spectral_bipartivity() requires SciPy: zhttp://scipy.org/)r   g      ?)Zscipy.linalgImportErrorlistnxZto_numpy_arrayZlinalgZexpmZdiagonalsumdictziprangelen)GZnodesr   ZscipyeZnodelistAZexpAZexpmAZcoshAindexZsbni r   X/var/www/html/virt/lib/python3.6/site-packages/networkx/algorithms/bipartite/spectral.pyr   	   s&    )
 )Nr   )__doc__Znetworkxr   __all__r   r   r   r   r   <module>   s   