
    0Ph[                        d Z ddlmZ ddlmZ ddlZddlZddl	m
Z
mZmZ ddlmZmZ ddlmZmZmZmZ dd	lmZmZ dd
lmZ ddlmZ ddlmZmZ ddlm Z  ddl!m"Z"m#Z# ddl$m%Z%m&Z&m'Z' ddl$m(Z)  ej*        g d          ddej+        f         Z, ej*        g d          ddej+        f         Z- G d de          Z. G d dee          Z/dS )z"Gaussian processes classification.    )Integral)
itemgetterN)	cho_solvecholeskysolve)erfexpit   )BaseEstimatorClassifierMixin_fit_contextclone)OneVsOneClassifierOneVsRestClassifier)LabelEncoder)check_random_state)Interval
StrOptions)_check_optimize_result)check_is_fittedvalidate_data   )RBFCompoundKernelKernel)ConstantKernel)g=
ףp=?g?gGz?g)\(?g(\?)g;
!IgQfAy@g>[(dk@gK`@gvic                   V    e Zd ZdZ	 ddddddddd	Zd
 Zd Zd Z	 ddZddZ	d Z
dS )'_BinaryGaussianProcessClassifierLaplacea*  Binary Gaussian process classification based on Laplace approximation.

    The implementation is based on Algorithm 3.1, 3.2, and 5.1 from [RW2006]_.

    Internally, the Laplace approximation is used for approximating the
    non-Gaussian posterior by a Gaussian.

    Currently, the implementation is restricted to using the logistic link
    function.

    .. versionadded:: 0.18

    Parameters
    ----------
    kernel : kernel instance, default=None
        The kernel specifying the covariance function of the GP. If None is
        passed, the kernel "1.0 * RBF(1.0)" is used as default. Note that
        the kernel's hyperparameters are optimized during fitting.

    optimizer : 'fmin_l_bfgs_b' or callable, default='fmin_l_bfgs_b'
        Can either be one of the internally supported optimizers for optimizing
        the kernel's parameters, specified by a string, or an externally
        defined optimizer passed as a callable. If a callable is passed, it
        must have the  signature::

            def optimizer(obj_func, initial_theta, bounds):
                # * 'obj_func' is the objective function to be maximized, which
                #   takes the hyperparameters theta as parameter and an
                #   optional flag eval_gradient, which determines if the
                #   gradient is returned additionally to the function value
                # * 'initial_theta': the initial value for theta, which can be
                #   used by local optimizers
                # * 'bounds': the bounds on the values of theta
                ....
                # Returned are the best found hyperparameters theta and
                # the corresponding value of the target function.
                return theta_opt, func_min

        Per default, the 'L-BFGS-B' algorithm from scipy.optimize.minimize
        is used. If None is passed, the kernel's parameters are kept fixed.
        Available internal optimizers are::

            'fmin_l_bfgs_b'

    n_restarts_optimizer : int, default=0
        The number of restarts of the optimizer for finding the kernel's
        parameters which maximize the log-marginal likelihood. The first run
        of the optimizer is performed from the kernel's initial parameters,
        the remaining ones (if any) from thetas sampled log-uniform randomly
        from the space of allowed theta-values. If greater than 0, all bounds
        must be finite. Note that n_restarts_optimizer=0 implies that one
        run is performed.

    max_iter_predict : int, default=100
        The maximum number of iterations in Newton's method for approximating
        the posterior during predict. Smaller values will reduce computation
        time at the cost of worse results.

    warm_start : bool, default=False
        If warm-starts are enabled, the solution of the last Newton iteration
        on the Laplace approximation of the posterior mode is used as
        initialization for the next call of _posterior_mode(). This can speed
        up convergence when _posterior_mode is called several times on similar
        problems as in hyperparameter optimization. See :term:`the Glossary
        <warm_start>`.

    copy_X_train : bool, default=True
        If True, a persistent copy of the training data is stored in the
        object. Otherwise, just a reference to the training data is stored,
        which might cause predictions to change if the data is modified
        externally.

    random_state : int, RandomState instance or None, default=None
        Determines random number generation used to initialize the centers.
        Pass an int for reproducible results across multiple function calls.
        See :term:`Glossary <random_state>`.

    Attributes
    ----------
    X_train_ : array-like of shape (n_samples, n_features) or list of object
        Feature vectors or other representations of training data (also
        required for prediction).

    y_train_ : array-like of shape (n_samples,)
        Target values in training data (also required for prediction)

    classes_ : array-like of shape (n_classes,)
        Unique class labels.

    kernel_ : kernl instance
        The kernel used for prediction. The structure of the kernel is the
        same as the one passed as parameter but with optimized hyperparameters

    L_ : array-like of shape (n_samples, n_samples)
        Lower-triangular Cholesky decomposition of the kernel in X_train_

    pi_ : array-like of shape (n_samples,)
        The probabilities of the positive class for the training points
        X_train_

    W_sr_ : array-like of shape (n_samples,)
        Square root of W, the Hessian of log-likelihood of the latent function
        values for the observed labels. Since W is diagonal, only the diagonal
        of sqrt(W) is stored.

    log_marginal_likelihood_value_ : float
        The log-marginal-likelihood of ``self.kernel_.theta``

    References
    ----------
    .. [RW2006] `Carl E. Rasmussen and Christopher K.I. Williams,
       "Gaussian Processes for Machine Learning",
       MIT Press 2006 <https://www.gaussianprocess.org/gpml/chapters/RW.pdf>`_
    Nfmin_l_bfgs_br   d   FT)	optimizern_restarts_optimizermax_iter_predict
warm_startcopy_X_trainrandom_statec                h    || _         || _        || _        || _        || _        || _        || _        d S Nkernelr!   r"   r#   r$   r%   r&   )selfr*   r!   r"   r#   r$   r%   r&   s           ]/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/sklearn/gaussian_process/_gpc.py__init__z0_BinaryGaussianProcessClassifierLaplace.__init__   s?     "$8! 0$((    c           	           j         )t          dd          t          dd          z   _        nt	           j                    _        t           j                   _         j        rt          j
        |          n| _        t                      }|                    |           _        |j         _         j        j        dk    r#t#           j        j        d j                   j        j        dk    r7t#          d	                     j        j         j        j                             j         j        j        d
k    rd fd	}                     | j        j         j        j                  g} j        d
k    rt          j         j        j                                                  st#          d           j        j        }t;           j                  D ]m}t          j         j                            |ddd
f         |dddf                             }|                                          |||                     ntC          tE          tG          d          |                    }	|t          j$        |	                   d
          j        _         j        %                                 t          j&        |	            _'        n$ (                     j        j                   _'                              j                  }
 )                    |
