
    h/                     F    S SK Jr  S SKrS/r\R
                  SS j5       rg)    )combinationsN
dispersionc                 |  ^^^^ UUUU4S jnUcj  Uc6  U  Vs0 s H  o0 _M     n	nU  H  nX    H  nU" XU5      X   U'   M     M     U	$ [         R                  X   0 5      n	X    H  nU" XU5      X'   M      U	$ Uc0  [         R                  X   0 5      n	X    H  nU" XU5      X'   M     U	$ U" XU5      n	U	$ s  snf )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                 j  > [        X   5      nX    Vs1 s H  oDU;   d  M
  UiM     nnX1n[        US5      nSnU HA  u  pUR                  X	   5      U-
  nX;  d  M"  UR                  X
   5      (       d  M<  US-  nMC     [	        U5      nUnT(       a  UT-   T-  nUT-   S:w  a  XT-   -  nU$ s  snf )z=dispersion for all nodes 'v' in a ego network G_u of node 'u'   r      )setr   intersection
isdisjointlen)G_uuvu_nbrsnSTset_uvpossibtotalstnbrs_sembeddednessdispersion_valalphabc
normalizeds                 [/var/www/html/env/lib/python3.13/site-packages/networkx/algorithms/centrality/dispersion.py_dispersiondispersion.<locals>._dispersion9   s    SV/A;a/b!$DA((069F$$SV,,QJE  2w#aiE1Na1$"22/ 0s
   	B0B0)dictfromkeys)
Gr   r   r   r   r   r   r    r   resultss
      ````   r   r   r      s    b 8 	y9&'(a"uaG(A$/a$8GJqM  $ N mmAD"-GT(q1
  N 9mmAD"-GT(q1
  N "!*GN' )s   B9)NNTg      ?        r&   )	itertoolsr   networkxnx__all___dispatchabler        r   <module>r.      s.    " . b br-   