ó
‡ˆ\c           @   sî   d  Z  d d l m Z m Z m Z d d l m Z m 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 d
 l m Z d d l m Z d d l m Z m Z e d d d d d d ƒ Z d e d e d „ Z d S(   s  Modified Olivetti faces dataset.

The original database was available from (now defunct)

    https://www.cl.cam.ac.uk/research/dtg/attarchive/facedatabase.html

The version retrieved here comes in MATLAB format from the personal
web page of Sam Roweis:

    https://cs.nyu.edu/~roweis/
iÿÿÿÿ(   t   dirnamet   existst   join(   t   makedirst   removeN(   t   loadmati   (   t   get_data_home(   t   _fetch_remote(   t   RemoteFileMetadata(   t   _pkl_filepathi   (   t   _joblib(   t   check_random_statet   Buncht   filenames   olivettifaces.matt   urls.   https://ndownloader.figshare.com/files/5976027t   checksumt@   b612fb967f2dc77c9c62d3e1266e0c73d5fca46a4b8906c18e454d41af987794i    c      
   C   sô  t  d |  ƒ }  t |  ƒ s( t |  ƒ n  t |  d ƒ } t | ƒ sÄ | sX t d ƒ ‚ n  d t j |  f GHt t d |  ƒ} t d | ƒ } t	 | ƒ | d j
 j ƒ  } t j | | d d	 ƒ~ n t j | ƒ } t j | ƒ } | | j ƒ  } | | j ƒ  :} | j d ƒ j d d d ƒ } t j g  t d
 ƒ D] } | d ^ q3ƒ }	 | rŠt | ƒ } | j t | ƒ ƒ }
 | |
 } |	 |
 }	 n  t t ƒ } t t | d d ƒ ƒ  } | j ƒ  } Wd QXt d | j t | ƒ d ƒ d | d |	 d | ƒ S(   sE  Load the Olivetti faces data-set from AT&T (classification).

    Download it if necessary.

    =================   =====================
    Classes                                40
    Samples total                         400
    Dimensionality                       4096
    Features            real, between 0 and 1
    =================   =====================

    Read more in the :ref:`User Guide <olivetti_faces_dataset>`.

    Parameters
    ----------
    data_home : optional, default: None
        Specify another download and cache folder for the datasets. By default
        all scikit-learn data is stored in '~/scikit_learn_data' subfolders.

    shuffle : boolean, optional
        If True the order of the dataset is shuffled to avoid having
        images of the same person grouped.

    random_state : int, RandomState instance or None (default=0)
        Determines random number generation for dataset shuffling. Pass an int
        for reproducible output across multiple function calls.
        See :term:`Glossary <random_state>`.

    download_if_missing : optional, True by default
        If False, raise a IOError if the data is not locally available
        instead of trying to download the data from the source site.

    Returns
    -------
    An object with the following attributes:

    data : numpy array of shape (400, 4096)
        Each row corresponds to a ravelled face image of original size
        64 x 64 pixels.

    images : numpy array of shape (400, 64, 64)
        Each row is a face image corresponding to one of the 40 subjects
        of the dataset.

    target : numpy array of shape (400, )
        Labels associated to each face image. Those labels are ranging from
        0-39 and correspond to the Subject IDs.

    DESCR : string
        Description of the modified Olivetti Faces Dataset.
    t	   data_homes   olivetti.pkzs1   Data not found and `download_if_missing` is Falses(   downloading Olivetti faces from %s to %sR    t	   file_namet   facest   compressi   i  i@   i    i   i   i
   t   descrs   olivetti_faces.rstNt   dataiÿÿÿÿt   imagest   targett   DESCR(   i  i@   i@   (    R   R   R   R	   t   IOErrort   FACESR   R   R   R   t   Tt   copyR
   t   dumpt   loadt   npt   float32t   mint   maxt   reshapet	   transposet   arrayt   rangeR   t   permutationt   lenR    t   __file__t   openR   t   readR   (   R   t   shufflet   random_statet   download_if_missingt   filepatht   mat_patht   mfileR   t   iR   t   ordert   module_patht   rst_filet   fdescr(    (    s>   lib/python2.7/site-packages/sklearn/datasets/olivetti_faces.pyt   fetch_olivetti_faces&   sB    5
,
(   t   __doc__t   os.pathR    R   R   t   osR   R   t   numpyR    t   scipy.io.matlabR   t   baseR   R   R   R	   t   utilsR
   R   R   R   t   Nonet   Falset   TrueR8   (    (    (    s>   lib/python2.7/site-packages/sklearn/datasets/olivetti_faces.pyt   <module>   s    		