
    Q3j.              
          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 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mZ d Z ej4                   ej6                  ddd            j8                  Z ej4                  g d      j8                  Z ej>                   ee      jA                         dkD  e!      Z" ee      jA                         Z# ejH                  e"jJ                  e!      Z&de&e#dk  <   de&e#dk\  e#dk  z  <   de&e#dkD  <    edd      Z' ed      e' edd       edd       edd      z  gZ(e(D  cg c]
  } | e'k7  s	|  c} Z)ejT                  jW                  de(      d        Z,d Z-ejT                  jW                  de)      d        Z.ejT                  jW                  de(      d        Z/ejT                  jW                  de(      d         Z0ejT                  jW                  de)      d!        Z1ejT                  je                  e3d"#      ejT                  jW                  de)      ejT                  jW                  d$ ejh                  d%d&d'            d(                      Z5d) Z6ejT                  jW                  de)      d*        Z7ejT                  jW                  de(      d+        Z8ejT                  jW                  de(      d,        Z9d- Z:ejT                  jW                  d.d ed      ie;d/fg      d0        Z<ejT                  jW                  de(      d1        Z=d2 Z>d3 Z?yc c} w )4z+Testing for Gaussian process classification    N)approx_fprime)clone)ConvergenceWarning)GaussianProcessClassifier)RBFCompoundKernelWhiteKernel)ConstantKernel)MiniSeqKernel)assert_allcloseassert_almost_equalassert_array_equalc                 ,    t        j                  |       S )N)npsin)xs    T/DATA/.local/lib/python3.12/site-packages/sklearn/gaussian_process/tests/test_gpc.pyfr      s    66!9    
      )       @g      @g      @g      @g      @dtypegffffffֿ   gffffff?         ?fixedlength_scalelength_scale_boundsg?)r    )MbP?     @@g{Gz?      Y@kernelc                     t        |       j                  t        t              }t	        |j                  t              |j                  t              d d df   dk\         y )Nr&   r         ?)r   fitXyr   predictpredict_probar&   gpcs     r   test_predict_consistentr1   7   sF     $6
2
6
6q!
<Cs{{1~s'8'8';AqD'AS'HIr   c                      g d} t        j                  g d      }t        d      }t        |      j	                  | |      }t        |j                  |       |j                  |       d d df   dk\         y )NAABBTFTr   baseline_similarity_boundsr(   r   r)   )r   arrayr   r   r*   r   r-   r.   r+   r,   r&   r0   s       r   "test_predict_consistent_structuredr<   >   sb    A
$%Ag>F
#6
2
6
6q!
<Cs{{1~s'8'8';AqD'AS'HIr   c                     t        |       j                  t        t              }|j	                  |j
                  j                        |j	                  | j                        kD  sJ y )Nr(   )r   r*   r+   r,   log_marginal_likelihoodkernel_thetar/   s     r   test_lml_improvingrA   G   sV     $6
2
6
6q!
<C&&s{{'8'89C<W<W=   r   c                     t        |       j                  t        t              }t	        |j                  |j                  j                        |j                         d       y )Nr(      )r   r*   r+   r,   r   r>   r?   r@   r/   s     r   test_lml_precomputedrD   P   sI     $6
2
6
6q!
<C##CKK$5$568S8S8UWXr   c                 :   t        |       j                  t        t              }t	        j
                  |j                  j                  j                  t        j                        }|j                  |d       t        |j                  j                  |d       y )Nr(   r   F)clone_kernelrC   )r   r*   r+   r,   r   onesr?   r@   shapefloat64r>   r   )r&   r0   input_thetas      r   test_lml_without_cloning_kernelrK   Y   sh     $6
2
6
6q!
<C''#++++11DK%@));:r   c                    t        |       j                  t        t              }|j	                  |j
                  j                  d      \  }}t        j                  t        j                  |      dk  |j
                  j                  |j
                  j                  d d df   k(  z  |j
                  j                  |j
                  j                  d d df   k(  z        sJ y )Nr(   T-C6?r   r   )r   r*   r+   r,   r>   r?   r@   r   allabsbounds)r&   r0   lmllml_gradients       r   test_converged_to_local_maximumrS   c   s     $6
