o
    pi                     @   sB   d dl ZddlmZ d dlmZ d dlmZ 				dd	d
ZdS )    N   )pdist)
squareform)Counterdistance	euclidean  c                 C   s6  |dkr+t | |d}t||k }tj|dddk}tt| D ]
}	||	 ||	|	f< qn|dkr5d}
t|
d}
t|
|du rGtt| }nt|	d	}tt| }t|D ]3}t
|}tj| |D ]}	t|||	  }|jdd
d d ||	< qit||k}|dkr nqZtj|dd\}}|d S )a  Chinese whispers clustering

    Parameters
    ----------
    X : `np.ndarray`
        (n_samples, n_dimensions) feature vectors.
    t :
    method : `str`
        Method use to build neighboring graph. Defaults to 'distance'.
        No other method is available yet.
    metric : `str`
        The distance metric to use. See `pdist` function for a list of valid
        distance metrics. Defaults to 'euclidean'.
    max_iter : `int`
        Maximum number of iterations. Defaults to 1000.
    init : `np.ndarray`
        (n_samples, ) array. Initial cluster number.
        Defauts to each item in its own cluster.

    Returns
    -------
    T : `np.ndarray`
        (n_samples, ) array. T[i] is the cluster number to which
        original observation i belongs.

    Reference
    ---------
    Chris Biemann. "Chinese Whispers - an Efficient Graph Clustering Algorithm
    and its Application to Natural Language Processing Problems". Workshop on
    TextGraphs, at HLT-NAACL 2006.

    r   )metricr   )axisr   knnz,only 'distance' method is supported for now.N)ng-C6?T)return_inverse)r   r   npsumrangelenNotImplementedErrorarangearrayreshapecopyrandomshuffler   most_commonmeanunique)Xtmethodr	   max_iterinitr   	neighborshas_no_neighborimsgclustersindices_prev_clusterscountschanged r,   O/home/ubuntu/.local/lib/python3.10/site-packages/pyannote/core/utils/cluster.pychinese_whispers_clustering#   s8   '
r.   )r   r   r   N)	numpyr   r   r   scipy.spatial.distancer   collectionsr   r.   r,   r,   r,   r-   <module>   s   