d          \  }\   _*         _+         _,        }} S )a  Fit Gaussian process classification model.

        Parameters
        ----------
        X : array-like of shape (n_samples, n_features) or list of object
            Feature vectors or other representations of training data.

        y : array-like of shape (n_samples,)
            Target values, must be binary.

        Returns
        -------
        self : returns an instance of self.
        Ng      ?fixed)constant_value_bounds)length_scale_boundsr
   z9 supports only binary classification. y contains classes r   z){0:s} requires 2 classes; got {1:d} classr   Tc                 z    |r!                     | dd          \  }}| | fS                      | d           S )NTF)eval_gradientclone_kernelr5   log_marginal_likelihood)thetar4   lmlgradr+   s       r,   obj_funcz=_BinaryGaussianProcessClassifierLaplace.fit.<locals>.obj_func   s]      T $ < <T != ! !IC  4$;& 88U8SSSSr.   zYMultiple optimizer restarts (n_restarts_optimizer>0) requires that all bounds are finite.return_temporaries)T)-r*   Cr   kernel_r   r   r&   rngr%   npcopyX_train_r   fit_transformy_train_classes_size
ValueError	__class____name__formatr!   n_dims_constrained_optimizationr9   boundsr"   isfiniteallrangeexpuniformappendlistmapr   argmin_check_bounds_paramsminlog_marginal_likelihood_value_r8   _posterior_modepi_W_sr_L_)r+   Xylabel_encoderr<   optimarO   	iterationtheta_initial
lml_valuesK_s   `           r,   fitz+_BinaryGaussianProcessClassifierLaplace.fit   sP    ;S@@@3D D D DLL !--DL%d&788&*&7>


Q %%33A66%.=!!>***DMM;   ]1$$;BBN+T]-?    >%$,*=*A*AT T T T T T ..dl0$,2E F (1,,{4<#677;;== $?   ,!&t'@!A!A  I$&F48+;+;F111a4L&QRQRQRTUQU,+W+W$X$XMMM66xPVWW   
 c*Q--8899J!'	*(=(=!>q!ADLL--///356*3E3E2ED//262N2N"3 3D/ LL''373G3G$ 4H 4
 4
00DHdj$'1a r.   c                    t          |            |                     | j        |          }|j                            | j        | j        z
            }t          j        |dk    | j	        d         | j	        d                   S )a  Perform classification on an array of test vectors X.

        Parameters
        ----------
        X : array-like of shape (n_samples, n_features) or list of object
            Query points where the GP is evaluated for classification.

        Returns
        -------
        C : ndarray of shape (n_samples,)
            Predicted target values for X, values are from ``classes_``
        r   r   )
r   r@   rD   TdotrF   r]   rB   whererG   )r+   r`   K_starf_stars       r,   predictz/_BinaryGaussianProcessClassifierLaplace.predict  sk     	
 dmQ//dmdh677x
