
    \Mh/                     B    d dl mZ d dlZdgZej        dd            ZdS )	    )combinationsN
dispersionT      ?        c                    fd}|r|3d | D             }| D ]#}| |         D ]} || ||          ||         |<   $nt                               | |         i           }| |         D ]} || ||          ||<   nL|=t                               | |         i           }| |         D ]} || ||          ||<   n || ||          }|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                 t   t          | |                   fd| |         D             }||h}t          |d          }d}|D ]G\  }}                    | |                   |z
  }	||	vr |	                    | |                   r|dz  }Ht	          |          }
|}r|z   z  }|
z   dk    r||
z   z  }|S )z=dispersion for all nodes 'v' in a ego network G_u of node 'u'c                     h | ]}|v |	S  r
   ).0nu_nbrss     i/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/networkx/algorithms/centrality/dispersion.py	<setcomp>z2dispersion.<locals>._dispersion.<locals>.<setcomp><   s    ///A1;;a;;;       r      )setr   intersection
isdisjointlen)G_uuvSTset_uvpossibtotalstnbrs_sembeddednessdispersion_valr   alphabc
normalizeds               @r   _dispersionzdispersion.<locals>._dispersion9   s    SV////Q///Qb!$$ 	 	DAq((Q0069F$$SV,, QJE2ww 	3#aiE1Na1$$,"22r   Nc                     i | ]}|i S r
   r
   )r   r   s     r   
<dictcomp>zdispersion.<locals>.<dictcomp>X   s    (((q"(((r   )dictfromkeys)	Gr   r   r&   r#   r$   r%   r'   resultss	      ````  r   r   r      sJ   b       8 	y9((a(((G 9 91 9 9A$/K1a$8$8GAJqMM99
 mmAaD"--GqT 2 2([Aq11

2 9mmAaD"--GqT 2 2([Aq11

2 "k!Q**GNr   )NNTr   r   r   )	itertoolsr   networkxnx__all___dispatchabler   r
   r   r   <module>r3      s^    " " " " " "    . b b b b b br   