
\c           @   so  d  Z  d d l m Z m Z d d l m Z d d l Z d d l Z d d l	 m
 Z
 m Z d d l m Z m Z m Z d d l m Z d d	 l m Z d d
 l m Z d d l m Z d   Z d e d d5  f d     YZ d e j e  f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ  d e  f d     YZ! d  e  f d!     YZ" d" e f d#     YZ# d$ e e f d%     YZ$ d& e e f d'     YZ% d( e e e f d)     YZ& d* e& f d+     YZ' d, e e e f d-     YZ( d. e e e f d/     YZ) d0 e f d1     YZ* d6 d2  Z+ d3 e f d4     YZ, d S(7   s  Kernels for Gaussian process regression and classification.

The kernels in this module allow kernel-engineering, i.e., they can be
combined via the "+" and "*" operators or be exponentiated with a scalar
via "**". These sum and product expressions can also contain scalar values,
which are automatically converted to a constant kernel.

All kernels allow (analytic) gradient-based hyperparameter optimization.
The space of hyperparameters can be specified by giving lower und upper
boundaries for the value of each hyperparameter (the search space is thus
rectangular). Instead of specifying bounds, hyperparameters can also be
declared to be "fixed", which causes these hyperparameters to be excluded from
optimization.
i(   t   ABCMetat   abstractmethod(   t
   namedtupleN(   t   kvt   gamma(   t   pdistt   cdistt
   squareformi   (   t   pairwise_kernels(   t   six(   t   clone(   t	   signaturec         C   s   t  j |  j t  } t  j |  d k r< t d   n  t  j |  d k r |  j d | j d k r t d | j d |  j d f   n  | S(   Ni   s2   length_scale cannot be of dimension greater than 1i    sK   Anisotropic kernel must have the same number of dimensions as data (%d!=%d)(   t   npt   squeezet   astypet   floatt   ndimt
   ValueErrort   shape(   t   Xt   length_scale(    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyt   _check_length_scale$   s    /!t   Hyperparametert   namet
   value_typet   boundst
   n_elementst   fixedc           B   s,   e  Z d  Z d Z d d d  Z d   Z RS(   s  A kernel hyperparameter's specification in form of a namedtuple.

    .. versionadded:: 0.18

    Attributes
    ----------
    name : string
        The name of the hyperparameter. Note that a kernel using a
        hyperparameter with name "x" must have the attributes self.x and
        self.x_bounds

    value_type : string
        The type of the hyperparameter. Currently, only "numeric"
        hyperparameters are supported.

    bounds : pair of floats >= 0 or "fixed"
        The lower and upper bound on the parameter. If n_elements>1, a pair
        of 1d array with n_elements each may be given alternatively. If
        the string "fixed" is passed as bounds, the hyperparameter's value
        cannot be changed.

    n_elements : int, default=1
        The number of elements of the hyperparameter value. Defaults to 1,
        which corresponds to a scalar hyperparameter. n_elements > 1
        corresponds to a hyperparameter which is vector-valued,
        such as, e.g., anisotropic length-scales.

    fixed : bool, default: None
        Whether the value of this hyperparameter is fixed, i.e., cannot be
        changed during hyperparameter tuning. If None is passed, the "fixed" is
        derived based on the given bounds.

    i   c         C   s   t  | t j  s | d k r t j |  } | d k r | j d d k re t j | | d  } q | j d | k r t d | | | j d f   q q n  | d  k r t  | t j  o | d k } n  t	 t
 |   j |  | | | | |  S(   NR   i   i    s@   Bounds on %s should have either 1 or %d dimensions. Given are %d(   t
   isinstanceR	   t   string_typesR   t
   atleast_2dR   t   repeatR   t   Nonet   superR   t   __new__(   t   clsR   R   R   R   R   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyR"   ]   s    #!c         C   sa   |  j  | j  k o` |  j | j k o` t j |  j | j k  o` |  j | j k o` |  j | j k S(   N(   R   R   R   t   allR   R   R   (   t   selft   other(    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyt   __eq__o   s
    (    N(   t   __name__t
   __module__t   __doc__t	   __slots__R    R"   R'   (    (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyR   /   s   #	t   Kernelc           B   s   e  Z d  Z e d  Z d   Z d   Z e d    Z e d    Z	 e d    Z
 e
 j d    Z
 e d    Z d	   Z d
   Z d   Z d   Z d   Z d   Z d   Z e d e d   Z e d    Z e d    Z RS(   s<   Base class for all kernels.

    .. versionadded:: 0.18
    c   
      C   s	  t    } |  j } t | j d | j  } t |  } g  g  } } xp | j j   D]_ } | j | j k r | j	 d k r | j
 | j	  n  | j | j k rS | j
 | j	  qS qS Wt |  d k r t d | f   n  x$ | D] }	 t |  |	 d  | |	 <q W| S(   sk  Get parameters of this kernel.

        Parameters
        ----------
        deep : boolean, optional
            If True, will return the parameters for this estimator and
            contained subobjects that are estimators.

        Returns
        -------
        params : mapping of string to any
            Parameter names mapped to their values.
        t   deprecated_originalR%   i    s   scikit-learn kernels should always specify their parameters in the signature of their __init__ (no varargs). %s doesn't follow this convention.N(   t   dictt	   __class__t   getattrt   __init__R   t
   parameterst   valuest   kindt   VAR_KEYWORDR   t   appendt   VAR_POSITIONALt   lent   RuntimeErrorR    (
   R%   t   deept   paramsR#   t   initt	   init_signt   argst   varargst	   parametert   arg(    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyt
   get_params}   s"    		c   	      K   s   | s
 |  S|  j  d t  } x t j |  D] \ } } | j d d  } t |  d k r | \ } } | | k r t d | |  f   n  | | } | j i | | 6  q, | | k r t d | |  j j	 f   n  t
 |  | |  q, W|  S(   s:  Set the parameters of this kernel.

        The method works on simple kernels as well as on nested kernels.
        The latter have parameters of the form ``<component>__<parameter>``
        so that it's possible to update each component of a nested object.

        Returns
        -------
        self
        R:   t   __i   sm   Invalid parameter %s for kernel %s. Check the list of available parameters with `kernel.get_params().keys()`.(   RB   t   TrueR	   t	   iteritemst   splitR8   R   t
   set_paramsR/   R(   t   setattr(	   R%   R;   t   valid_paramst   keyt   valueRF   R   t   sub_namet
   sub_object(    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyRG      s"    
c         C   s   t  |   } | | _ | S(   s   Returns a clone of self with given hyperparameters theta.

        Parameters
        ----------
        theta : array, shape (n_dims,)
            The hyperparameters
        (   R
   t   theta(   R%   RN   t   cloned(    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyt   clone_with_theta   s    	c         C   s   |  j  j d S(   s>   Returns the number of non-fixed hyperparameters of the kernel.i    (   RN   R   (   R%   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyt   n_dims   s    c         C   sI   g  } x< t  |   D]. } | j d  r | j t |  |   q q W| S(   s4   Returns a list of all hyperparameter specifications.t   hyperparameter_(   t   dirt
   startswithR6   R0   (   R%   t   rt   attr(    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyt   hyperparameters   s
    c         C   s   g  } |  j    } x1 |  j D]& } | j s | j | | j  q q Wt |  d k rn t j t j |   St j	 g   Sd S(   s  Returns the (flattened, log-transformed) non-fixed hyperparameters.

        Note that theta are typically the log-transformed values of the
        kernel's hyperparameters as this representation of the search space
        is more amenable for hyperparameter search, as hyperparameters like
        length-scales naturally live on a log-scale.

        Returns
        -------
        theta : array, shape (n_dims,)
            The non-fixed, log-transformed hyperparameters of the kernel
        i    N(
   RB   RW   R   R6   R   R8   R   t   logt   hstackt   array(   R%   RN   R;   t   hyperparameter(    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyRN      s    	c         C   s   |  j    } d } x |  j D]| } | j r1 q n  | j d k rt t j | | | | j ! | | j <| | j 7} q t j | |  | | j <| d 7} q W| t |  k r t d | t |  f   n  |  j	 |   d S(   s   Sets the (flattened, log-transformed) non-fixed hyperparameters.

        Parameters
        ----------
        theta : array, shape (n_dims,)
            The non-fixed, log-transformed hyperparameters of the kernel
        i    i   sG   theta has not the correct number of entries. Should be %d; given are %dN(
   RB   RW   R   R   R   t   expR   R8   R   RG   (   R%   RN   R;   t   iR[   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyRN      s    		c         C   so   g  } x- |  j  D]" } | j s | j | j  q q Wt |  d k r^ t j t j |   St j g   Sd S(   s   Returns the log-transformed bounds on the theta.

        Returns
        -------
        bounds : array, shape (n_dims, 2)
            The log-transformed bounds on the kernel's hyperparameters theta
        i    N(	   RW   R   R6   R   R8   R   RX   t   vstackRZ   (   R%   R   R[   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyR     s    		c         C   s/   t  | t  s" t |  t |   St |  |  S(   N(   R   R,   t   Sumt   ConstantKernel(   R%   t   b(    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyt   __add__*  s    c         C   s/   t  | t  s" t t |  |   St | |   S(   N(   R   R,   R_   R`   (   R%   Ra   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyt   __radd__/  s    c         C   s/   t  | t  s" t |  t |   St |  |  S(   N(   R   R,   t   ProductR`   (   R%   Ra   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyt   __mul__4  s    c         C   s/   t  | t  s" t t |  |   St | |   S(   N(   R   R,   Rd   R`   (   R%   Ra   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyt   __rmul__9  s    c         C   s   t  |  |  S(   N(   t   Exponentiation(   R%   Ra   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyt   __pow__>  s    c         C   s   t  |   t  |  k r t S|  j   } | j   } xa t t | j    t | j     D]7 } t j | j | d   | j | d   k  r] t Sq] Wt
 S(   N(   t   typet   FalseRB   t   sett   listt   keysR   t   anyt   getR    RD   (   R%   Ra   t   params_at   params_bRJ   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyR'   A  s    /-c         C   s.   d j  |  j j d j t d j  |  j    S(   Ns   {0}({1})s   , s   {0:.3g}(   t   formatR/   R(   t   joint   mapRN   (   R%   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyt   __repr__K  s    c         C   s   d S(   s   Evaluate the kernel.N(    (   R%   R   t   Yt   eval_gradient(    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyt   __call__O  s    c         C   s   d S(   s  Returns the diagonal of the kernel k(X, X).

        The result of this method is identical to np.diag(self(X)); however,
        it can be evaluated more efficiently since only the diagonal is
        evaluated.

        Parameters
        ----------
        X : array, shape (n_samples_X, n_features)
            Left argument of the returned kernel k(X, Y)

        Returns
        -------
        K_diag : array, shape (n_samples_X,)
            Diagonal of kernel k(X, X)
        N(    (   R%   R   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyt   diagS  s    c         C   s   d S(   s*   Returns whether the kernel is stationary. N(    (   R%   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyt   is_stationaryf  s    N(   R(   R)   R*   RD   RB   RG   RP   t   propertyRQ   RW   RN   t   setterR   Rb   Rc   Re   Rf   Rh   R'   Ru   R   R    Rj   Rx   Ry   Rz   (    (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyR,   w   s(   '	%								
	t   NormalizedKernelMixinc           B   s   e  Z d  Z d   Z RS(   sS   Mixin for kernels which are normalized: k(X, X)=1.

    .. versionadded:: 0.18
    c         C   s   t  j | j d  S(   s  Returns the diagonal of the kernel k(X, X).

        The result of this method is identical to np.diag(self(X)); however,
        it can be evaluated more efficiently since only the diagonal is
        evaluated.

        Parameters
        ----------
        X : array, shape (n_samples_X, n_features)
            Left argument of the returned kernel k(X, Y)

        Returns
        -------
        K_diag : array, shape (n_samples_X,)
            Diagonal of kernel k(X, X)
        i    (   R   t   onesR   (   R%   R   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyRy   q  s    (   R(   R)   R*   Ry   (    (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyR}   k  s   t   StationaryKernelMixinc           B   s   e  Z d  Z d   Z RS(   sY   Mixin for kernels which are stationary: k(X, Y)= f(X-Y).

    .. versionadded:: 0.18
    c         C   s   t  S(   s*   Returns whether the kernel is stationary. (   RD   (   R%   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyRz     s    (   R(   R)   R*   Rz   (    (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyR     s   t   CompoundKernelc           B   s}   e  Z d  Z d   Z e d  Z e d    Z e j d    Z e d    Z	 d
 e d  Z d   Z d   Z d	   Z RS(   s   Kernel which is composed of a set of other kernels.

    .. versionadded:: 0.18

    Parameters
    ----------
    kernels : list of Kernel objects
        The other kernels
    c         C   s   | |  _  d  S(   N(   t   kernels(   R%   R   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyR1     s    c         C   s   t  d |  j  S(   sk  Get parameters of this kernel.

        Parameters
        ----------
        deep : boolean, optional
            If True, will return the parameters for this estimator and
            contained subobjects that are estimators.

        Returns
        -------
        params : mapping of string to any
            Parameter names mapped to their values.
        R   (   R.   R   (   R%   R:   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyRB     s    c         C   s&   t  j g  |  j D] } | j ^ q  S(   s  Returns the (flattened, log-transformed) non-fixed hyperparameters.

        Note that theta are typically the log-transformed values of the
        kernel's hyperparameters as this representation of the search space
        is more amenable for hyperparameter search, as hyperparameters like
        length-scales naturally live on a log-scale.

        Returns
        -------
        theta : array, shape (n_dims,)
            The non-fixed, log-transformed hyperparameters of the kernel
        (   R   RY   R   RN   (   R%   t   kernel(    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyRN     s    c         C   sL   |  j  j } x9 t |  j  D]( \ } } | | | | d | !| _ q Wd S(   s   Sets the (flattened, log-transformed) non-fixed hyperparameters.

        Parameters
        ----------
        theta : array, shape (n_dims,)
            The non-fixed, log-transformed hyperparameters of the kernel
        i   N(   t   k1RQ   t	   enumerateR   RN   (   R%   RN   t   k_dimsR]   R   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyRN     s    	c         C   s&   t  j g  |  j D] } | j ^ q  S(   s   Returns the log-transformed bounds on the theta.

        Returns
        -------
        bounds : array, shape (n_dims, 2)
            The log-transformed bounds on the kernel's hyperparameters theta
        (   R   R^   R   R   (   R%   R   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyR     s    	c   	      C   s   | r g  } g  } xP |  j  D]E } | | | |  \ } } | j |  | j | d t j f  q Wt j |  t j | d  f St j g  |  j  D] } | | | |  ^ q  Sd S(   s!  Return the kernel k(X, Y) and optionally its gradient.

        Note that this compound kernel returns the results of all simple kernel
        stacked along an additional axis.

        Parameters
        ----------
        X : array, shape (n_samples_X, n_features)
            Left argument of the returned kernel k(X, Y)

        Y : array, shape (n_samples_Y, n_features), (optional, default=None)
            Right argument of the returned kernel k(X, Y). If None, k(X, X)
            if evaluated instead.

        eval_gradient : bool (optional, default=False)
            Determines whether the gradient with respect to the kernel
            hyperparameter is determined.

        Returns
        -------
        K : array, shape (n_samples_X, n_samples_Y, n_kernels)
            Kernel k(X, Y)

        K_gradient : array, shape (n_samples_X, n_samples_X, n_dims, n_kernels)
            The gradient of the kernel k(X, X) with respect to the
            hyperparameter of the kernel. Only returned when eval_gradient
            is True.
        .i   N(   R   R6   R   t   newaxist   dstackt   concatenate(	   R%   R   Rv   Rw   t   Kt   K_gradR   t   K_singlet   K_grad_single(    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyRx     s    	c         C   s}   t  |   t  |  k s6 t |  j  t | j  k r: t St j g  t t |  j   D]  } |  j | | j | k ^ qV  S(   N(   Ri   R8   R   Rj   R   R$   t   range(   R%   Ra   R]   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyR'     s    6	c         C   s)   t  j g  |  j D] } | j   ^ q  S(   s*   Returns whether the kernel is stationary. (   R   R$   R   Rz   (   R%   R   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyRz     s    c         C   s/   t  j g  |  j D] } | j |  ^ q  j S(   s  Returns the diagonal of the kernel k(X, X).

        The result of this method is identical to np.diag(self(X)); however,
        it can be evaluated more efficiently since only the diagonal is
        evaluated.

        Parameters
        ----------
        X : array, shape (n_samples_X, n_features)
            Left argument of the returned kernel k(X, Y)

        Returns
        -------
        K_diag : array, shape (n_samples_X, n_kernels)
            Diagonal of kernel k(X, X)
        (   R   R^   R   Ry   t   T(   R%   R   R   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyRy   	  s    N(   R(   R)   R*   R1   RD   RB   R{   RN   R|   R   R    Rj   Rx   R'   Rz   Ry   (    (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyR     s   		)		t   KernelOperatorc           B   st   e  Z d  Z d   Z e d  Z e d    Z e d    Z e j	 d    Z e d    Z
 d   Z d   Z RS(	   sE   Base class for all kernel operators.

    .. versionadded:: 0.18
    c         C   s   | |  _  | |  _ d  S(   N(   R   t   k2(   R%   R   R   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyR1   #  s    	c         C   s   t  d |  j d |  j  } | r| |  j j   j   } | j d   | D  |  j j   j   } | j d   | D  n  | S(   sk  Get parameters of this kernel.

        Parameters
        ----------
        deep : boolean, optional
            If True, will return the parameters for this estimator and
            contained subobjects that are estimators.

        Returns
        -------
        params : mapping of string to any
            Parameter names mapped to their values.
        R   R   c         s   s%   |  ] \ } } d  | | f Vq d S(   t   k1__N(    (   t   .0t   kt   val(    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pys	   <genexpr>8  s    c         s   s%   |  ] \ } } d  | | f Vq d S(   t   k2__N(    (   R   R   R   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pys	   <genexpr>:  s    (   R.   R   R   RB   t   itemst   update(   R%   R:   R;   t
   deep_items(    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyRB   '  s    c         C   s   g  } x@ |  j  j D]2 } | j t d | j | j | j | j   q Wx@ |  j j D]2 } | j t d | j | j | j | j   qV W| S(   s%   Returns a list of all hyperparameter.R   R   (	   R   RW   R6   R   R   R   R   R   R   (   R%   RU   R[   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyRW   >  s    c         C   s   t  j |  j j |  j j  S(   s  Returns the (flattened, log-transformed) non-fixed hyperparameters.

        Note that theta are typically the log-transformed values of the
        kernel's hyperparameters as this representation of the search space
        is more amenable for hyperparameter search, as hyperparameters like
        length-scales naturally live on a log-scale.

        Returns
        -------
        theta : array, shape (n_dims,)
            The non-fixed, log-transformed hyperparameters of the kernel
        (   R   R6   R   RN   R   (   R%   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyRN   N  s    c         C   s0   |  j  j } | |  |  j  _ | | |  j _ d S(   s   Sets the (flattened, log-transformed) non-fixed hyperparameters.

        Parameters
        ----------
        theta : array, shape (n_dims,)
            The non-fixed, log-transformed hyperparameters of the kernel
        N(   R   RQ   RN   R   (   R%   RN   t   k1_dims(    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyRN   ^  s    	c         C   s]   |  j  j j d k r |  j j S|  j j j d k r> |  j  j St j |  j  j |  j j f  S(   s   Returns the log-transformed bounds on the theta.

        Returns
        -------
        bounds : array, shape (n_dims, 2)
            The log-transformed bounds on the kernel's hyperparameters theta
        i    (   R   R   t   sizeR   R   R^   (   R%   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyR   k  s
    	

c         C   sb   t  |   t  |  k r t S|  j | j k r@ |  j | j k pa |  j | j k oa |  j | j k S(   N(   Ri   Rj   R   R   (   R%   Ra   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyR'   z  s    $c         C   s   |  j  j   o |  j j   S(   s*   Returns whether the kernel is stationary. (   R   Rz   R   (   R%   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyRz     s    (   R(   R)   R*   R1   RD   RB   R{   RW   RN   R|   R   R'   Rz   (    (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyR     s   		R_   c           B   s/   e  Z d  Z d e d  Z d   Z d   Z RS(   sK  Sum-kernel k1 + k2 of two kernels k1 and k2.

    The resulting kernel is defined as
    k_sum(X, Y) = k1(X, Y) + k2(X, Y)

    .. versionadded:: 0.18

    Parameters
    ----------
    k1 : Kernel object
        The first base-kernel of the sum-kernel

    k2 : Kernel object
        The second base-kernel of the sum-kernel

    c         C   s   | r_ |  j  | | d t \ } } |  j | | d t \ } } | | t j | | f  f S|  j  | |  |  j | |  Sd S(   s  Return the kernel k(X, Y) and optionally its gradient.

        Parameters
        ----------
        X : array, shape (n_samples_X, n_features)
            Left argument of the returned kernel k(X, Y)

        Y : array, shape (n_samples_Y, n_features), (optional, default=None)
            Right argument of the returned kernel k(X, Y). If None, k(X, X)
            if evaluated instead.

        eval_gradient : bool (optional, default=False)
            Determines whether the gradient with respect to the kernel
            hyperparameter is determined.

        Returns
        -------
        K : array, shape (n_samples_X, n_samples_Y)
            Kernel k(X, Y)

        K_gradient : array (opt.), shape (n_samples_X, n_samples_X, n_dims)
            The gradient of the kernel k(X, X) with respect to the
            hyperparameter of the kernel. Only returned when eval_gradient
            is True.
        Rw   N(   R   RD   R   R   R   (   R%   R   Rv   Rw   t   K1t   K1_gradientt   K2t   K2_gradient(    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyRx     s
    c         C   s    |  j  j |  |  j j |  S(   s  Returns the diagonal of the kernel k(X, X).

        The result of this method is identical to np.diag(self(X)); however,
        it can be evaluated more efficiently since only the diagonal is
        evaluated.

        Parameters
        ----------
        X : array, shape (n_samples_X, n_features)
            Left argument of the returned kernel k(X, Y)

        Returns
        -------
        K_diag : array, shape (n_samples_X,)
            Diagonal of kernel k(X, X)
        (   R   Ry   R   (   R%   R   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyRy     s    c         C   s   d j  |  j |  j  S(   Ns	   {0} + {1}(   Rr   R   R   (   R%   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyRu     s    N(   R(   R)   R*   R    Rj   Rx   Ry   Ru   (    (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyR_     s   !	Rd   c           B   s/   e  Z d  Z d e d  Z d   Z d   Z RS(   sX  Product-kernel k1 * k2 of two kernels k1 and k2.

    The resulting kernel is defined as
    k_prod(X, Y) = k1(X, Y) * k2(X, Y)

    .. versionadded:: 0.18

    Parameters
    ----------
    k1 : Kernel object
        The first base-kernel of the product-kernel

    k2 : Kernel object
        The second base-kernel of the product-kernel

    c         C   s   | r |  j  | | d t \ } } |  j | | d t \ } } | | t j | | d d  d d  t j f | | d d  d d  t j f f  f S|  j  | |  |  j | |  Sd S(   s  Return the kernel k(X, Y) and optionally its gradient.

        Parameters
        ----------
        X : array, shape (n_samples_X, n_features)
            Left argument of the returned kernel k(X, Y)

        Y : array, shape (n_samples_Y, n_features), (optional, default=None)
            Right argument of the returned kernel k(X, Y). If None, k(X, X)
            if evaluated instead.

        eval_gradient : bool (optional, default=False)
            Determines whether the gradient with respect to the kernel
            hyperparameter is determined.

        Returns
        -------
        K : array, shape (n_samples_X, n_samples_Y)
            Kernel k(X, Y)

        K_gradient : array (opt.), shape (n_samples_X, n_samples_X, n_dims)
            The gradient of the kernel k(X, X) with respect to the
            hyperparameter of the kernel. Only returned when eval_gradient
            is True.
        Rw   N(   R   RD   R   R   R   R   (   R%   R   Rv   Rw   R   R   R   R   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyRx     s    0-c         C   s    |  j  j |  |  j j |  S(   s  Returns the diagonal of the kernel k(X, X).

        The result of this method is identical to np.diag(self(X)); however,
        it can be evaluated more efficiently since only the diagonal is
        evaluated.

        Parameters
        ----------
        X : array, shape (n_samples_X, n_features)
            Left argument of the returned kernel k(X, Y)

        Returns
        -------
        K_diag : array, shape (n_samples_X,)
            Diagonal of kernel k(X, X)
        (   R   Ry   R   (   R%   R   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyRy     s    c         C   s   d j  |  j |  j  S(   Ns	   {0} * {1}(   Rr   R   R   (   R%   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyRu     s    N(   R(   R)   R*   R    Rj   Rx   Ry   Ru   (    (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyRd     s   "	Rg   c           B   s   e  Z d  Z d   Z e d  Z e d    Z e d    Z e j	 d    Z e d    Z
 d   Z d e d  Z d	   Z d
   Z d   Z RS(   s'  Exponentiate kernel by given exponent.

    The resulting kernel is defined as
    k_exp(X, Y) = k(X, Y) ** exponent

    .. versionadded:: 0.18

    Parameters
    ----------
    kernel : Kernel object
        The base kernel

    exponent : float
        The exponent for the base kernel

    c         C   s   | |  _  | |  _ d  S(   N(   R   t   exponent(   R%   R   R   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyR1   +  s    	c         C   sT   t  d |  j d |  j  } | rP |  j j   j   } | j d   | D  n  | S(   sk  Get parameters of this kernel.

        Parameters
        ----------
        deep : boolean, optional
            If True, will return the parameters for this estimator and
            contained subobjects that are estimators.

        Returns
        -------
        params : mapping of string to any
            Parameter names mapped to their values.
        R   R   c         s   s%   |  ] \ } } d  | | f Vq d S(   t   kernel__N(    (   R   R   R   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pys	   <genexpr>@  s    (   R.   R   R   RB   R   R   (   R%   R:   R;   R   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyRB   /  s
    c         C   sM   g  } x@ |  j  j D]2 } | j t d | j | j | j | j   q W| S(   s%   Returns a list of all hyperparameter.R   (   R   RW   R6   R   R   R   R   R   (   R%   RU   R[   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyRW   C  s    c         C   s
   |  j  j S(   s  Returns the (flattened, log-transformed) non-fixed hyperparameters.

        Note that theta are typically the log-transformed values of the
        kernel's hyperparameters as this representation of the search space
        is more amenable for hyperparameter search, as hyperparameters like
        length-scales naturally live on a log-scale.

        Returns
        -------
        theta : array, shape (n_dims,)
            The non-fixed, log-transformed hyperparameters of the kernel
        (   R   RN   (   R%   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyRN   N  s    c         C   s   | |  j  _ d S(   s   Sets the (flattened, log-transformed) non-fixed hyperparameters.

        Parameters
        ----------
        theta : array, shape (n_dims,)
            The non-fixed, log-transformed hyperparameters of the kernel
        N(   R   RN   (   R%   RN   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyRN   ^  s    	c         C   s
   |  j  j S(   s   Returns the log-transformed bounds on the theta.

        Returns
        -------
        bounds : array, shape (n_dims, 2)
            The log-transformed bounds on the kernel's hyperparameters theta
        (   R   R   (   R%   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyR   i  s    	c         C   s>   t  |   t  |  k r t S|  j | j k o= |  j | j k S(   N(   Ri   Rj   R   R   (   R%   Ra   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyR'   t  s    c         C   s   | rm |  j  | | d t \ } } | |  j | d d  d d  t j f |  j d 9} | |  j | f S|  j  | | d t } | |  j Sd S(   s  Return the kernel k(X, Y) and optionally its gradient.

        Parameters
        ----------
        X : array, shape (n_samples_X, n_features)
            Left argument of the returned kernel k(X, Y)

        Y : array, shape (n_samples_Y, n_features), (optional, default=None)
            Right argument of the returned kernel k(X, Y). If None, k(X, X)
            if evaluated instead.

        eval_gradient : bool (optional, default=False)
            Determines whether the gradient with respect to the kernel
            hyperparameter is determined.

        Returns
        -------
        K : array, shape (n_samples_X, n_samples_Y)
            Kernel k(X, Y)

        K_gradient : array (opt.), shape (n_samples_X, n_samples_X, n_dims)
            The gradient of the kernel k(X, X) with respect to the
            hyperparameter of the kernel. Only returned when eval_gradient
            is True.
        Rw   Ni   (   R   RD   R   R   R   Rj   (   R%   R   Rv   Rw   R   t
   K_gradient(    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyRx   y  s    5c         C   s   |  j  j |  |  j S(   s  Returns the diagonal of the kernel k(X, X).

        The result of this method is identical to np.diag(self(X)); however,
        it can be evaluated more efficiently since only the diagonal is
        evaluated.

        Parameters
        ----------
        X : array, shape (n_samples_X, n_features)
            Left argument of the returned kernel k(X, Y)

        Returns
        -------
        K_diag : array, shape (n_samples_X,)
            Diagonal of kernel k(X, X)
        (   R   Ry   R   (   R%   R   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyRy     s    c         C   s   d j  |  j |  j  S(   Ns
   {0} ** {1}(   Rr   R   R   (   R%   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyRu     s    c         C   s   |  j  j   S(   s*   Returns whether the kernel is stationary. (   R   Rz   (   R%   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyRz     s    N(   R(   R)   R*   R1   RD   RB   R{   RW   RN   R|   R   R'   R    Rj   Rx   Ry   Ru   Rz   (    (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyRg     s   		#		R`   c           B   sM   e  Z d  Z d d	 d  Z e d    Z d
 e d  Z d   Z	 d   Z
 RS(   sF  Constant kernel.

    Can be used as part of a product-kernel where it scales the magnitude of
    the other factor (kernel) or as part of a sum-kernel, where it modifies
    the mean of the Gaussian process.

    k(x_1, x_2) = constant_value for all x_1, x_2

    .. versionadded:: 0.18

    Parameters
    ----------
    constant_value : float, default: 1.0
        The constant value which defines the covariance:
        k(x_1, x_2) = constant_value

    constant_value_bounds : pair of floats >= 0, default: (1e-5, 1e5)
        The lower and upper bound on constant_value

    g      ?gh㈵>g     j@c         C   s   | |  _  | |  _ d  S(   N(   t   constant_valuet   constant_value_bounds(   R%   R   R   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyR1     s    	c         C   s   t  d d |  j  S(   NR   t   numeric(   R   R   (   R%   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyt   hyperparameter_constant_value  s    c         C   s  t  j |  } | d k r$ | } n | r9 t d   n  t  j | j d | j d f |  j d t  j |  j  j } | r |  j	 j
 s | t  j | j d | j d d f |  j d t  j |  j  j f S| t  j | j d | j d d f  f Sn | Sd S(   s  Return the kernel k(X, Y) and optionally its gradient.

        Parameters
        ----------
        X : array, shape (n_samples_X, n_features)
            Left argument of the returned kernel k(X, Y)

        Y : array, shape (n_samples_Y, n_features), (optional, default=None)
            Right argument of the returned kernel k(X, Y). If None, k(X, X)
            if evaluated instead.

        eval_gradient : bool (optional, default=False)
            Determines whether the gradient with respect to the kernel
            hyperparameter is determined. Only supported when Y is None.

        Returns
        -------
        K : array, shape (n_samples_X, n_samples_Y)
            Kernel k(X, Y)

        K_gradient : array (opt.), shape (n_samples_X, n_samples_X, n_dims)
            The gradient of the kernel k(X, X) with respect to the
            hyperparameter of the kernel. Only returned when eval_gradient
            is True.
        s.   Gradient can only be evaluated when Y is None.i    t   dtypei   N(   R   R   R    R   t   fullR   R   RZ   R   R   R   t   empty(   R%   R   Rv   Rw   R   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyRx     s    	&#	-c         C   s/   t  j | j d |  j d t  j |  j  j S(   s  Returns the diagonal of the kernel k(X, X).

        The result of this method is identical to np.diag(self(X)); however,
        it can be evaluated more efficiently since only the diagonal is
        evaluated.

        Parameters
        ----------
        X : array, shape (n_samples_X, n_features)
            Left argument of the returned kernel k(X, Y)

        Returns
        -------
        K_diag : array, shape (n_samples_X,)
            Diagonal of kernel k(X, X)
        i    R   (   R   R   R   R   RZ   R   (   R%   R   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyRy     s    c         C   s   d j  t j |  j   S(   Ns
   {0:.3g}**2(   Rr   R   t   sqrtR   (   R%   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyRu     s    (   gh㈵>g     j@N(   R(   R)   R*   R1   R{   R   R    Rj   Rx   Ry   Ru   (    (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyR`     s   ,	t   WhiteKernelc           B   sM   e  Z d  Z d d	 d  Z e d    Z d
 e d  Z d   Z	 d   Z
 RS(   s	  White kernel.

    The main use-case of this kernel is as part of a sum-kernel where it
    explains the noise-component of the signal. Tuning its parameter
    corresponds to estimating the noise-level.

    k(x_1, x_2) = noise_level if x_1 == x_2 else 0

    .. versionadded:: 0.18

    Parameters
    ----------
    noise_level : float, default: 1.0
        Parameter controlling the noise level

    noise_level_bounds : pair of floats >= 0, default: (1e-5, 1e5)
        The lower and upper bound on noise_level

    g      ?gh㈵>g     j@c         C   s   | |  _  | |  _ d  S(   N(   t   noise_levelt   noise_level_bounds(   R%   R   R   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyR1   -  s    	c         C   s   t  d d |  j  S(   NR   R   (   R   R   (   R%   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyt   hyperparameter_noise_level1  s    c         C   s  t  j |  } | d k	 r0 | r0 t d   n  | d k r |  j t  j | j d  } | r |  j j s | |  j t  j | j d  d d  d d  t  j	 f f S| t  j
 | j d | j d d f  f Sq | Sn! t  j | j d | j d f  Sd S(   s  Return the kernel k(X, Y) and optionally its gradient.

        Parameters
        ----------
        X : array, shape (n_samples_X, n_features)
            Left argument of the returned kernel k(X, Y)

        Y : array, shape (n_samples_Y, n_features), (optional, default=None)
            Right argument of the returned kernel k(X, Y). If None, k(X, X)
            if evaluated instead.

        eval_gradient : bool (optional, default=False)
            Determines whether the gradient with respect to the kernel
            hyperparameter is determined. Only supported when Y is None.

        Returns
        -------
        K : array, shape (n_samples_X, n_samples_Y)
            Kernel k(X, Y)

        K_gradient : array (opt.), shape (n_samples_X, n_samples_X, n_dims)
            The gradient of the kernel k(X, X) with respect to the
            hyperparameter of the kernel. Only returned when eval_gradient
            is True.
        s.   Gradient can only be evaluated when Y is None.i    N(   R   R   R    R   R   t   eyeR   R   R   R   R   t   zeros(   R%   R   Rv   Rw   R   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyRx   6  s    	4-c         C   s/   t  j | j d |  j d t  j |  j  j S(   s  Returns the diagonal of the kernel k(X, X).

        The result of this method is identical to np.diag(self(X)); however,
        it can be evaluated more efficiently since only the diagonal is
        evaluated.

        Parameters
        ----------
        X : array, shape (n_samples_X, n_features)
            Left argument of the returned kernel k(X, Y)

        Returns
        -------
        K_diag : array, shape (n_samples_X,)
            Diagonal of kernel k(X, X)
        i    R   (   R   R   R   R   RZ   R   (   R%   R   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyRy   a  s    c         C   s   d j  |  j j |  j  S(   Ns   {0}(noise_level={1:.3g})(   Rr   R/   R(   R   (   R%   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyRu   u  s    (   gh㈵>g     j@N(   R(   R)   R*   R1   R{   R   R    Rj   Rx   Ry   Ru   (    (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyR     s   +	t   RBFc           B   sS   e  Z d  Z d d	 d  Z e d    Z e d    Z d
 e d  Z	 d   Z
 RS(   s  Radial-basis function kernel (aka squared-exponential kernel).

    The RBF kernel is a stationary kernel. It is also known as the
    "squared exponential" kernel. It is parameterized by a length-scale
    parameter length_scale>0, which can either be a scalar (isotropic variant
    of the kernel) or a vector with the same number of dimensions as the inputs
    X (anisotropic variant of the kernel). The kernel is given by:

    k(x_i, x_j) = exp(-1 / 2 d(x_i / length_scale, x_j / length_scale)^2)

    This kernel is infinitely differentiable, which implies that GPs with this
    kernel as covariance function have mean square derivatives of all orders,
    and are thus very smooth.

    .. versionadded:: 0.18

    Parameters
    -----------
    length_scale : float or array with shape (n_features,), default: 1.0
        The length scale of the kernel. If a float, an isotropic kernel is
        used. If an array, an anisotropic kernel is used where each dimension
        of l defines the length-scale of the respective feature dimension.

    length_scale_bounds : pair of floats >= 0, default: (1e-5, 1e5)
        The lower and upper bound on length_scale

    g      ?gh㈵>g     j@c         C   s   | |  _  | |  _ d  S(   N(   R   t   length_scale_bounds(   R%   R   R   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyR1     s    	c         C   s%   t  j |  j  o$ t |  j  d k S(   Ni   (   R   t   iterableR   R8   (   R%   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyt   anisotropic  s    c         C   s;   |  j  r( t d d |  j t |  j   St d d |  j  S(   NR   R   (   R   R   R   R8   R   (   R%   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyt   hyperparameter_length_scale  s    		c         C   s  t  j |  } t | |  j  } | d k ru t | | d d } t  j d |  } t |  } t  j | d  nE | r t	 d   n  t
 | | | | d d } t  j d |  } | r|  j j r | t  j | j d | j d d f  f S|  j s| j d d k rI| t |  d d  d d  t  j f } | | f S|  j r| d d  t  j d d  f | t  j d d  d d  f d | d } | | d	 t  j f 9} | | f Sn | Sd S(
   s  Return the kernel k(X, Y) and optionally its gradient.

        Parameters
        ----------
        X : array, shape (n_samples_X, n_features)
            Left argument of the returned kernel k(X, Y)

        Y : array, shape (n_samples_Y, n_features), (optional, default=None)
            Right argument of the returned kernel k(X, Y). If None, k(X, X)
            if evaluated instead.

        eval_gradient : bool (optional, default=False)
            Determines whether the gradient with respect to the kernel
            hyperparameter is determined. Only supported when Y is None.

        Returns
        -------
        K : array, shape (n_samples_X, n_samples_Y)
            Kernel k(X, Y)

        K_gradient : array (opt.), shape (n_samples_X, n_samples_X, n_dims)
            The gradient of the kernel k(X, X) with respect to the
            hyperparameter of the kernel. Only returned when eval_gradient
            is True.
        t   metrict   sqeuclideang      i   s.   Gradient can only be evaluated when Y is None.i    Ni   .(   R   R   R   R   R    R   R\   R   t   fill_diagonalR   R   R   R   R   R   R   R   (   R%   R   Rv   Rw   R   t   distsR   R   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyRx     s2    	*,
	Cc         C   sa   |  j  r7 d j |  j j d j t d j |  j    Sd j |  j j t j |  j  d  Sd  S(   Ns   {0}(length_scale=[{1}])s   , s   {0:.3g}s   {0}(length_scale={1:.3g})i    (	   R   Rr   R/   R(   Rs   Rt   R   R   t   ravel(   R%   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyRu     s    	(   gh㈵>g     j@N(   R(   R)   R*   R1   R{   R   R   R    Rj   Rx   Ru   (    (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyR   z  s   	;t   Maternc           B   s8   e  Z d  Z d d d d  Z d	 e d  Z d   Z RS(
   s   Matern kernel.

    The class of Matern kernels is a generalization of the RBF and the
    absolute exponential kernel parameterized by an additional parameter
    nu. The smaller nu, the less smooth the approximated function is.
    For nu=inf, the kernel becomes equivalent to the RBF kernel and for nu=0.5
    to the absolute exponential kernel. Important intermediate values are
    nu=1.5 (once differentiable functions) and nu=2.5 (twice differentiable
    functions).

    See Rasmussen and Williams 2006, pp84 for details regarding the
    different variants of the Matern kernel.

    .. versionadded:: 0.18

    Parameters
    -----------
    length_scale : float or array with shape (n_features,), default: 1.0
        The length scale of the kernel. If a float, an isotropic kernel is
        used. If an array, an anisotropic kernel is used where each dimension
        of l defines the length-scale of the respective feature dimension.

    length_scale_bounds : pair of floats >= 0, default: (1e-5, 1e5)
        The lower and upper bound on length_scale

    nu : float, default: 1.5
        The parameter nu controlling the smoothness of the learned function.
        The smaller nu, the less smooth the approximated function is.
        For nu=inf, the kernel becomes equivalent to the RBF kernel and for
        nu=0.5 to the absolute exponential kernel. Important intermediate
        values are nu=1.5 (once differentiable functions) and nu=2.5
        (twice differentiable functions). Note that values of nu not in
        [0.5, 1.5, 2.5, inf] incur a considerably higher computational cost
        (appr. 10 times higher) since they require to evaluate the modified
        Bessel function. Furthermore, in contrast to l, nu is kept fixed to
        its initial value and not optimized.

    g      ?gh㈵>g     j@g      ?c         C   s&   t  t |   j | |  | |  _ d  S(   N(   R!   R   R1   t   nu(   R%   R   R   R   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyR1     s    c            sM  t  j      t    j  }  d k rF t   | d d } n2 | r[ t d   n  t   |  | d d }  j d k r t  j	 |  } n j d k r | t
 j d  } d | t  j	 |  } n  j d k r | t
 j d	  } d | | d
 d t  j	 |  } n | } | | d k c t  j t  j 7<t
 j d
  j  | } | j d
 d  j t  j   | |  j 9} | t  j |  9}  d k rt |  } t  j | d  n  | rE j j rt  j   j d   j d d f  } | | f S j ru  d d  t  j d d  f   t  j d d  d d  f d
 | d
 }	 n, t | d
  d d  d d  t  j f }	  j d k r| d t  j f |	 t  j |	 j d
   d d  d d  t  j f } d | t  j |  <n  j d k r]d |	 t  j	 t  j d |	 j d    d t  j f } n  j d k rt  j d	 |	 j d   d t  j f } d d |	 | d t  j	 |  } n.     f d   }
 | t  j |
 d  f S j s8| | d d  d d  f j d  d d  d d  t  j f f S| | f Sn | Sd S(   s  Return the kernel k(X, Y) and optionally its gradient.

        Parameters
        ----------
        X : array, shape (n_samples_X, n_features)
            Left argument of the returned kernel k(X, Y)

        Y : array, shape (n_samples_Y, n_features), (optional, default=None)
            Right argument of the returned kernel k(X, Y). If None, k(X, X)
            if evaluated instead.

        eval_gradient : bool (optional, default=False)
            Determines whether the gradient with respect to the kernel
            hyperparameter is determined. Only supported when Y is None.

        Returns
        -------
        K : array, shape (n_samples_X, n_samples_Y)
            Kernel k(X, Y)

        K_gradient : array (opt.), shape (n_samples_X, n_samples_X, n_dims)
            The gradient of the kernel k(X, X) with respect to the
            hyperparameter of the kernel. Only returned when eval_gradient
            is True.
        R   t	   euclideans.   Gradient can only be evaluated when Y is None.g      ?g      ?i   g      ?g      @i   i   g      @g        i   i    N.ig      @c            s    j  |       S(   N(   RP   (   RN   (   R   Rv   R%   (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyt   fk  s    g|=(   R   R   R   R   R    R   R   R   R   R\   t   mathR   t   finfoR   t   epst   fillR   R   R   R   R   R   R   R   R   R   t   sumt   isfinitet   _approx_fprimeRN   (   R%   R   Rv   Rw   R   R   R   t   tmpR   t   DR   (    (   R   Rv   R%   s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyRx     s`    	'"%&
	C,I>)'	Ec         C   sm   |  j  r= d j |  j j d j t d j |  j   |  j  Sd j |  j j t j	 |  j  d |  j  Sd  S(   Ns#   {0}(length_scale=[{1}], nu={2:.3g})s   , s   {0:.3g}s%   {0}(length_scale={1:.3g}, nu={2:.3g})i    (
   R   Rr   R/   R(   Rs   Rt   R   R   R   R   (   R%   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyRu   v  s    		
(   gh㈵>g     j@N(   R(   R)   R*   R1   R    Rj   Rx   Ru   (    (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyR     s
   &^t   RationalQuadraticc           B   sY   e  Z d  Z d d d	 d
 d  Z e d    Z e d    Z d e d  Z	 d   Z
 RS(   s  Rational Quadratic kernel.

    The RationalQuadratic kernel can be seen as a scale mixture (an infinite
    sum) of RBF kernels with different characteristic length-scales. It is
    parameterized by a length-scale parameter length_scale>0 and a scale
    mixture parameter alpha>0. Only the isotropic variant where length_scale is
    a scalar is supported at the moment. The kernel given by:

    k(x_i, x_j) = (1 + d(x_i, x_j)^2 / (2*alpha * length_scale^2))^-alpha

    .. versionadded:: 0.18

    Parameters
    ----------
    length_scale : float > 0, default: 1.0
        The length scale of the kernel.

    alpha : float > 0, default: 1.0
        Scale mixture parameter

    length_scale_bounds : pair of floats >= 0, default: (1e-5, 1e5)
        The lower and upper bound on length_scale

    alpha_bounds : pair of floats >= 0, default: (1e-5, 1e5)
        The lower and upper bound on alpha

    g      ?gh㈵>g     j@c         C   s(   | |  _  | |  _ | |  _ | |  _ d  S(   N(   R   t   alphaR   t   alpha_bounds(   R%   R   R   R   R   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyR1     s    			c         C   s   t  d d |  j  S(   NR   R   (   R   R   (   R%   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyR     s    c         C   s   t  d d |  j  S(   NR   R   (   R   R   (   R%   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyt   hyperparameter_alpha  s    c   
      C   s  t  j |  } | d k rz t t | d d  } | d |  j |  j d } d | } | |  j } t  j | d  nR | r t d   n  t	 | | d d } d | d |  j |  j d |  j } | r|  j
 j s| | |  j d | } | d d  d d  t  j f } n& t  j | j d | j d d f  } |  j j s| |  j t  j |  | d |  j d | }	 |	 d d  d d  t  j f }	 n& t  j | j d | j d d f  }	 | t  j |	 | f  f S| Sd S(   s  Return the kernel k(X, Y) and optionally its gradient.

        Parameters
        ----------
        X : array, shape (n_samples_X, n_features)
            Left argument of the returned kernel k(X, Y)

        Y : array, shape (n_samples_Y, n_features), (optional, default=None)
            Right argument of the returned kernel k(X, Y). If None, k(X, X)
            if evaluated instead.

        eval_gradient : bool (optional, default=False)
            Determines whether the gradient with respect to the kernel
            hyperparameter is determined. Only supported when Y is None.

        Returns
        -------
        K : array, shape (n_samples_X, n_samples_Y)
            Kernel k(X, Y)

        K_gradient : array (opt.), shape (n_samples_X, n_samples_X, n_dims)
            The gradient of the kernel k(X, X) with respect to the
            hyperparameter of the kernel. Only returned when eval_gradient
            is True.
        R   R   i   i   s.   Gradient can only be evaluated when Y is None.Ni    (   R   R   R    R   R   R   R   R   R   R   R   R   R   R   R   R   RX   R   (
   R%   R   Rv   Rw   R   R   t   baseR   t   length_scale_gradientt   alpha_gradient(    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyRx     s2    
%&%&c         C   s   d j  |  j j |  j |  j  S(   Ns(   {0}(alpha={1:.3g}, length_scale={2:.3g})(   Rr   R/   R(   R   R   (   R%   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyRu     s    (   gh㈵>g     j@(   gh㈵>g     j@N(   R(   R)   R*   R1   R{   R   R   R    Rj   Rx   Ru   (    (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyR     s   ?t   ExpSineSquaredc           B   sY   e  Z d  Z d d d	 d
 d  Z e d    Z e d    Z d e d  Z	 d   Z
 RS(   s\  Exp-Sine-Squared kernel.

    The ExpSineSquared kernel allows modeling periodic functions. It is
    parameterized by a length-scale parameter length_scale>0 and a periodicity
    parameter periodicity>0. Only the isotropic variant where l is a scalar is
    supported at the moment. The kernel given by:

    k(x_i, x_j) =
    exp(-2 (sin(\pi / periodicity * d(x_i, x_j)) / length_scale) ^ 2)

    .. versionadded:: 0.18

    Parameters
    ----------
    length_scale : float > 0, default: 1.0
        The length scale of the kernel.

    periodicity : float > 0, default: 1.0
        The periodicity of the kernel.

    length_scale_bounds : pair of floats >= 0, default: (1e-5, 1e5)
        The lower and upper bound on length_scale

    periodicity_bounds : pair of floats >= 0, default: (1e-5, 1e5)
        The lower and upper bound on periodicity

    g      ?gh㈵>g     j@c         C   s(   | |  _  | |  _ | |  _ | |  _ d  S(   N(   R   t   periodicityR   t   periodicity_bounds(   R%   R   R   R   R   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyR1     s    			c         C   s   t  d d |  j  S(   NR   R   (   R   R   (   R%   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyR     s    c         C   s   t  d d |  j  S(   NR   R   (   R   R   (   R%   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyt   hyperparameter_periodicity  s    c         C   s  t  j |  } | d k rw t t | d d  } t  j | |  j } t  j |  } t  j d | |  j	 d  } n_ | r t
 d   n  t | | d d } t  j d t  j t  j |  j |  |  j	 d  } | rt  j |  } |  j j s9d |  j	 d | d | }	 |	 d d  d d  t  j f }	 n& t  j | j d | j d	 d f  }	 |  j j sd | |  j	 d | | | }
 |
 d d  d d  t  j f }
 n& t  j | j d | j d	 d f  }
 | t  j |	 |
 f  f S| Sd S(
   s  Return the kernel k(X, Y) and optionally its gradient.

        Parameters
        ----------
        X : array, shape (n_samples_X, n_features)
            Left argument of the returned kernel k(X, Y)

        Y : array, shape (n_samples_Y, n_features), (optional, default=None)
            Right argument of the returned kernel k(X, Y). If None, k(X, X)
            if evaluated instead.

        eval_gradient : bool (optional, default=False)
            Determines whether the gradient with respect to the kernel
            hyperparameter is determined. Only supported when Y is None.

        Returns
        -------
        K : array, shape (n_samples_X, n_samples_Y)
            Kernel k(X, Y)

        K_gradient : array (opt.), shape (n_samples_X, n_samples_X, n_dims)
            The gradient of the kernel k(X, X) with respect to the
            hyperparameter of the kernel. Only returned when eval_gradient
            is True.
        R   R   ii   s.   Gradient can only be evaluated when Y is None.i   Ni    i   (   R   R   R    R   R   t   piR   t   sinR\   R   R   R   t   cosR   R   R   R   R   R   R   (   R%   R   Rv   Rw   R   RA   t
   sin_of_argR   t
   cos_of_argR   t   periodicity_gradient(    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyRx      s0    !#%&!%&c         C   s   d j  |  j j |  j |  j  S(   Ns.   {0}(length_scale={1:.3g}, periodicity={2:.3g})(   Rr   R/   R(   R   R   (   R%   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyRu   ^  s    (   gh㈵>g     j@(   gh㈵>g     j@N(   R(   R)   R*   R1   R{   R   R   R    Rj   Rx   Ru   (    (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyR     s   >t
   DotProductc           B   sV   e  Z d  Z d d
 d  Z e d    Z d e d  Z d   Z	 d   Z
 d	   Z RS(   s  Dot-Product kernel.

    The DotProduct kernel is non-stationary and can be obtained from linear
    regression by putting N(0, 1) priors on the coefficients of x_d (d = 1, . .
    . , D) and a prior of N(0, \sigma_0^2) on the bias. The DotProduct kernel
    is invariant to a rotation of the coordinates about the origin, but not
    translations. It is parameterized by a parameter sigma_0^2. For
    sigma_0^2 =0, the kernel is called the homogeneous linear kernel, otherwise
    it is inhomogeneous. The kernel is given by

    k(x_i, x_j) = sigma_0 ^ 2 + x_i \cdot x_j

    The DotProduct kernel is commonly combined with exponentiation.

    .. versionadded:: 0.18

    Parameters
    ----------
    sigma_0 : float >= 0, default: 1.0
        Parameter controlling the inhomogenity of the kernel. If sigma_0=0,
        the kernel is homogenous.

    sigma_0_bounds : pair of floats >= 0, default: (1e-5, 1e5)
        The lower and upper bound on l

    g      ?gh㈵>g     j@c         C   s   | |  _  | |  _ d  S(   N(   t   sigma_0t   sigma_0_bounds(   R%   R   R   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyR1     s    	c         C   s   t  d d |  j  S(   NR   R   (   R   R   (   R%   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyt   hyperparameter_sigma_0  s    c         C   s   t  j |  } | d k r; t  j | |  |  j d } n2 | rP t d   n  t  j | |  |  j d } | r |  j j s t  j | j	 d | j	 d d f  } d |  j d | d <| | f S| t  j | j	 d | j	 d d f  f Sn | Sd S(   s  Return the kernel k(X, Y) and optionally its gradient.

        Parameters
        ----------
        X : array, shape (n_samples_X, n_features)
            Left argument of the returned kernel k(X, Y)

        Y : array, shape (n_samples_Y, n_features), (optional, default=None)
            Right argument of the returned kernel k(X, Y). If None, k(X, X)
            if evaluated instead.

        eval_gradient : bool (optional, default=False)
            Determines whether the gradient with respect to the kernel
            hyperparameter is determined. Only supported when Y is None.

        Returns
        -------
        K : array, shape (n_samples_X, n_samples_Y)
            Kernel k(X, Y)

        K_gradient : array (opt.), shape (n_samples_X, n_samples_X, n_dims)
            The gradient of the kernel k(X, X) with respect to the
            hyperparameter of the kernel. Only returned when eval_gradient
            is True.
        i   s.   Gradient can only be evaluated when Y is None.i    i   .N(   .i    (
   R   R   R    t   innerR   R   R   R   R   R   (   R%   R   Rv   Rw   R   R   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyRx     s     &
-c         C   s   t  j d | |  |  j d S(   s  Returns the diagonal of the kernel k(X, X).

        The result of this method is identical to np.diag(self(X)); however,
        it can be evaluated more efficiently since only the diagonal is
        evaluated.

        Parameters
        ----------
        X : array, shape (n_samples_X, n_features)
            Left argument of the returned kernel k(X, Y)

        Returns
        -------
        K_diag : array, shape (n_samples_X,)
            Diagonal of kernel k(X, X)
        s   ij,ij->ii   (   R   t   einsumR   (   R%   R   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyRy     s    c         C   s   t  S(   s*   Returns whether the kernel is stationary. (   Rj   (   R%   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyRz     s    c         C   s   d j  |  j j |  j  S(   Ns   {0}(sigma_0={1:.3g})(   Rr   R/   R(   R   (   R%   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyRu     s    (   gh㈵>g     j@N(   R(   R)   R*   R1   R{   R   R    Rj   Rx   Ry   Rz   Ru   (    (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyR   c  s   -		c   	      C   s   | |  f |   } t  j | j d | j d t |   f t  } t  j t |   f t  } xt t t |    D]` } d | | <| | } | |  | f |   | | | | d  d   d  d   | f <d | | <qp W| S(   Ni    i   g      ?g        (   R   R   R   R8   R   R   (	   t   xkR   t   epsilonR>   t   f0t   gradt   eiR   t   d(    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyR     s    /

<t   PairwiseKernelc           B   s\   e  Z d  Z d d d d d  Z e d    Z d e d  Z d   Z	 d	   Z
 d
   Z RS(   s  Wrapper for kernels in sklearn.metrics.pairwise.

    A thin wrapper around the functionality of the kernels in
    sklearn.metrics.pairwise.

    Note: Evaluation of eval_gradient is not analytic but numeric and all
          kernels support only isotropic distances. The parameter gamma is
          considered to be a hyperparameter and may be optimized. The other
          kernel parameters are set directly at initialization and are kept
          fixed.

    .. versionadded:: 0.18

    Parameters
    ----------
    gamma : float >= 0, default: 1.0
        Parameter gamma of the pairwise kernel specified by metric

    gamma_bounds : pair of floats >= 0, default: (1e-5, 1e5)
        The lower and upper bound on gamma

    metric : string, or callable, default: "linear"
        The metric to use when calculating kernel between instances in a
        feature array. If metric is a string, it must be one of the metrics
        in pairwise.PAIRWISE_KERNEL_FUNCTIONS.
        If metric is "precomputed", X is assumed to be a kernel matrix.
        Alternatively, if metric is a callable function, it is called on each
        pair of instances (rows) and the resulting value recorded. The callable
        should take two arrays from X as input and return a value indicating
        the distance between them.

    pairwise_kernels_kwargs : dict, default: None
        All entries of this dict (if any) are passed as keyword arguments to
        the pairwise kernel function.

    g      ?gh㈵>g     j@t   linearc         C   s(   | |  _  | |  _ | |  _ | |  _ d  S(   N(   R   t   gamma_boundsR   t   pairwise_kernels_kwargs(   R%   R   R   R   R   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyR1     s    			c         C   s   t  d d |  j  S(   NR   R   (   R   R   (   R%   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyt   hyperparameter_gamma
  s    c      
      s    j    j  d k r! i   n  t j      t    d  j d  j d t  } | r  j j	 r | t j
   j d   j d d f  f S     f d   } | t  j | d  f Sn | Sd S(   s  Return the kernel k(X, Y) and optionally its gradient.

        Parameters
        ----------
        X : array, shape (n_samples_X, n_features)
            Left argument of the returned kernel k(X, Y)

        Y : array, shape (n_samples_Y, n_features), (optional, default=None)
            Right argument of the returned kernel k(X, Y). If None, k(X, X)
            if evaluated instead.

        eval_gradient : bool (optional, default=False)
            Determines whether the gradient with respect to the kernel
            hyperparameter is determined. Only supported when Y is None.

        Returns
        -------
        K : array, shape (n_samples_X, n_samples_Y)
            Kernel k(X, Y)

        K_gradient : array (opt.), shape (n_samples_X, n_samples_X, n_dims)
            The gradient of the kernel k(X, X) with respect to the
            hyperparameter of the kernel. Only returned when eval_gradient
            is True.
        R   R   t   filter_paramsi    c      
      s.   t     d  j d t j |   d t  S(   NR   R   R   (   R   R   R   R\   RD   (   R   (   R   Rv   R   R%   (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyR   5  s    !g|=N(   R   R    R   R   R   R   R   RD   R   R   R   R   R   RN   (   R%   R   Rv   Rw   R   R   (    (   R   Rv   R   R%   s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyRx     s    			*c         C   s   t  j |  d |  j   S(   s  Returns the diagonal of the kernel k(X, X).

        The result of this method is identical to np.diag(self(X)); however,
        it can be evaluated more efficiently since only the diagonal is
        evaluated.

        Parameters
        ----------
        X : array, shape (n_samples_X, n_features)
            Left argument of the returned kernel k(X, Y)

        Returns
        -------
        K_diag : array, shape (n_samples_X,)
            Diagonal of kernel k(X, X)
        i   (   R   t   apply_along_axisR   (   R%   R   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyRy   =  s    c         C   s   |  j  d k S(   s*   Returns whether the kernel is stationary. t   rbf(   R   (   R   (   R%   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyRz   Q  s    c         C   s   d j  |  j j |  j |  j  S(   Ns   {0}(gamma={1}, metric={2})(   Rr   R/   R(   R   R   (   R%   (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyRu   U  s    (   gh㈵>g     j@N(   R(   R)   R*   R    R1   R{   R   Rj   Rx   Ry   Rz   Ru   (    (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyR     s   $	/		(   R   R   R   R   R   (    (-   R*   t   abcR    R   t   collectionsR   R   t   numpyR   t   scipy.specialR   R   t   scipy.spatial.distanceR   R   R   t   metrics.pairwiseR   t	   externalsR	   R   R
   t   utils.fixesR   R   R   t   with_metaclassR,   t   objectR}   R   R   R   R_   Rd   Rg   R`   R   R   R   R   R   R   R   R   (    (    (    s?   lib/python2.7/site-packages/sklearn/gaussian_process/kernels.pyt   <module>   s>   		 FhJKbarpqn