DM!$4dmA6FGGGr.   c           
      6   t          |            |                     | j        |          }|j                            | j        | j        z
            }t          | j        | j	        ddt          j        f         |z            }| j                            |          t          j        d||          z
  }dd|z  z  }t          |z  }t          j        t          j        |z            t#          |t          j        ||t          dz  z   z            z            z  dt          j        |dz  t          j        z            z  z  }t$          |z                      d          dt$                                          z  z   }	t          j        d|	z
  |	f          j        S )a  Return probability estimates for the test vector X.

        Parameters
        ----------
        X : array-like of shape (n_samples, n_features) or list of object
            Query points where the GP is evaluated for classification.

        Returns
        -------
        C : array-like of shape (n_samples, n_classes)
            Returns the probability of the samples for each class in
            the model. The columns correspond to the classes in sorted
            order, as they appear in the attribute ``classes_``.
        Nzij,ij->jr   r
   r   )axis      ?)r   r@   rD   rk   rl   rF   r]   r   r_   r^   rB   newaxisdiageinsumLAMBDASsqrtpir   COEFSsumvstack)
r+   r`   rn   ro   v
var_f_staralphagamma	integralspi_stars
             r,   predict_probaz5_BinaryGaussianProcessClassifierLaplace.predict_proba$  sa    	 dmQ//dmdh677$'4:aaam4v=>>\&&q))BIj!Q,G,GG
 Q^$& GBEEM""%"'%57A:+=">???@@A27:>BE12224 	
 9$))q)11C%))++4EEy!g+w/0022r.   c                    ||rt          d          | j        S |r| j                            |          }n| j        }||_        |r || j        d          \  }}n || j                  }|                     |d          \  }\  }}	}
}}|s|S t          j        |j	        d                   }|	ddt          j
        f         t          |
dft          j        |	                    z  }t          |
|	ddt          j
        f         |z            }dt          j        |          t          j        d||          z
  z  |d	|z
  z  d	d
|z  z
  z  z  }t          |j	        d                   D ]}|dddd|f         }d|j                            |                              |          z  d|j                                                             |j                              z  z
  } |j        | j        |z
            }||                    |                    |                    z
  }||j                            |          z   ||<   ||fS )a  Returns log-marginal likelihood of theta for training data.

        Parameters
        ----------
        theta : array-like of shape (n_kernel_params,), default=None
            Kernel hyperparameters for which the log-marginal likelihood is
            evaluated. If None, the precomputed log_marginal_likelihood
            of ``self.kernel_.theta`` is returned.

        eval_gradient : bool, default=False
            If True, the gradient of the log-marginal likelihood with respect
            to the kernel hyperparameters at position theta is returned
            additionally. If True, theta must not be None.

        clone_kernel : bool, default=True
            If True, the kernel attribute is copied. If False, the kernel
            attribute is modified, but may result in a performance improvement.

        Returns
        -------
        log_likelihood : float
            Log-marginal likelihood of theta for training data.

        log_likelihood_gradient : ndarray of shape (n_kernel_params,),                 optional
            Gradient of the log-marginal likelihood with respect to the kernel
            hyperparameters at position theta.
            Only returned when `eval_gradient` is True.
        N.Gradient can only be evaluated for theta!=NoneT)r4   r=   r         zij, ij -> jr   r
   rs   )rI   r[   r@   clone_with_thetar9   rD   r\   rB   emptyshapert   r   ru   r   rv   rR   rk   rl   ravelrF   )r+   r9   r4   r5   r*   rg   
K_gradientZry   W_srLbad_ZRr?   s_2js_1s_3s                       r,   r8   z?_BinaryGaussianProcessClassifierLaplace.log_marginal_likelihoodN  sS   @ = S !QRRR66 	!\22599FF\F FL 	&"F4=EEEMAzzt}%%A "&!5!5aD!5!Q!QBaA 	H hu{1~&&BJ)QIrwt}}"E"EE!T!!!RZ-(1,-- wqzzBImQ:::<QV}AF
+- 	 sy|$$ 	* 	*A111aaa7#A

q)))C!#))++//'!'))2L2L,LLCdmb())AaeeAEE!HHoo%C3599S>>)CFF#vr.   c           	         | j         r2t          | d          r"| j        j        | j        j        k    r| j        }n%t          j        | j        t
          j                  }t
          j         }t          | j
                  D ]x}t          |          }|d|z
  z  }t          j        |          }|ddt
          j        f         |z  }	t          j        |j        d                   |	|z  z   }
t          |
d          }||z  | j        |z
  z   }||t!          |df|	                    |                    z  z
  }|                    |          }d|j                            |          z  t          j        t          j        | j        d	z  dz
   |z                                                      z
  t          j        t          j        |                                                    z
  }||z
  d
k     r n|}z|| _        |r	||||||ffS |S )a   Mode-finding for binary Laplace GPC and fixed kernel.

        This approximates the posterior of the latent function values for given
        inputs and target observations with a Gaussian approximation and uses
        Newton's iteration to find the mode of this approximation.
        f_cached)dtyper   Nr   T)lowerr   r
   g|=)r$   hasattrr   r   rF   rB   
zeros_likefloat64infrR   r#   r	   rx   rt   eyer   r   rl   rk   log1prS   r{   logru   )r+   rg   r>   fr8   rh   ry   Wr   W_sr_KBr   r   r   r:   s                  r,   r\   z7_BinaryGaussianProcessClassifierLaplace._posterior_mode  s    O	?j))	? #t}':::AAdm2:>>>A $&6't,-- 	* 	*AqBa"fA71::D!!!RZ-(1,Fqwqz""Vd]2A$'''AA+,AD9aY

1>>>>AaA
 qswwqzz!(26DMA$5$9":Q">??@@DDFFG&$$((**+  ,,u44&)## 	+*Rq!Q,???**r.   c                 4   | j         dk    rCt          j                            ||dd|          }t	          d|           |j        |j        }}nGt          | j                   r|                      |||          \  }}nt          d| j         z            ||fS )Nr   zL-BFGS-BT)methodjacrO   lbfgs)rO   zUnknown optimizer %s.)	r!   scipyoptimizeminimizer   xfuncallablerI   )r+   r<   initial_thetarO   opt_res	theta_optfunc_mins          r,   rN   zA_BinaryGaussianProcessClassifierLaplace._constrained_optimization  s    >_,,n---
V .  G #7G444"))W[xIIdn%% 	G"&..=QW."X"XIxx4t~EFFF(""r.   r(   NFT)F)rK   
__module____qualname____doc__r-   ri   rp   r   r8   r\   rN    r.   r,   r   r   $   s        q qj ) ") ) ) ) )&` ` `DH H H.(3 (3 (3V =AM M M M^8+ 8+ 8+ 8+t# # # # #r.   r   c                   "   e Zd ZU dZedg edh          edg eeddd          g eeddd          gdgdgd	g ed
dh          gedgd	Z	e
ed<   	 dddddddd
dddZ ed          d             Zd Zd Zed             Z	 ddZdS )GaussianProcessClassifieraK  Gaussian process classification (GPC) based on Laplace approximation.

    The implementation is based on Algorithm 3.1, 3.2, and 5.1 from [RW2006]_.

    Internally, the Laplace approximation is used for approximating the
    non-Gaussian posterior by a Gaussian.

    Currently, the implementation is restricted to using the logistic link
    function. For multi-class classification, several binary one-versus rest
    classifiers are fitted. Note that this class thus does not implement
    a true multi-class Laplace approximation.

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

    .. versionadded:: 0.18

    Parameters
    ----------
    kernel : kernel instance, default=None
        The kernel specifying the covariance function of the GP. If None is
        passed, the kernel "1.0 * RBF(1.0)" is used as default. Note that
        the kernel's hyperparameters are optimized during fitting. Also kernel
        cannot be a `CompoundKernel`.

    optimizer : 'fmin_l_bfgs_b', callable or None, default='fmin_l_bfgs_b'
        Can either be one of the internally supported optimizers for optimizing
        the kernel's parameters, specified by a string, or an externally
        defined optimizer passed as a callable. If a callable is passed, it
        must have the  signature::

            def optimizer(obj_func, initial_theta, bounds):
                # * 'obj_func' is the objective function to be maximized, which
                #   takes the hyperparameters theta as parameter and an
                #   optional flag eval_gradient, which determines if the
                #   gradient is returned additionally to the function value
                # * 'initial_theta': the initial value for theta, which can be
                #   used by local optimizers
                # * 'bounds': the bounds on the values of theta
                ....
                # Returned are the best found hyperparameters theta and
                # the corresponding value of the target function.
                return theta_opt, func_min

        Per default, the 'L-BFGS-B' algorithm from scipy.optimize.minimize
        is used. If None is passed, the kernel's parameters are kept fixed.
        Available internal optimizers are::

            'fmin_l_bfgs_b'

    n_restarts_optimizer : int, default=0
        The number of restarts of the optimizer for finding the kernel's
        parameters which maximize the log-marginal likelihood. The first run
        of the optimizer is performed from the kernel's initial parameters,
        the remaining ones (if any) from thetas sampled log-uniform randomly
        from the space of allowed theta-values. If greater than 0, all bounds
        must be finite. Note that n_restarts_optimizer=0 implies that one
        run is performed.

    max_iter_predict : int, default=100
        The maximum number of iterations in Newton's method for approximating
        the posterior during predict. Smaller values will reduce computation
        time at the cost of worse results.

    warm_start : bool, default=False
        If warm-starts are enabled, the solution of the last Newton iteration
        on the Laplace approximation of the posterior mode is used as
        initialization for the next call of _posterior_mode(). This can speed
        up convergence when _posterior_mode is called several times on similar
        problems as in hyperparameter optimization. See :term:`the Glossary
        <warm_start>`.

    copy_X_train : bool, default=True
        If True, a persistent copy of the training data is stored in the
        object. Otherwise, just a reference to the training data is stored,
        which might cause predictions to change if the data is modified
        externally.

    random_state : int, RandomState instance or None, default=None
        Determines random number generation used to initialize the centers.
        Pass an int for reproducible results across multiple function calls.
        See :term:`Glossary <random_state>`.

    multi_class : {'one_vs_rest', 'one_vs_one'}, default='one_vs_rest'
        Specifies how multi-class classification problems are handled.
        Supported are 'one_vs_rest' and 'one_vs_one'. In 'one_vs_rest',
        one binary Gaussian process classifier is fitted for each class, which
        is trained to separate this class from the rest. In 'one_vs_one', one
        binary Gaussian process classifier is fitted for each pair of classes,
        which is trained to separate these two classes. The predictions of
        these binary predictors are combined into multi-class predictions.
        Note that 'one_vs_one' does not support predicting probability
        estimates.

    n_jobs : int, default=None
        The number of jobs to use for the computation: the specified
        multiclass problems are computed in parallel.
        ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.
        ``-1`` means using all processors. See :term:`Glossary <n_jobs>`
        for more details.

    Attributes
    ----------
    base_estimator_ : ``Estimator`` instance
        The estimator instance that defines the likelihood function
        using the observed data.

    kernel_ : kernel instance
        The kernel used for prediction. In case of binary classification,
        the structure of the kernel is the same as the one passed as parameter
        but with optimized hyperparameters. In case of multi-class
        classification, a CompoundKernel is returned which consists of the
        different kernels used in the one-versus-rest classifiers.

    log_marginal_likelihood_value_ : float
        The log-marginal-likelihood of ``self.kernel_.theta``

    classes_ : array-like of shape (n_classes,)
        Unique class labels.

    n_classes_ : int
        The number of classes in the training data

    n_features_in_ : int
        Number of features seen during :term:`fit`.

        .. versionadded:: 0.24

    feature_names_in_ : ndarray of shape (`n_features_in_`,)
        Names of features seen during :term:`fit`. Defined only when `X`
        has feature names that are all strings.

        .. versionadded:: 1.0

    See Also
    --------
    GaussianProcessRegressor : Gaussian process regression (GPR).

    References
    ----------
    .. [RW2006] `Carl E. Rasmussen and Christopher K.I. Williams,
       "Gaussian Processes for Machine Learning",
       MIT Press 2006 <https://www.gaussianprocess.org/gpml/chapters/RW.pdf>`_

    Examples
    --------
    >>> from sklearn.datasets import load_iris
    >>> from sklearn.gaussian_process import GaussianProcessClassifier
    >>> from sklearn.gaussian_process.kernels import RBF
    >>> X, y = load_iris(return_X_y=True)
    >>> kernel = 1.0 * RBF(1.0)
    >>> gpc = GaussianProcessClassifier(kernel=kernel,
    ...         random_state=0).fit(X, y)
    >>> gpc.score(X, y)
    0.9866...
    >>> gpc.predict_proba(X[:2,:])
    array([[0.83548752, 0.03228706, 0.13222543],
           [0.79064206, 0.06525643, 0.14410151]])

    For a comaprison of the GaussianProcessClassifier with other classifiers see:
    :ref:`sphx_glr_auto_examples_classification_plot_classification_probability.py`.
    Nr   r   left)closedr   booleanr&   one_vs_rest
one_vs_one	r*   r!   r"   r#   r$   r%   r&   multi_classn_jobs_parameter_constraintsr    FT)r!   r"   r#   r$   r%   r&   r   r   c                    || _         || _        || _        || _        || _        || _        || _        || _        |	| _        d S r(   r   )
r+   r*   r!   r"   r#   r$   r%   r&   r   r   s
             r,   r-   z"GaussianProcessClassifier.__init__  sL     "$8! 0$((&r.   )prefer_skip_nested_validationc           	         t          | j        t                    rt          d          | j        | j        j        rt          | ||ddd          \  }}nt          | ||ddd          \  }}t          | j        | j        | j        | j	        | j
        | j        | j                  | _        t          j        |          | _        | j        j        | _        | j        dk    r$t          d	| j        | j        d
         fz            | j        dk    ro| j        dk    r!t)          | j        | j                  | _        nC| j        dk    r!t-          | j        | j                  | _        nt          d| j        z            | j                            ||           | j        dk    r.t          j        d | j        j        D                       | _        n| j                                        | _        | S )a  Fit Gaussian process classification model.

        Parameters
        ----------
        X : array-like of shape (n_samples, n_features) or list of object
            Feature vectors or other representations of training data.

        y : array-like of shape (n_samples,)
            Target values, must be binary.

        Returns
        -------
        self : object
            Returns an instance of self.
        z!kernel cannot be a CompoundKernelNFTnumeric)multi_output	ensure_2dr   r)   r   zfGaussianProcessClassifier requires 2 or more distinct classes; got %d class (only class %s is present)r   r
   r   )r   r   zUnknown multi-class mode %sc                 6    g | ]}|                                 S r   r7   .0	estimators     r,   
