
    -is                     	   S r SSKrSSKrSSKrSSKrSSKrSSKJr  SSK	J
r
  SSKJr  SSKJrJrJrJr  SSKJr  SSKJr  SS	KJrJrJrJr  S
 r\R8                  " / SQ5      R:                  r\R8                  " / SQ5      R:                  r\" \5      RA                  5       r!\" SSS9r"\" SS9\"\" SSS9\" SS5      \" SSS9-  \" SS5      \" SSS9-  \" SS5      -   \" SS5      \" SSS9-  \" SS5      -   /r#\# V s/ s H  o \":w  d  M
  U PM     sn r$\RJ                  RM                  S\#5      S 5       r'S r(\RJ                  RM                  S\$5      S 5       r)\RJ                  RM                  S\#5      S 5       r*\RJ                  RM                  S\#5      S 5       r+\RJ                  RM                  S\$5      S 5       r,\RJ                  RM                  S\$5      S 5       r-\RJ                  RM                  S\#5      S 5       r.\RJ                  RM                  S\#5      S 5       r/\RJ                  RM                  S\#5      S  5       r0S! r1\RJ                  RM                  S\#5      \RJ                  RM                  S"\!\Rd                  " \Rf                  S   \Rh                  S#9/5      S$ 5       5       r5S% r6S& r7\RJ                  RM                  S\#5      S' 5       r8S( r9S) r:\RJ                  RM                  S\$5      S* 5       r;S+ r<\RJ                  RM                  S\#5      S, 5       r=S- r>S. r?S/ r@\RJ                  RM                  S\#5      S0 5       rAS1 rB\RJ                  RM                  S2S3\R                  " S45      0\DS54\" \R                  * \R                  4S69S7S8.\DS94/5      S: 5       rFS; rGS< rH\RJ                  RM                  S=S>S?/5      \RJ                  RM                  S@/ SAQ5      SB 5       5       rI\RJ                  RM                  S=S>S?/5      \RJ                  RM                  S@/ SAQ5      SC 5       5       rJ\RJ                  RM                  S@/ SDQ5      \RJ                  RM                  SESFSG/5      SH 5       5       rK\RJ                  RM                  S@/ SDQ5      SI 5       rLSJ rM " SK SL\5      rNSM rOgs  sn f )Nz'Testing for Gaussian process regression    N)approx_fprime)ConvergenceWarning)GaussianProcessRegressor)RBF
