o
    ˷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u r7|	  |   S t	t
|tt|}
i }|D ]}|
| }|	||f |||f  ||< qF|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      ?)scipyscipy.linalglistnxto_numpy_arraylinalgexpmdiagonalsumdictziprangelen)Gnodesr   spr   nodelistAexpAexpmAcoshAindexsbni r   ]/var/www/ideatree/venv/lib/python3.10/site-packages/networkx/algorithms/bipartite/spectral.pyr   	   s   ))Nr   )__doc__networkxr   __all__r   r   r   r   r   <module>   s    