U
    Ç-eb  ã                   @   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¾   ddl }ddl}t| ƒ}tj| ||d}|j |¡}|j | ¡}d||  }	|dkrn|	 ¡  ¡ | ¡  ¡  S t	t
|tt|ƒƒƒƒ}
i }|D ](}|
| }|	||f |||f  ||< qŒ|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   N)r   g      à?)ÚscipyZscipy.linalgÚlistÚnxZto_numpy_arrayZlinalgZexpmZdiagonalÚsumÚdictÚzipÚrangeÚlen)ÚGZnodesr   Úspr   ZnodelistÚAZexpAZexpmAZcoshAÚindexÚsbÚnÚi© r   úg/var/www/html/Darija-Ai-Train/env/lib/python3.8/site-packages/networkx/algorithms/bipartite/spectral.pyr   	   s    ))Nr   )Ú__doc__Znetworkxr   Ú__all__r   r   r   r   r   Ú<module>   s   