ó
‡ˆ\c           @   sl   d  Z  d d l Z d d l m Z d d l m Z d d l m Z d d l	 m
 Z
 d e f d	 „  ƒ  YZ d S(
   sY   
Feature agglomeration. Base classes and functions for performing feature
agglomeration.
iÿÿÿÿNi   (   t   TransformerMixin(   t   check_array(   t   check_is_fitted(   t   issparset   AgglomerationTransformc           B   s)   e  Z d  Z e j Z d „  Z d „  Z RS(   sG   
    A class for feature agglomeration via the transform interface
    c      	   C   sA  t  |  d ƒ |  j } t | ƒ } t |  j ƒ | j d k rM t d ƒ ‚ n  | t j k rÖ t	 | ƒ rÖ t j
 |  j ƒ } | j d } t j g  t | ƒ D]/ } t j
 |  j | | d d … f ƒ | ^ q› ƒ } ng g  } xL t j |  j ƒ D]8 } | j | | d d … |  j | k f d d ƒƒ qï Wt j | ƒ j } | S(   sÎ  
        Transform a new matrix using the built clustering

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

        Returns
        -------
        Y : array, shape = [n_samples, n_clusters] or [n_clusters]
            The pooled values for each feature cluster.
        t   labels_i   s9   X has a different number of features than during fitting.i    Nt   axis(   R   t   pooling_funcR   t   lenR   t   shapet
   ValueErrort   npt   meanR   t   bincountt   arrayt   ranget   uniquet   appendt   T(   t   selft   XR   t   sizet	   n_samplest   it   nXt   l(    (    sE   lib/python2.7/site-packages/sklearn/cluster/_feature_agglomeration.pyt	   transform   s    		E6c         C   s9   t  |  d ƒ t j |  j d t ƒ\ } } | d | f S(   s'  
        Inverse the transformation.
        Return a vector of size nb_features with the values of Xred assigned
        to each group of features

        Parameters
        ----------
        Xred : array-like, shape=[n_samples, n_clusters] or [n_clusters,]
            The values to be assigned to each cluster of samples

        Returns
        -------
        X : array, 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.
        R   t   return_inverse.(   R   R   R   R   t   True(   R   t   Xredt   unilt   inverse(    (    sE   lib/python2.7/site-packages/sklearn/cluster/_feature_agglomeration.pyt   inverse_transform=   s    (   t   __name__t
   __module__t   __doc__R   R   R   R   R    (    (    (    sE   lib/python2.7/site-packages/sklearn/cluster/_feature_agglomeration.pyR      s   		#(   R#   t   numpyR   t   baseR    t   utilsR   t   utils.validationR   t   scipy.sparseR   R   (    (    (    sE   lib/python2.7/site-packages/sklearn/cluster/_feature_agglomeration.pyt   <module>   s   