o
    ]Zh/                     @   s.   d dl mZ d dlZdgZejdddZdS )	    )combinationsN
dispersionT      ?        c           	         s    fdd}|du rI|du r0dd | D }| D ]}| | D ]}|| |||| |< q q|S t | | i }| | D ]
}|| ||||< q<|S |du rft | | i }| | D ]
}|| ||||< qY|S || ||}|S )a  Calculate dispersion between `u` and `v` in `G`.

    A link between two actors (`u` and `v`) has a high dispersion when their
    mutual ties (`s` and `t`) are not well connected with each other.

    Parameters
    ----------
    G : graph
        A NetworkX graph.
    u : node, optional
        The source for the dispersion score (e.g. ego node of the network).
    v : node, optional
        The target of the dispersion score if specified.
    normalized : bool
        If True (default) normalize by the embeddedness of the nodes (u and v).
    alpha, b, c : float
        Parameters for the normalization procedure. When `normalized` is True,
        the dispersion value is normalized by::

            result = ((dispersion + b) ** alpha) / (embeddedness + c)

        as long as the denominator is nonzero.

    Returns
    -------
    nodes : dictionary
        If u (v) is specified, returns a dictionary of nodes with dispersion
        score for all "target" ("source") nodes. If neither u nor v is
        specified, returns a dictionary of dictionaries for all nodes 'u' in the
        graph with a dispersion score for each node 'v'.

    Notes
    -----
    This implementation follows Lars Backstrom and Jon Kleinberg [1]_. Typical
    usage would be to run dispersion on the ego network $G_u$ if $u$ were
    specified.  Running :func:`dispersion` with neither $u$ nor $v$ specified
    can take some time to complete.

    References
    ----------
    .. [1] Romantic Partnerships and the Dispersion of Social Ties:
        A Network Analysis of Relationship Status on Facebook.
        Lars Backstrom, Jon Kleinberg.
        https://arxiv.org/pdf/1310.6753v1.pdf

    c                    s   t | |   fdd| | D }||h}t|d}d}|D ]\}} | | | }	||	vr:|	| | r:|d7 }qt|}
|}rU|  }|
 dkrU||
  }|S )z=dispersion for all nodes 'v' in a ego network G_u of node 'u'c                    s   h | ]}| v r|qS  r   .0nZu_nbrsr   X/var/www/auris/lib/python3.10/site-packages/networkx/algorithms/centrality/dispersion.py	<setcomp><   s    z2dispersion.<locals>._dispersion.<locals>.<setcomp>   r      )setr   intersection
isdisjointlen)ZG_uuvZSTZset_uvZpossibtotalstZnbrs_sZembeddednessZdispersion_valalphabc
normalizedr
   r   _dispersion9   s$   
zdispersion.<locals>._dispersionNc                 S   s   i | ]}|i qS r   r   r   r   r   r   
<dictcomp>X   s    zdispersion.<locals>.<dictcomp>)dictfromkeys)	Gr   r   r   r   r   r   r   resultsr   r   r   r      s(   1)NNTr   r   r   )	itertoolsr   Znetworkxnx__all__Z_dispatchabler   r   r   r   r   <module>   s
    