<listcomp>z1GaussianProcessClassifier.fit.<locals>.<listcomp>  s4       ! 5577  r.   )
isinstancer*   r   rI   requires_vector_inputr   r   r!   r"   r#   r$   r%   r&   base_estimator_rB   uniquerG   rH   
n_classes_r   r   r   r   ri   meanestimators_r[   r8   )r+   r`   ra   s      r,   ri   zGaussianProcessClassifier.fit  s1   " dk>22 	B@AAA;$+"C a$i  DAqq !a%t  DAq  G;n!%!:!2** 
  
  
 	!-,?a!%$-2B CD  
 ?Q=00':(( ( ($$ !\11'9(( ( ($$ !!>AQ!QRRR  A&&&?Q24' %)%9%E  3 3D// $<<>> / r.   c                     t          |            | j        | j        j        rt          | |ddd          }nt          | |ddd          }| j                            |          S )a  Perform classification on an array of test vectors X.

        Parameters
        ----------
        X : array-like of shape (n_samples, n_features) or list of object
            Query points where the GP is evaluated for classification.

        Returns
        -------
        C : ndarray of shape (n_samples,)
            Predicted target values for X, values are from ``classes_``.
        NTr   Fr   r   reset)r   r*   r   r   r   rp   r+   r`   s     r,   rp   z!GaussianProcessClassifier.predict  sm     	;$+"CdAYeTTTAAdAd%PPPA#++A...r.   c                    t          |            | j        dk    r| j        dk    rt          d          | j        | j        j        rt          | |ddd          }nt          | |ddd          }| j                            |          S )	a  Return probability estimates for the test vector X.

        Parameters
        ----------
        X : array-like of shape (n_samples, n_features) or list of object
            Query points where the GP is evaluated for classification.

        Returns
        -------
        C : array-like of shape (n_samples, n_classes)
            Returns the probability of the samples for each class in
            the model. The columns correspond to the classes in sorted
            order, as they appear in the attribute :term:`classes_`.
        r
   r   zlone_vs_one multi-class mode does not support predicting probability estimates. Use one_vs_rest mode instead.NTr   Fr   )	r   r   r   rI   r*   r   r   r   r   r   s     r,   r   z'GaussianProcessClassifier.predict_proba  s     	?Q4#3|#C#C,   ;$+"CdAYeTTTAAdAd%PPPA#11!444r.   c                 v    | j         dk    r| j        j        S t          d | j        j        D                       S )z(Return the kernel of the base estimator.r
   c                     g | ]	}|j         