DotProductExpSineSquaredWhiteKernel)ConstantKernel)MiniSeqKernel)assert_allcloseassert_almost_equalassert_array_almost_equalassert_array_lessc                 4    U [         R                  " U 5      -  $ )N)npsin)xs    Z/var/www/html/venv/lib/python3.13/site-packages/sklearn/gaussian_process/tests/test_gpr.pyfr   "   s    rvvay=    )      ?g      @g      @g      @g      @g       @)       @g      @g      @g      @g      @r   fixedlength_scalelength_scale_boundsr   )MbP?     @@{Gz?      Y@h㈵>)r#   r"   皙?kernelc                 &   [         R                  S::  a  [        R                  " S5        [	        U S9R                  [        [        5      nUR                  [        SS9u  p#[        U[        5        [        [        R                  " U5      S5        g )N        #This test may fail on 32 bit Pythonr%   T
return_cov        )sysmaxsizepytestxfailr   fitXypredictr   r   diag)r%   gpry_predy_covs       r   test_gpr_interpolationr9   8   sd    
{{e:; #&
1
5
5a
;CKKdK3MF",r   c            	         [        SS9n / SQn[        R                  " / SQ5      n[        U S9R	                  X5      nUR                  USS9u  pE[        U " USS9S	   R                  5       S	[        R                  " [        U5      5      -
  R                  5       5        [        XB5        [        [        R                  " U5      S
5        g )Nr   )baseline_similarity_bounds)ABC)         r)   Tr*   eval_gradientr?   r,   )r   r   arrayr   r1   r4   r   raveleyelenr5   )r%   r2   r3   r6   r7   r8   s         r   !test_gpr_interpolation_structuredrH   E   s    g>FA
A
"&
1
5
5a
;CKKdK3MFq%a(..01rvvc!f~3E2L2L2N ",r   c                 "   [         R                  S::  a  [        R                  " S5        [	        U S9R                  [        [        5      nUR                  UR                  R                  5      UR                  U R                  5      :  d   eg )Nr'   r(   r)   )r-   r.   r/   r0   r   r1   r2   r3   log_marginal_likelihoodkernel_thetar%   r6   s     r   test_lml_improvingrN   T   so    
{{e:; #&
1
5
5a
;C&&s{{'8'89C<W<W=   r   c                     [        U S9R                  [        [        5      nUR	                  UR
                  R                  5      [        R                  " UR	                  5       5      :X  d   eg )Nr)   )	r   r1   r2   r3   rJ   rK   rL   r/   approxrM   s     r   test_lml_precomputedrQ   `   sY     #&
1
5
5a
;C&&s{{'8'89V]]##%>   r   c                 *   [        U S9R                  [        [        5      n[        R
                  " UR                  R                  R                  [        R                  S9nUR                  USS9  [        UR                  R                  US5        g )Nr)   dtypeF)clone_kernel   )r   r1   r2   r3   r   onesrK   rL   shapefloat64rJ   r   )r%   r6   input_thetas      r   test_lml_without_cloning_kernelr[   i   sh     #&
1
5
5a
;C''#++++11DK%@));:r   c                    [        U S9R                  [        [        5      nUR	                  UR
                  R                  S5      u  p#[        R                  " [        R                  " U5      S:  UR
                  R                  UR
                  R                  S S 2S4   :H  -  UR
                  R                  UR
                  R                  S S 2S4   :H  -  5      (       d   eg )Nr)   T-C6?r   r?   )r   r1   r2   r3   rJ   rK   rL   r   allabsbounds)r%   r6   lmllml_gradients       r   test_converged_to_local_maximumrc   s   s     #&
1
5
5a
;C33CKK4E4EtLC66			$;; 2 21a4 88	:;; 2 21a4 88	:   r   c                    [        U S9R                  [        [        5      nUR                  R
                  n[        R                  " UR                  R                  R                  5      R                  nSnX2[        R                  " US S 2S4   5      ) S4'   [        US S 2S4   UR                  R                  U-   5        [        UR                  R                  US S 2S4   U-   5        g )Nr)   绽|=r?   r   )r   r1   r2   r3   rK   r`   r   finforL   rT   maxisfiniter   )r%   r6   r`   max_tinys        r   test_solution_inside_boundsrk      s     #&
1
5
5a
;C[[F88CKK%%++,00DD,0BKKq!t%%q()fQTlCKK$5$5$<=ckk''1)<=r   c                    ^ [        U S9R                  [        [        5      mTR	                  U R
                  S5      u  p[        U R
                  U4S jS5      n[        X#S5        g )Nr)   Tc                 (   > TR                  U S5      $ )NF)rJ   )rL   r6   s    r   <lambda>#test_lml_gradient.<locals>.<lambda>   s    C$?$?u$Mr   re   rA   )r   r1   r2   r3   rJ   rL   r   r   )r%   ra   rb   lml_gradient_approxr6   s       @r   test_lml_gradientrq      sX     #&
1
5
5a
;C33FLL$GC'Mu 1=r   c                 j   [        U S9nUR                  [        SS9u  p#[        USS5        [	        UR
                  R                  5      S:  aC  [        [        R                  " U5      [        R                  " U R                  S   5      S5        g [        [        R                  " U5      SS5        g )Nr)   Tr*   r      r?   )
r   r4   r2   r   rG   r%   rL   r   r5   exp)r%   r6   y_meanr8   s       r   
test_priorrv      s~     #&
1CKKdK3MF1%
3::q BGGENBFF6<<?,CQGBGGENAq1r   c                    [        U S9R                  [        [        5      nUR	                  [
        SS9u  p#UR                  [
        S5      n[        U[        R                  " US5      S5        [        [        R                  " U5      [        R                  " U5      R                  5       -  [        R                  " US5      [        R                  " U5      R                  5       -  S5        g )Nr)   Tr*   i r?   )r   r1   r2   r3   r4   X2sample_yr   r   meanr5   rg   var)r%   r6   ru   r8   sampless        r   test_sample_statisticsr}      s     #&
1
5
5a
;CKKtK4MFll2v&G  3Q7
++--
wRWWU^//11	r   c                      [        S5      n [        U S S9R                  [        [        5      n[
        R                  " UR                  R                  5      S:X  d   eg )Nr   r%   	optimizer)	r   r   r1   r2   r3   r   rt   rK   rL   rM   s     r   test_no_optimizerr      sE    XF
"&D
A
E
Ea
KC66#++##$+++r   targetrS   c                 Z   [         R                  S::  a  [        R                  " S5        [	        U S9R                  [        [        5      nUR                  [        SS9u  p4UR                  [        SS9u  p5[        [        R                  " [        R                  " U5      5      U5        g )Nr'   r(   r)   Tr*   
return_std)r-   r.   r/   r0   r   r1   r2   r3   r4   rx   r   r   sqrtr5   )r%   r   r6   ru   r8   y_stds         r   test_predict_cov_vs_stdr      sy     {{e:; #&
1
5
5a
;CKKtK4MFKKtK4MF/7r   c                     [         R                  R                  S5      n U R                  SSS5      nUS S 2S4   SUS S 2S4   -  -   n[	        SS/5      n[        US9R                  X5      n[         R                  " UR                  R                  S   5      [         R                  " UR                  R                  S   5      S-  :  d   eg )	Nr   r?   )2   r@   r$   r   r)   rs   )
r   randomRandomStateuniformr   r   r1   rt   rK   rL   )rngr2   r3   r%   r6   s        r   test_anisotropic_kernelr      s    
 ))


"CB7#A	!Q$#!Q$-A#s_F
"&
1
5
5a
;C66#++##A&'"&&1B1B11E*F*JJJJr   c                     Su  p[         R                  R                  S5      nUR                  X5      S-  S-
  n[         R                  " U5      R                  SS9[         R                  " SU-  5      R                  SS9-   UR                  SU S9-   n[        S	S
5      [        S	/U-  S/U-  S9-  [        SSS9-   n[         R                  * n[        S5       Hz  n[        UUSS9R                  X45      nUR                  UR                  R                   5      n	X[         R"                  " [         R$                  5      R&                  -
  :  d   eU	nM|     g )N)   r@   r   r@   r?   axisrA   r$   )scalesizer   r    )r]   r"   r   r#   )r#         $@)noise_levelnoise_level_boundsrs   )r%   n_restarts_optimizerrandom_state)r   r   r   randnr   sumnormalr>   r   r	   infranger   r1   rJ   rK   rL   rf   float32eps)
	n_samples
n_featuresr   r2   r3   r%   last_lmlr   gpra   s
             r   test_random_startsr      sI    "I
))


"C		)(1,q0A
q	1
&&Q-



#	$
**3Y*
/	0  sK 3UZ'k]Z=W$ EFF wH %a%!5
 #a)	 	
 (()9)9: 4 8 88888 !)r   c                     [         R                  " [        5      n[         R                  " [        5      n[        U-
  U-  n[	        U S9nUR                  [        U5        [	        U SS9nUR                  [        [        5        UR                  [        SS9u  pgXb-  U-   nXr-  nUR                  [        SS9u  p[        Xh5        [        Xy5        UR                  [        SS9u  pXS-  -  nUR                  [        SS9u  p[        X5        g)a  
Test normalization of the target values in GP

Fitting non-normalizing GP on normalized y and fitting normalizing GP
on unnormalized y should yield identical results. Note that, here,
'normalized y' refers to y that has been made zero mean and unit
variance.

r)   Tr%   normalize_yr   r*   r@   N)
r   rz   r3   stdr   r1   r2   r4   rx   r   )r%   ru   r   y_normr6   gpr_normr7   
y_pred_stdy_pred_normy_pred_std_norm_r8   
y_cov_norms                r   test_y_normalizationr      s     WWQZFFF1IE&jE!F #&
1CGGAv (v4HHLLA RD9F^f$F#J#+#3#3B4#3#H K,
4{{2${/HA1HE$$RD$9MA*r   c                  ,   S[         -  n SS0n[        S0 UD6n[        USS9nUR                  [        U 5        UR                  [        SS9u  pE[        R                  " / SQ5      n[        R                  " / SQ5      n[        XFS	S
S9  [        XWSS
S9  g)aR  
Here we test that, when noramlize_y=True, our GP can produce a
sensible fit to training data whose variance is significantly
larger than unity. This test was made in response to issue #15612.

GP predictions are verified against predictions that were made
using GPy which, here, is treated as the 'gold standard'. Note that we
only investigate the RBF kernel here, as that is what was used in the
GPy implementation.

The following code can be used to recreate the GPy data:

--------------------------------------------------------------------------
import GPy

kernel_gpy = GPy.kern.RBF(input_dim=1, lengthscale=1.)
gpy = GPy.models.GPRegression(X, np.vstack(y_large), kernel_gpy)
gpy.optimize()
y_pred_gpy, y_var_gpy = gpy.predict(X2)
y_pred_std_gpy = np.sqrt(y_var_gpy)
--------------------------------------------------------------------------

   r   r   Tr   r   )gy(V.@gV],;g6}~CgHW-@gƠKQ@)gؼG'@gsr@g{u>5?g	?g.[?gQ?r   )rtolatolg333333?N )
r3   r   r   r1   r2   r4   rx   r   rD   r   )y_large
RBF_paramsr%   r6   r7   r   
y_pred_gpyy_pred_std_gpys           r   test_large_variance_yr   "  s    2 1fG !#&J:F
"&d
CCGGAwRD9F KJ
 XXDN FT:
 JTBr   c                     [         R                  " [        [        S-  45      R                  n [	        SS9n[        US SS9nUR                  [        [        5        [        US SS9nUR                  [        U 5        UR                  [        SS9u  pEUR                  [        SS9u  pgUR                  [        SS9u  pUR                  [        SS9u  p[        XFS S 2S	4   5        [        XFS S 2S
4   S-  5        [        U R                  S
   5       H#  n[        XWSU4   5        [        XSU4   5        M%     UR                  [        SS9nUR                  [        SS9nUR                  S:X  d   eUR                  S:X  d   e[        XS S 2S	S S 24   5        [         H  n[        USS9nUR                  [        [        5        [        USS9nUR                  [        [         R                  " [        [        45      R                  5        [        UR                  R                   UR                  R                   S5        M     g )Nr@   r   r   F)r%   r   r   Tr   r*   r   r?   .r   r   )rs   r   )rs   r@   r   r      )r   vstackr3   Tr   r   r1   r2   r4   rx   r   r   rX   ry   kernelsrK   rL   )y_2dr%   r6   gpr_2d	y_pred_1dy_std_1d	y_pred_2dy_std_2dr   y_cov_1dy_cov_2dr   y_sample_1dy_sample_2ds                 r   test_y_multioutputr   Y  s   99aQZ ""D c"F
"&De
TCGGAqM%VtQVWF
JJq$++bT+:I ...=I++bT+2KA...5KA	QT?3	QT?Q#67 

1&HsF{&;<HsF{&;< ' ,,rR,0K//"/3K'''
***Aq%9: &f$G1)TJ

1biiA'))*CKK--v~~/C/CQG r   c                     S n[        XS9nUR                  [        [        5        UR	                  UR
                  R                  5      UR	                  UR                  R                  5      :  d   eg )Nc                 V   [         R                  R                  S5      nUU " USS9pT[        S5       Hq  n[         R                  " UR                  [         R                  " SUS S 2S4   5      [         R                  " SUS S 2S4   5      5      5      nU " USS9nX:  d  Mo  XxpTMs     XE4$ )Nr   FrB   r   r?   )r   r   r   r   
atleast_1dr   maximumminimum)	obj_funcinitial_thetar`   r   	theta_optfunc_minr   rL   r   s	            r   r   (test_custom_optimizer.<locals>.optimizer  s    ii##A&]%8  rAMMBJJr6!Q$<8"**QqRSt:UVE e4A|&+8  ""r   r   )r   r1   r2   r3   rJ   rK   rL   r%   )r%   r   r6   s      r   test_custom_optimizerr     sa    # #&
FCGGAqM&&s{{'8'89C<W<W

=   r   c                     [         R                  " S5      R                  SS5      n [         R                  " S5      n[	        5       n[        USS9nSU-  n[        R                  " [         R                  R                  [        R                  " U5      S9   UR                  X5        S S S 5        g ! , (       d  f       g = f)N      r   r,   r%   alphazThe kernel, %s, is not returning a positive definite matrix. Try gradually increasing the 'alpha' parameter of your GaussianProcessRegressor estimator.match)r   arangereshaperW   r   r   r/   raiseslinalgLinAlgErrorreescaper1   )r2   r3   r%   r6   messages        r   test_gpr_correct_error_messager     s    
		"a$A

A\F
"&
<C	. 17	7  
ryy,,BIIg4F	G 
H	G	Gs   B22
C c                 L   [        U SS9n[        U SS9n[        R                  " [        [        S   45      n[        R                  " [
        [
        S   S-   45      nUR                  X45        [        R                  " [        [        S   S-   45      n[        R                  " [
        [
        S   S-   45      nUR                  X45        [        R                  " SSS5      S S 2S 4   nUR                  USS	9u  pgUR                  USS	9u  p[        Xh5        [        Xy5        g )
Nr!   r   r   r?   gV瞯<r   d   Tr   )
r   r   r   r2   hstackr3   r1   linspacer4   r   )
r%   gpr_equal_inputsgpr_similar_inputsX_y_X_testy_pred_equaly_std_equaly_pred_similary_std_similars
             r   test_duplicate_inputr     s     0vTJ1tL	Aqt9	B	Aqtax=	!B 	Aqte|$	%B	Aqtax=	!B2"[[B$QW-F 0 8 8D 8 QL$6$>$>vRV$>$W!N53r   c                  0   [        SSS9[        SSS9-  n [        5       nUR                  [        SS9u  p#UR                  [        SS9u  p$[        U S9nUR                  [        SS9u  p&UR                  [        SS9u  p'[        X65        [        XG5        g )	Nr   r   )constant_value_boundsr   Tr   r*   r)   )r>   r   r   r4   r2   r   )default_kernelgpr1r   y_std1y_cov1gpr2y_std2y_cov2s           r   test_no_fit_default_predictr    s    s':S> N $%DQ40IAQ40IA#>:DQ40IAQ40IAf-f-r   c                  Z   [        SS/S9n [        U S9nSn[        R                  " [        US9   UR                  [        [        5        S S S 5        [        SS/S9[        SS	/S9-   n[        US9n[        R                  " S
S9 n[        R                  " S5        UR                  [        [        5        [        U5      S:X  d   e[        US   R                  [        5      (       d   eUS   R                  R                   S   S:X  d   e[        US   R                  [        5      (       d   eUS   R                  R                   S   S:X  d   e S S S 5        ["        R$                  " [        S5      n[        SS/SS/S9n[        US9n[        R                  " S
S9 n[        R                  " S5        UR                  U[        5        [        U5      S:X  d   e[        US   R                  [        5      (       d   eUS   R                  R                   S   S:X  d   e[        US   R                  [        5      (       d   eUS   R                  R                   S   S:X  d   e S S S 5        g ! , (       d  f       GN4= f! , (       d  f       GN;= f! , (       d  f       g = f)Nr#   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.r   r   r   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   r   r"   r   zThe optimal value found for dimension 0 of parameter length_scale is close to the specified lower bound 10.0. Decreasing 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 lower bound 10.0. Decreasing the bound and calling fit again may find a better value.)r   r   r/   warnsr   r1   r2   r3   r	   warningscatch_warningssimplefilterrG   
issubclasscategoryr   argsr   tile)	r%   r6   warning_message
kernel_sumgpr_sumr  X_tilekernel_dimsgpr_dimss	            r   test_warning_boundsr    sy   dD\2F
"&
1C	  
(	@1 
A t= #JA J 'j9G		 	 	-h'Aq6{a&),,.@AAAA1I""1% *1 1	
1 &),,.@AAAA1I""1% *1 1	
1% 
.4 WWQ]FC:C:NK'{;H		 	 	-h'VQ6{a&),,.@AAAA1I""1% *1 1	
1 &),,.@AAAA1I""1% *1 1	
1% 
.	-K 
A	@ 
.	-< 
.	-s%   I8CJ
$C
J8
J

J
J*c                  |    S[        SS9-  n [        SSSS9nX-   n[        US9R                  [        [
        5        g )Ng     @g      I@r   r   r   )r   periodicityperiodicity_boundsr)   )r   r   r   r1   r2   r3   )k1k2r%   s      r   %test_bound_check_fixed_hyperparameterr  !  sB     
3D)	)B	cg
B WFF+//15r   c                 d   [         R                  " [        R                  S   [         R                  S9n[        U SS9nUR                  [        U5        UR                  [        R                  " S5      :X  d   eUR                  [        SS9u  p4[        X15        [        [         R                  " U5      SSS	9  [        R                  S   S
pe[         R                  R                  S5      n[         R                  " UR!                  US4S9[         R"                  " US4S
S9/SS9nUR                  [        U5        UR                  [        SS9u  p[        U	SS2S4   S
5        [        [         R                  " U
S   5      SSS	9  U	R                  XV4:X  d   eU
R                  XUU4:X  d   eg)zCheck that the std. dev. is affected to 1 when normalizing a constant
feature.
Non-regression test for:
https://github.com/scikit-learn/scikit-learn/issues/18318
NaN where affected to the target when scaling due to null std. dev. with
constant target.
r   rS   Tr   r   r*   r,   g&.>)r   r@   r?   )r   )rX   
fill_valuer   N).r?   )r   rW   r2   rX   rY   r   r1   _y_train_stdr/   rP   r4   r   r5   r   r   concatenater   full)r%   
y_constantr6   r7   r8   r   	n_targetsr   r3   Y_predY_covs              r   test_constant_targetr&  -  sb    2::6J
"&d
CCGGAzv}}S1111KKdK3MFF'BGGENCd3 771:qy
))


"C
JJYNJ+GG9a.Q7	
 	A GGAqMKKdK3MFF1a4L!$BGGE&M*Cd;<<I1111;;9;;;;r   c            	         [        SS5      [        SS/S5      -  [        SS9-   n [        U SSS	9n[        R
                  " S
S
/SS/SS
/S
S/SS/SS//5      n[        R
                  " S/S/S/S/S/S//5      nUR                  X#5        [        R
                  " SS/SS/SS/SS//5      nUR                  USS9u  pVUR                  USS9u  px[        U[        R                  " [        R                  " U5      5      SS9  g)zCheck the consistency between the returned std. dev. and the covariance.
Non-regression test for:
https://github.com/scikit-learn/scikit-learn/issues/19936
Inconsistencies were observed when the kernel cannot be inverted (or
numerically stable).
gT l+A)g-q=g   mBg닄z@gG\@r#   )r   r   N)r%   r   r   r,   g6~?g6~g6~g6~?g6$}gNխgHx@gR|=gd-ig^ L
@gzgz?Tr   r*   )r   )r>   r   r	   r   r   rD   r1   r4   r   r   diagonal)	r%   r6   X_trainy_trainr   pred1r   pred2covs	            r   2test_gpr_consistency_std_cov_non_invertible_kernelr.  V  sE    }m,s	&0 %&F #&T
JChh#J%#+$*%	
	G hhOO	
	G GGGXX+&%*%$		
F V5JEV5JECS!12>r   zparams, TypeError, err_msgr   r   zCalpha must be a scalar or an array with same number of entries as yr  r@   )r%   r   z#requires that all bounds are finitec                     [        S0 U D6n[        R                  " XS9   UR                  [        [
        5        SSS5        g! , (       d  f       g= f)z0Check that expected error are raised during fit.r   Nr   )r   r/   r   r1   r2   r3   )params	TypeErrorerr_msgr6   s       r   test_gpr_fit_errorr3    s6    ( #
,V
,C	y	01 
1	0	0s   A
Ac                      [        [        5       S9R                  [        [        5      n Sn[
        R                  " [        US9   U R                  SS9  SSS5        g! , (       d  f       g= f)z7Check that we raise the proper error in the LML method.r)   z.Gradient can only be evaluated for theta!=Noner   TrB   N)	r   r   r1   r2   r3   r/   r   
ValueErrorrJ   r6   r2  s     r   test_gpr_lml_errorr7    sK    
"#%
0
4
4Q
:C>G	z	1##$#7 
2	1	1s   A
A,c                      [        [        5       S9R                  [        [        5      n Sn[
        R                  " [        US9   U R                  [        SSS9  SSS5        g! , (       d  f       g= f)z4Check that we raise the proper error during predict.r)   z9At most one of return_std or return_cov can be requested.r   T)r+   r   N)	r   r   r1   r2   r3   r/   r   RuntimeErrorr4   r6  s     r   test_gpr_predict_errorr:    sL    
"#%
0
4
4Q
:CIG	|7	3A$48 
4	3	3s   A$$
A2r   TFr#  )Nr?   r   c                    [         R                  R                  S5      nSu  p4nU4nUb  Xa4-   nU4nUb  US:  a  Xq4-   nUR                  XC5      nUR                  XS5      n	UR                  " U6 n
[	        U S9nUR                  X5        UR                  U	SS9u  pUR                  U	SS9u  pUR                  U:X  d   eUR                  U:X  d   eUR                  U4U-   :X  d   eg)	a  Check the shapes of y_mean, y_std, and y_cov in single-output
(n_targets=None) and multi-output settings, including the edge case when
n_targets=1, where the sklearn convention is to squeeze the predictions.

Non-regression test for:
https://github.com/scikit-learn/scikit-learn/issues/17394
https://github.com/scikit-learn/scikit-learn/issues/18065
https://github.com/scikit-learn/scikit-learn/issues/22174
  )r   	   rV   Nr?   r   Tr   r*   )r   r   r   r   r   r1   r4   rX   )r   r#  r   r   n_samples_trainn_samples_testy_train_shapey_test_shaper)  r   r*  modelr7   r   r   r8   s                   r   test_predict_shapesrD    s     ))


%C29/J$&M%4 #$LQ#l2ii4GYY~2Fii'G$=E	IIgMM&TM:MF}}V}5HA<<<''';;,&&&;;>+l::::r   c                 b   [         R                  R                  S5      nSu  p4SnSnU4nUb  Xq4-   nUb  US:  a  XQU4nOXV4nUR                  XC5      n	UR                  XS5      n
UR                  " U6 n[	        U S9nUR                  X5        UR                  XS9nUR                  U:X  d   eg)	a  Check the shapes of y_samples in single-output (n_targets=0) and
multi-output settings, including the edge case when n_targets=1, where the
sklearn convention is to squeeze the predictions.

Non-regression test for:
https://github.com/scikit-learn/scikit-learn/issues/22175
r<  )r   r=  rV   rs   Nr?   r>  r   )r   r   r   r   r   r1   ry   rX   )r   r#  r   r   r?  n_samples_X_testn_samples_y_testrA  rB  r)  r   r*  rC  	y_sampless                 r   test_sample_y_shapesrI    s     ))


%C"&J$&M%4 Q(5EF(;ii4GYY'4Fii'G$=E 
IIgvBI??l***r   )Nr?   r@   rA   r   r?   rs   c                 :   [         R                  R                  S5      nUR                  SS5      nUR                  SU b  U OS5      n[	        U S9nUR                  X1S9R                  nUR                  X45        UR                  X1S9R                  nXg:X  d   eg)zJCheck the output shape of `sample_y` is consistent before and after `fit`.   r   rA   Nr?   r#  r   )r   r   r   r   r   ry   rX   r1   )r#  r   r   r2   r3   rC  shape_before_fitshape_after_fits           r   test_sample_y_shape_with_priorrO    s     ))


%C		"aA		"9#8ia@A$y9E~~a~=CC	IIaOnnQn<BBO...r   c                    [         R                  R                  S5      nSnUR                  US5      nUR                  X b  U OS5      n[	        U S9nUR                  USS9u  pgUR                  USS	9u  pUR                  X45        UR                  USS9u  pUR                  USS	9u  pUR                  U
R                  :X  d   eUR                  UR                  :X  d   eU	R                  UR                  :X  d   eg)
z<Check the output shape of `predict` with prior distribution.rK  r   rA   Nr?   rL  Tr*   r   )r   r   r   r   r   r4   r1   rX   )r#  r   n_sampler2   r3   rC  
mean_prior	cov_priorr   	std_prior	mean_postcov_poststd_posts                r   test_predict_shape_with_priorrX    s     ))


%CH		(AA		()>IAFA$y9E!MM!M=J==t=4LA	IIaO--d-;I--d-3KAy...??hnn,,,??hnn,,,r   c                  $   [         R                  R                  S5      n U R                  SS5      nU R                  SS5      n[	        SS9n[
        R                  " [        SS9   UR                  X5        S	S	S	5        g	! , (       d  f       g	= f)
zeCheck that an error is raised when the number of targets seen at fit is
inconsistent with n_targets.
r   r   rA   r@   r?   rL  z!The number of targets seen in `y`r   N)	r   r   r   r   r   r/   r   r5  r1   )r   r2   r3   rC  s       r   test_n_targets_errorrZ  ,  si     ))


"C		"aA		"aA$q1E	z)L	M		! 
N	M	Ms   &B
Bc                       \ rS rSrSrS rSrg)CustomKerneli9  z
A custom kernel that has a diag method that returns the first column of the
input matrix X. This is a helper for the test to check that the input
matrix X is not mutated.
c                     US S 2S4   $ )Nr   r   )selfr2   s     r   r5   CustomKernel.diag@  s    Awr   r   N)__name__
__module____qualname____firstlineno____doc__r5   __static_attributes__r   r   r   r\  r\  9  s    r   r\  c                      [        [        5       S9R                  [        [        5      n [
        R                  " [        5      nU R                  [        SS9u    n[        [        U5        g)z
Check that the input X is not modified by the predict method of the
GaussianProcessRegressor when setting return_std=True.

Non-regression test for:
https://github.com/scikit-learn/scikit-learn/issues/24340
r)   Tr   N)
r   r\  r1   r2   r3   r   copyrx   r4   r   )r6   X2_copyr   s      r   #test_gpr_predict_input_not_modifiedri  D  sJ     #,.
9
=
=a
CCggbkG;;rd;+DAqB r   )Prd  r   r-   r	  numpyr   r/   scipy.optimizer   sklearn.exceptionsr   sklearn.gaussian_processr    sklearn.gaussian_process.kernelsr   r   r   r	   r
   r>   4sklearn.gaussian_process.tests._mini_sequence_kernelr   sklearn.utils._testingr   r   r   r   r   
atleast_2dr   r2   rx   rE   r3   fixed_kernelr   non_fixed_kernelsmarkparametrizer9   rH   rN   rQ   r[   rc   rk   rq   rv   r}   r   rW   rX   rY   r   r   r   r   r   r   r   r   r   r  r  r  r&  r.  zerosr5  r   r3  r7  r:  rD  rI  rO  rX  rZ  r\  ri  r)   s   0r   <module>rw     s0   -
 
 
    ( 1 =  O  MM0133]],-//aDJJLASSk:c;#3KPPc;#3KPPkc;#3KPPk	 +2L'|5KV'L  7+	- ,	-- #45 6 7+ , 7+; ,; #45
 6
 #45
> 6
> 7+	> ,	> 7+2 ,2 7+ ,", 7+Arwwqwwqz'L#MN8 O ,8K6 7+$+ ,$+N4Cn+H\ #45 64 7+4 ,4*."F
R	6 7+%< ,%<P*?Z   bhhsm$Q	
 &266'2669JK() 1	
$%$89 u6m4#; 5 7#;L u6m4++ 5 7++\ o6q!f-/ . 7/ o6- 7-*
1 !_ Ms   ?	R>R>