2
6
6q!
<C33CKK4E4EtLC66			$;; 2 21a4 88	:;; 2 21a4 88	:  r   z9https://github.com/scikit-learn/scikit-learn/issues/31366)raisesreasonr          c                    t        |       } t        d | j                         D              } | j                  di ||i t	        |       j                  t        t              j                  | j                  d      \  }}d}t        | j                  j                         fd|      }t        ||d|d	z  
       y )Nc              3   D   K   | ]  }|j                  d       s|  yw)r    N)endswith).0names     r   	<genexpr>z$test_lml_gradient.<locals>.<genexpr>{   s       #,n0M,s     r(   Teval_gradientg&.>c                 (    j                  | d      S )NF)r>   )r@   gprs    r   <lambda>z#test_lml_gradient.<locals>.<lambda>   s    c11%?r   )epsilonrM   d   )rtolatol )r   next
get_params
set_paramsr   r*   r+   r,   r>   r@   r   copyr   )r&   r    length_scale_param_name_rR   rd   lml_gradient_approxrb   s          @r   test_lml_gradientrp   q   s     6]F" #**,#  F@0,?@ $6
2
6
6q!
<C11&,,d1SOA|G'?
 L"5DwQT}Ur   c                    d\  }}t         j                  j                  |       }|j                  ||      dz  dz
  }t        j                  |      j                  d      t        j                  d|z        j                  d      z   dkD  }t        dd      t        d	g|z  d
g|z        z  }t         j                   }t        d      D ]|  }t        |||       j                  ||      }	|	j                  |	j                  j                        }
|
|t        j                  t         j                         j"                  z
  kD  sJ |
}~ y )N)   r   r   r   )axisrW   r   r   r$   r"   )rM   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   gprQ   s              r   test_random_startsr      s*    "Iz
))

 2
3C		)Z(1,q0A	A	A!2!2!2!:	:a?AsK 3Vj({mj>X$ F wH %a&!5+
 #a)	 	
 (()9)9:X 4 8 88888 !)r   c                     fd}t        | |      }|j                  t        t               |j	                  |j
                  j                        |j	                  | j                        k\  sJ y )Nc                 `   t         j                  j                  	      }| | |d      }}t        d      D ]q  }t        j                  |j                  t        j                  d|d d df         t        j                  d|d d df                     } | |d      }||k  sn||}}s ||fS )NFr_   r   r   r   )r   rw   rx   r}   
atleast_1duniformmaximumminimum)
obj_funcinitial_thetarP   r   	theta_optfunc_minrn   r@   r   r   s
            r   	optimizerz(test_custom_optimizer.<locals>.optimizer   s    ii##$67]%8 	 rAMMBJJr6!Q$<8"**QqRSt:UVE e4A8|&+Q8	  (""r   )r&   r   )r   r*   r+   y_mcr>   r?   r@   )r&   r   r   r0   s    `  r   test_custom_optimizerr      s`    # $6Y
GCGGAt&&		$	$V\\	23 3 3r   c                    t        |       }|j                  t        t               |j	                  t
              }t        |j                  d      d       |j                  t
              }t        t        j                  |d      |       y )Nr(   r   )r   r*   r+   r   r.   X2r   rz   r-   r   r   argmax)r&   r0   y_proby_preds       r   test_multi_classr      s`     $6
2CGGAtr"F