S r   )r@   r   s     r,   r   z5GaussianProcessClassifier.kernel_.<locals>.<listcomp>2  s    UUUy"UUUr.   )r   r   r@   r   r   )r+   s    r,   r@   z!GaussianProcessClassifier.kernel_+  sF     ?a'//!UUD4H4TUUU  r.   c                    t          |            |rt          d          | j        S t          j                  | j        dk    r| j                            |          S |rt          d          | j        j	        }|d         j
        j        j        d         k    r.t          j        fdt          |          D                       S j        d         | j        j        d         z  k    r/t          j        fdt          |          D                       S t          d	| j        j        d         z  j        d         fz            )
a  Return log-marginal likelihood of theta for training data.

        In the case of multi-class classification, the mean log-marginal
        likelihood of the one-versus-rest classifiers are returned.

        Parameters
        ----------
        theta : array-like of shape (n_kernel_params,), default=None
            Kernel hyperparameters for which the log-marginal likelihood is
            evaluated. In the case of multi-class classification, theta may
            be the  hyperparameters of the compound kernel or of an individual
            kernel. In the latter case, all individual kernel get assigned the
            same theta values. If None, the precomputed log_marginal_likelihood
            of ``self.kernel_.theta`` is returned.

        eval_gradient : bool, default=False
            If True, the gradient of the log-marginal likelihood with respect
            to the kernel hyperparameters at position theta is returned
            additionally. Note that gradient computation is not supported
            for non-binary classification. If True, theta must not be None.

        clone_kernel : bool, default=True
            If True, the kernel attribute is copied. If False, the kernel
            attribute is modified, but may result in a performance improvement.

        Returns
        -------
        log_likelihood : float
            Log-marginal likelihood of theta for training data.

        log_likelihood_gradient : ndarray of shape (n_kernel_params,), optional
            Gradient of the log-marginal likelihood with respect to the kernel
            hyperparameters at position theta.
            Only returned when `eval_gradient` is True.
        Nr   r
   r6   zHGradient of log-marginal-likelihood not implemented for multi-class GPC.r   c                 D    g | ]\  }}|                                S )r6   r7   )r   ir   r5   r9   s      r,   r   zEGaussianProcessClassifier.log_marginal_likelihood.<locals>.<listcomp>q  sI        )Ay "99! :    r.   c           	      f    g | ]-\  }}|                     |z  |d z   z                     .S )r   r6   r7   )r   r   r   r5   rM   r9   s      r,   r   zEGaussianProcessClassifier.log_marginal_likelihood.<locals>.<listcomp>{  sa       
 )Ay	 "99!&1*vQ/?"?@)5 :    r.   zEShape of theta must be either %d or %d. Obtained theta with shape %d.)r   rI   r[   rB   asarrayr   r   r8   NotImplementedErrorr   r@   rM   r   r   	enumeraterG   )r+   r9   r4   r5   
