o
    tBhW	                     @   sD   d Z ddlZddlmZ ddlmZ ddlmZ G dd deZ	dS )	zY
Feature agglomeration. Base classes and functions for performing feature
agglomeration.
    N   )TransformerMixin)check_is_fitted)issparsec                   @   s    e Zd ZdZdd Zdd ZdS )AgglomerationTransformzH
    A class for feature agglomeration via the transform interface.
    c                    s   t  j dd jtjkr2t s2tj jd }t	 fddt
|D }|S  fddtjD }t	|j}|S )a  
        Transform a new matrix using the built clustering.

        Parameters
        ----------
        X : array-like of shape (n_samples, n_features) or                 (n_samples, n_samples)
            A M by N array of M observations in N dimensions or a length
            M array of M one-dimensional observations.

        Returns
        -------
        Y : ndarray of shape (n_samples, n_clusters) or (n_clusters,)
            The pooled values for each feature cluster.
        F)resetr   c              	      s*   g | ]}t j |d d f  qS )N)npbincountlabels_).0iXselfsize }/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/sklearn/cluster/_feature_agglomeration.py
<listcomp>/   s   * z4AgglomerationTransform.transform.<locals>.<listcomp>c                    s,   g | ]}j  d d j|kf ddqS )N   )axis)pooling_funcr
   )r   l)r   r   r   r   r   2   s    )r   _validate_datar   r   meanr   r	   r
   shapearrayrangeuniqueT)r   r   	n_samplesnXr   r   r   	transform   s   
	
z AgglomerationTransform.transformc                 C   s(   t |  tj| jdd\}}|d|f S )a  
        Inverse the transformation and return a vector of size `n_features`.

        Parameters
        ----------
        Xred : array-like of shape (n_samples, n_clusters) or (n_clusters,)
            The values to be assigned to each cluster of samples.

        Returns
        -------
        X : ndarray of shape (n_samples, n_features) or (n_features,)
            A vector of size `n_samples` with the values of `Xred` assigned to
            each of the cluster of samples.
        T)return_inverse.)r   r   r   r
   )r   Xredunilinverser   r   r   inverse_transform9   s   z(AgglomerationTransform.inverse_transformN)__name__
__module____qualname____doc__r!   r&   r   r   r   r   r      s    "r   )
r*   numpyr   baser   utils.validationr   scipy.sparser   r   r   r   r   r   <module>   s    