1q)[[_Fryy+V4r   c                 
   t        |       }|j                  t        t               t        | d      }|j                  t        t               |j	                  t
              }|j	                  t
              }t        ||       y )Nr(   r   )r&   n_jobs)r   r*   r+   r   r.   r   r   )r&   r0   gpc_2r   y_prob_2s        r   test_multi_class_n_jobsr      s`     $6
2CGGAt%VA>E	IIar"F""2&H)r   c                  8   t        ddg      } t        |       }d}t        j                  t        |      5  |j                  t        t               d d d        t        ddg      t        dd	g      z   }t        |      }t        j                  d
      5 }t        j                  d       |j                  t        t               t        |      dk(  sJ t        |d   j                  t              sJ |d   j                  j                   d   dk(  sJ t        |d   j                  t              sJ |d   j                  j                   d   dk(  sJ 	 d d d        t#        j$                  t        d      }t        ddgddg      }t        |      }t        j                  d
      5 }t        j                  d       |j                  |t               t        |      dk(  sJ t        |d   j                  t              sJ |d   j                  j                   d   dk(  sJ t        |d   j                  t              sJ |d   j                  j                   d   dk(  sJ 	 d d d        y # 1 sw Y   %xY w# 1 sw Y   *xY w# 1 sw Y   y xY w)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&   r0   warning_message
kernel_sumgpc_sumr   X_tilekernel_dimsgpc_dimss	            r   test_warning_boundsr      sm   dD\2F
#6
2C	  
(	@1 
A t= #JA J (z:G		 	 	-h'Aq6{a&),,.@AAA1I""1% *1 1	
1 &),,.@AAA1I""1% *1 1	
1% 
.4 WWQ]FC:C:NK(<H		 	 	-h'VQ6{a&),,.@AAA1I""1% *1 1	
1 &),,.@AAA1I""1% *1 1	
1% 
.	-K 
A	@ 
.	-< 
.	-s%   I6C J0B<J6J JJzparams, error_type, err_msgz!kernel cannot be a CompoundKernelc                     t        di | }t        j                  ||      5  |j                  t        t
               ddd       y# 1 sw Y   yxY w)z0Check that expected error are raised during fit.r   Nrh   )r   r   rT   r*   r+   r,   )params
error_typeerr_msgr0   s       r   test_gpc_fit_errorr   "  s8     $
-f
-C	z	11 
2	1	1s   AAc                    t        |       }|j                  t        t               |j	                  t              \  }}|j
                  t        j
                  d   fk(  sJ |j
                  t        j
                  d   fk(  sJ y)>Checks that the latent mean and variance have the right shape.r(   r   N)r   r*   r+   r,   latent_mean_and_variancerH   )r&   r0   latent_meanlatent_variances       r   'test_gpc_latent_mean_and_variance_shaper   3  sn     $6
2CGGAqM $'#?#?#B K---  QWWQZM111r   c                      t        t                     } | j                  t        t               t        j                  t        d      5  | j                  t               ddd       y# 1 sw Y   yxY w)r   r(   zdReturning the mean and variance of the latent function f is only supported for binary classificationr   N)	r   r   r*   r+   r   r   rT   
ValueErrorr   )r0   s    r   Atest_gpc_latent_mean_and_variance_complain_on_more_than_2_classesr   ?  sR    
#35
1CGGAt 
6

 	$$Q'
 
 
s   
A))A2c                      g d} t        j                  g d      }t        d      }t        |      j	                  | |      }|j                  |        y )Nr3   r7   r   r8   r(   )r   r:   r   r   r*   r   r;   s       r   9test_latent_mean_and_variance_works_on_structured_kernelsr   M  sE    A
$%Ag>F
#6
2
6
6q!
<C  #r   )@__doc__r   numpyr   r   scipy.optimizer   sklearn.baser   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   r   
atleast_2dlinspaceTr+   r   r:   ravelintr,   fXemptyrH   r   fixed_kernelkernelsnon_fixed_kernelsmarkparametrizer1   r<   rA   rD   rK   rS   xfailAssertionErrorlogspacerp   r   r   r   r   r   r   r   r   r   r   r(   s   0r   <module>r      s   1
    (  1 > 
 O  BMM+"++aR()++R]],-//BHHQqTZZ\AS)qTZZ\rxxs#R%Z $%bEkb4i  !R$Y ASSk:c;#3KPP	 +2L'V|5KV'L  7+J ,JJ #45 6 7+ , 7+; ,; #45
 6
 F   #45RB)?@V A 6	V*. #453 634 7+	5 ,	5 7+
* ,
*F
R ! ~a()/	
		 7+2 ,2($s Ms   
L=L=