o
    \i+                     @   s  d Z ddlZddlZddlZddlmZ ddlmZ ddl	m
Z
 ddlmZmZmZ ddlmZ ddlmZ dd	lmZmZ d
d ZeedddjZeg djZejee dkedZee Z ej!ej"edZ#de#e dk < de#e dke dk @ < de#e dk< edddZ$edde$edddeddeddd gZ%dd e%D Z&ej'(de%dd Z)d d! Z*ej'(de&d"d# Z+ej'(de%d$d% Z,ej'(de%d&d' Z-ej'(de&d(d) Z.ej'(de%d*d+ Z/d,d- Z0ej'(de&d.d/ Z1ej'(de%d0d1 Z2ej'(de%d2d3 Z3d4d5 Z4ej'(d6dedie5d7fgd8d9 Z6ej'(de%d:d; Z7d<d= Z8d>d? Z9dS )@z+Testing for Gaussian process classification    N)approx_fprime)ConvergenceWarning)GaussianProcessClassifier)RBFCompoundKernelWhiteKernel)ConstantKernel)MiniSeqKernel)assert_almost_equalassert_array_equalc                 C   s
   t | S )N)npsin)x r   /var/www/www-root/data/www/176.119.141.140/sports-predictor/venv/lib/python3.10/site-packages/sklearn/gaussian_process/tests/test_gpc.pyf   s   
r   
      )       @g      @g      @g      @g      @dtypegffffffֿ   gffffff?         ?fixedlength_scalelength_scale_boundsg?)r   )MbP?     @@g{Gz?      Y@c                 C   s   g | ]}|t kr|qS r   )fixed_kernel).0kernelr   r   r   
<listcomp>/   s    r%   r$   c                 C   s<   t | dtt}t|t|td d df dk d S )Nr$   r         ?)r   fitXyr   predictpredict_probar$   gpcr   r   r   test_predict_consistent2   s   *r/   c                  C   s\   g d} t g d}tdd}t|d| |}t|| || d d df dk d S )NAABBTFTr   baseline_similarity_boundsr&   r   r'   )r   arrayr	   r   r(   r   r+   r,   r)   r*   r$   r.   r   r   r   "test_predict_consistent_structured9   s
   
*r9   c                 C   s4   t | dtt}||jj|| jksJ d S )Nr&   )r   r(   r)   r*   log_marginal_likelihoodkernel_thetar-   r   r   r   test_lml_improvingB   s   r=   c                 C   s0   t | dtt}t||jj| d d S )Nr&      )r   r(   r)   r*   r
   r:   r;   r<   r-   r   r   r   test_lml_precomputedK   s   r?   c                 C   sJ   t | dtt}tj|jjjtj	d}|j
|dd t|jj|d d S )Nr&   r   F)clone_kernelr>   )r   r(   r)   r*   r   onesr;   r<   shapefloat64r:   r
   )r$   r.   input_thetar   r   r   test_lml_without_cloning_kernelT   s   rE   c                 C   sz   t | dtt}||jjd\}}tt	|dk |jj|jj
d d df kB |jj|jj
d d df kB s;J d S )Nr&   T-C6?r   r   )r   r(   r)   r*   r:   r;   r<   r   allabsbounds)r$   r.   lmllml_gradientr   r   r   test_converged_to_local_maximum^   s   rL   c                    sJ   t | dtt  | jd\}}t| j fddd}t||d d S )Nr&   Tc                    s     | dS )NF)r:   )r<   r.   r   r   <lambda>s   s    z#test_lml_gradient.<locals>.<lambda>g|=   )r   r(   r)   r*   r:   r<   r   r
   )r$   rJ   rK   lml_gradient_approxr   rM   r   test_lml_gradientl   s   rQ   c                 C   s   d\}}t j| }|||d d }t |jddt d| jdd dk}tddtd	g| d
g| d }t j }t	dD ]#}t
||| d||}	|	|	jj}
|
|t t jj ksdJ |
}qCd S )N)   r   r   r   )axisrO   r   r   r    r   )rF   r!   r      )r$   n_restarts_optimizerrandom_state)r   randomRandomStaterandnr   sumCr   infranger   r(   r:   r;   r<   finfofloat32eps)global_random_seed	n_samples
n_featuresrngr)   r*   r$   last_lmlrU   gprJ   r   r   r   test_random_startsy   s(   ,
rg   c                    sF    fdd}t | |d}|tt ||jj|| jks!J d S )Nc           	         s   t j }|| |dd}}tdD ].}t |t d|d d df t d|d d df }| |dd}||k rA||}}q||fS )NF)eval_gradientr   r   r   )r   rW   rX   r]   
atleast_1duniformmaximumminimum)	obj_funcinitial_thetarI   rd   	theta_optfunc_min_r<   r   ra   r   r   	optimizer   s   
2
z(test_custom_optimizer.<locals>.optimizer)r$   rt   )r   r(   r)   y_mcr:   r;   r<   )r$   ra   rt   r.   r   rs   r   test_custom_optimizer   s   
rv   c                 C   sP   t | d}|tt |t}t|dd |t}t	t
|d| d S )Nr&   r   )r   r(   r)   ru   r,   X2r
   rZ   r+   r   r   argmax)r$   r.   y_proby_predr   r   r   test_multi_class   s   


