o
    ßË·eÙ  ã                   @   s4   d dl mZmZ dgZedƒedƒddd„ƒƒZdS )	é    )Únot_implemented_forÚpy_random_stateÚaverage_clusteringé   Údirectedéè  Nc           	         s|   t | ƒ‰ d}t| ƒ}‡ ‡fdd„t|ƒD ƒD ]#}t| ||  ƒ}t |ƒdk r'qˆ |d¡\}}|| | v r9|d7 }q|| S )uË  Estimates the average clustering coefficient of G.

    The local clustering of each node in `G` is the fraction of triangles
    that actually exist over all possible triangles in its neighborhood.
    The average clustering coefficient of a graph `G` is the mean of
    local clusterings.

    This function finds an approximate average clustering coefficient
    for G by repeating `n` times (defined in `trials`) the following
    experiment: choose a node at random, choose two of its neighbors
    at random, and check if they are connected. The approximate
    coefficient is the fraction of triangles found over the number
    of trials [1]_.

    Parameters
    ----------
    G : NetworkX graph

    trials : integer
        Number of trials to perform (default 1000).

    seed : integer, random_state, or None (default)
        Indicator of random number generation state.
        See :ref:`Randomness<randomness>`.

    Returns
    -------
    c : float
        Approximated average clustering coefficient.

    Examples
    --------
    >>> from networkx.algorithms import approximation
    >>> G = nx.erdos_renyi_graph(10, 0.2, seed=10)
    >>> approximation.average_clustering(G, trials=1000, seed=10)
    0.214

    References
    ----------
    .. [1] Schank, Thomas, and Dorothea Wagner. Approximating clustering
       coefficient and transitivity. UniversitÃ¤t Karlsruhe, FakultÃ¤t fÃ¼r
       Informatik, 2004.
       https://doi.org/10.5445/IR/1000001239

    r   c                    s   g | ]
}t ˆ ¡ ˆ  ƒ‘qS © )ÚintÚrandom)Ú.0Úi©ÚnÚseedr   úo/var/www/ideatree/venv/lib/python3.10/site-packages/networkx/algorithms/approximation/clustering_coefficient.pyÚ
<listcomp>9   s    z&average_clustering.<locals>.<listcomp>r   é   )ÚlenÚlistÚrangeÚsample)	ÚGÚtrialsr   Ú	trianglesÚnodesr   ÚnbrsÚuÚvr   r   r   r      s   0€)r   N)Únetworkx.utilsr   r   Ú__all__r   r   r   r   r   Ú<module>   s
    