estimatorsrM   s    ` ` @r,   r8   z1GaussianProcessClassifier.log_marginal_likelihood5  s   L 	= S !QRRR66
5!!?a'??}< @     )'   -9J]*1F{1~''w     -6j,A,A	     Q6DM,?,B#BBBw     
 -6j,A,A     !4v(;A(>>AOP  r.   r(   r   )rK   r   r   r   r   r   r   r   r   r   dict__annotations__r-   r   ri   rp   r   propertyr@   r8   r   r.   r,   r   r     s        ` `F 4. j/!233XtD!)(AtF!K!K!K L%Xh4GGGH k"'("
M<#@AABT"
$ 
$D 
 
 
  "!    . \555H H 65HT/ / /,5 5 5<   X =AS S S S S Sr.   r   )0r   numbersr   operatorr   numpyrB   scipy.optimizer   scipy.linalgr   r   r   scipy.specialr   r	   baser   r   r   r   
multiclassr   r   preprocessingr   utilsr   utils._param_validationr   r   utils.optimizer   utils.validationr   r   kernelsr   r   r   r   r?   arrayrt   rw   rz   r   r   r   r.   r,   <module>r      s   ( (
                     3 3 3 3 3 3 3 3 3 3 $ $ $ $ $ $ $ $ F F F F F F F F F F F F @ @ @ @ @ @ @ @ ( ( ( ( ( ( & & & & & & : : : : : : : : 3 3 3 3 3 3 = = = = = = = = 0 0 0 0 0 0 0 0 0 0 ( ( ( ( ( ( "(000
1
1!!!RZ-
@NNN	 	!!RZ-	
# # # # #m # # #Db b b b b b b b b br.   