r{   c                 C   sP   t | d}|tt t | dd}|tt |t}|t}t|| d S )Nr&   r   )r$   n_jobs)r   r(   r)   ru   r,   rw   r
   )r$   r.   gpc_2ry   y_prob_2r   r   r   test_multi_class_n_jobs   s   


r   c            	      C   s   t ddgd} t| d}d}tjt|d |tt W d    n1 s&w   Y  tddgdt dd	gd }t|d}t	j
d
dG}t	d |tt t|dksXJ t|d jtsbJ |d jjd dksnJ t|d jtsxJ |d jjd dksJ W d    n1 sw   Y  ttd}t ddgddgd}t|d}t	j
d
dH}t	d ||t t|dksJ t|d jtsJ |d jjd dksJ t|d jtsJ |d jjd dksJ W d    d S 1 sw   Y  d S )Ngh㈵>r   )r   r&   zThe optimal value found for dimension 0 of parameter length_scale is close to the specified upper bound 0.001. Increasing the bound and calling fit again may find a better value.match)noise_level_boundsr   g     j@T)recordalwaysr   r   zThe optimal value found for dimension 0 of parameter k1__noise_level is close to the specified upper bound 0.001. Increasing the bound and calling fit again may find a better value.r   zThe optimal value found for dimension 0 of parameter k2__length_scale is close to the specified lower bound 1000.0. Decreasing the bound and calling fit again may find a better value.r   r   g      $@r!   r   zThe optimal value found for dimension 0 of parameter length_scale is close to the specified upper bound 100.0. Increasing the bound and calling fit again may find a better value.zThe optimal value found for dimension 1 of parameter length_scale is close to the specified upper bound 100.0. Increasing the bound and calling fit again may find a better value.)r   r   pytestwarnsr   r(   r)   r*   r   warningscatch_warningssimplefilterlen
issubclasscategorymessageargsr   tile)	r$   r.   warning_message
kernel_sumgpc_sumr   X_tilekernel_dimsgpc_dimsr   r   r   test_warning_bounds   s@   




"r   zparams, error_type, err_msgz!kernel cannot be a CompoundKernelc                 C   sN   t di | }tj||d |tt W d   dS 1 s w   Y  dS )z0Check that expected error are raised during fit.r   Nr   )r   r   raisesr(   r)   r*   )params
error_typeerr_msgr.   r   r   r   test_gpc_fit_error  s   "r   c                 C   sT   t | d}|tt |t\}}|jtjd fksJ |jtjd fks(J dS )>Checks that the latent mean and variance have the right shape.r&   r   N)r   r(   r)   r*   latent_mean_and_variancerB   )r$   r.   latent_meanlatent_variancer   r   r   'test_gpc_latent_mean_and_variance_shape   s
   
r   c                  C   sV   t t d} | tt tjtdd | t W d   dS 1 s$w   Y  dS )r   r&   zdReturning the mean and variance of the latent function f is only supported for binary classificationr   N)	r   r   r(   r)   ru   r   r   
ValueErrorr   rM   r   r   r   Atest_gpc_latent_mean_and_variance_complain_on_more_than_2_classes,  s   "r   c                  C   s@   g d} t g d}tdd}t|d| |}||  d S )Nr0   r4   r   r5   r&   )r   r7   r	   r   r(   r   r8   r   r   r   9test_latent_mean_and_variance_works_on_structured_kernels:  s
   
r   ):__doc__r   numpyr   r   scipy.optimizer   sklearn.exceptionsr   sklearn.gaussian_processr    sklearn.gaussian_process.kernelsr   r   r   r   r[   4sklearn.gaussian_process.tests._mini_sequence_kernelr	   sklearn.utils._testingr
   r   r   
atleast_2dlinspaceTr)   rw   r7   ravelintr*   fXemptyrB   ru   r"   kernelsnon_fixed_kernelsmarkparametrizer/   r9   r=   r?   rE   rL   rQ   rg   rv   r{   r   r   r   r   r   r   r   r   r   r   r   <module>   sz    

	


	




I



