
    0Phs              
       
   d Z ddlZddl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mZ ddlmZ ddlmZ dd	lmZmZmZmZ d
 Z ej        g d          j        Z ej        g d          j        Z ee                                           Z! edd          Z" ed          e" edd           edd           edd          z   edd           edd          z   edd          z    edd           edd          z   edd          z   gZ#d e#D             Z$ej%        &                    de#          d             Z'd Z(ej%        &                    de$          d             Z)ej%        &                    de#          d             Z*ej%        &                    de#          d             Z+ej%        &                    de$          d             Z,ej%        &                    de$          d             Z-ej%        &                    de#          d             Z.ej%        &                    de#          d              Z/ej%        &                    de#          d!             Z0d" Z1ej%        &                    de#          ej%        &                    d#e! ej2        ej3        d         ej4        $          g          d%                         Z5d& Z6d' Z7ej%        &                    de#          d(             Z8d) Z9d* Z:ej%        &                    de$          d+             Z;d, Z<ej%        &                    de#          d-             Z=d. Z>d/ Z?d0 Z@ej%        &                    de#          d1             ZAd2 ZBej%        &                    d3d4 ejC        d5          ieDd6f eejE         ejE        f7          d8d9eDd:fg          d;             ZFd< ZGd= ZHej%        &                    d>d?d@g          ej%        &                    dAg dB          dC                         ZIej%        &                    d>d?d@g          ej%        &                    dAg dB          dD                         ZJej%        &                    dAg dE          ej%        &                    dFdGdHg          dI                         ZKej%        &                    dAg dE          dJ             ZLdK ZM G dL dMe          ZNdN ZOdS )Oz'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                 0    | t          j        |           z  S )N)npsin)xs    g/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/sklearn/gaussian_process/tests/test_gpr.pyfr   "   s    rvayy=    )      ?g      @g      @g      @g      @g       @)       @g      @g      @g      @g      @r   fixedlength_scalelength_scale_boundsr   )MbP?     @@{Gz?      Y@h㈵>)r#   r"   皙?c                 (    g | ]}|t           k    |S  )fixed_kernel).0kernels     r   
<listcomp>r*   5   s"    LLLV|5K5KV5K5K5Kr   r)   c                 V   t           j        dk    rt          j        d           t	          |                               t          t                    }|                    t          d          \  }}t          |t                     t          t          j        |          d           d S )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_interpolationr>   8   s    
{e:;;; #&
1
1
1
5
5a
;
;CKKdK33MFE""",,,,,r   c            	         t          d          } g d}t          j        g d          }t          |                               ||          }|                    |d          \  }}t           | |d          d	                                         d	t          j        t          |                    z
                                             t          ||           t          t          j
        |          d
           d S )Nr   )baseline_similarity_bounds)ABC)         r.   Tr/   eval_gradientrD   r1   )r   r   arrayr   r6   r9   r   raveleyelenr:   )r)   r7   r8   r;   r<   r=   s         r   !test_gpr_interpolation_structuredrM   E   s    g>>>FA
A
"&
1
1
1
5
5a
;
;CKKdK33MFEq%%%a(..001rvc!ff~~3E2L2L2N2N   """,,,,,r   c                 $   t           j        dk    rt          j        d           t	          |                               t          t                    }|                    |j	        j
                  |                    | j
                  k    sJ d S )Nr,   r-   r.   )r2   r3   r4   r5   r   r6   r7   r8   log_marginal_likelihoodkernel_thetar)   r;   s     r   test_lml_improvingrS   T   s    
{e:;;; #&
1
1
1
5
5a
;
;C&&s{'899C<W<W= =      r   c                     t          |                               t          t                    }|                    |j        j                  t          j        |                                          k    sJ d S )Nr.   )	r   r6   r7   r8   rO   rP   rQ   r4   approxrR   s     r   test_lml_precomputedrV   `   su     #&
1
1
1
5
5a
;
;C&&s{'899V]##%%> >      r   c                 $   t          |                               t          t                    }t	          j        |j        j        j        t          j	                  }|
                    |d           t          |j        j        |d           d S )Nr.   dtypeF)clone_kernel   )r   r6   r7   r8   r   onesrP   rQ   shapefloat64rO   r   )r)   r;   input_thetas      r   test_lml_without_cloning_kernelr`   i   sx     #&
1
1
1
5
5a
;
;C'#++1DDDK%@@@);:::::r   c                    t          |                               t          t                    }|                    |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 d S )Nr.   T-C6?r   rD   )r   r6   r7   r8   rO   rP   rQ   r   allabsbounds)r)   r;   lmllml_gradients       r   test_converged_to_local_maximumrh   s   s     #&
1
1
1
5
5a
;
;C33CK4EtLLC6				$; 2111a4 88	:; 2111a4 88	:      r   c                    t          |                               t          t                    }|j        j        }t          j        |j        j        j	                  j
        }d}||t          j        |d d df                    df<   t          |d d df         |j        j        |z              t          |j        j        |d d df         |z              d S )Nr.   绽|=rD   r   )r   r6   r7   r8   rP   re   r   finforQ   rY   maxisfiniter   )r)   r;   re   max_tinys        r   test_solution_inside_boundsrp      s     #&
1
1
1
5
5a
;
;C[F8CK%+,,0DD,0FBKqqq!t%%%q()fQQQTlCK$5$<===ck'1)<=====r   c                     t          |                               t          t                                        | j        d          \  }}t          | j        fdd          }t          ||d           d S )Nr.   Tc                 0                         | d          S )NF)rO   )rQ   r;   s    r   <lambda>z#test_lml_gradient.<locals>.<lambda>   s    C$?$?u$M$M r   rj   rF   )r   r6   r7   r8   rO   rQ   r   r   )r)   rf   rg   lml_gradient_approxr;   s       @r   test_lml_gradientru      s     #&
1
1
1
5
5a
;
;C33FL$GGC'MMMMu  &91=====r   c                    t          |           }|                    t          d          \  }}t          |dd           t	          |j        j                  dk    rBt          t          j        |          t          j	        | j        d                   d           d S t          t          j        |          dd           d S )Nr.   Tr/   r      rD   )
r   r9   r7   r   rL   r)   rQ   r   r:   exp)r)   r;   y_meanr=   s       r   
test_priorrz      s     #&
1
1
1CKKdK33MFE1%%%
3:q  BGENNBF6<?,C,CQGGGGGBGENNAq11111r   c                 &   t          |                               t          t                    }|                    t
          d          \  }}|                    t
          d          }t          |t          j	        |d          d           t          t          j
        |          t          j
        |                                          z  t          j        |d          t          j
        |                                          z  d           d S )Nr.   Tr/   i rD   )r   r6   r7   r8   r9   X2sample_yr   r   meanr:   rl   var)r)   r;   ry   r=   sampless        r   test_sample_statisticsr      s     #&
1
1
1
5
5a
;
;CKKtK44MFEll2v&&G  3 3Q777
++---
wRWU^^//111	    r   c                      t          d          } t          | d                               t          t                    }t          j        |j        j                  dk    sJ d S )Nr   r)   	optimizer)	r   r   r6   r7   r8   r   rx   rP   rQ   rR   s     r   test_no_optimizerr      sU    XXF
"&D
A
A
A
E
Ea
K
KC6#+#$$++++++r   targetrX   c                    t           j        dk    rt          j        d           t	          |                               t          t                    }|                    t          d          \  }}|                    t          d          \  }}t          t          j        t          j        |                    |           d S )Nr,   r-   r.   Tr/   
return_std)r2   r3   r4   r5   r   r6   r7   r8   r9   r|   r   r   sqrtr:   )r)   r   r;   ry   r=   y_stds         r   test_predict_cov_vs_stdr      s     {e:;;; #&
1
1
1
5
5a
;
;CKKtK44MFEKKtK44MFE//77777r   c                     t           j                            d          } |                     ddd          }|d d df         d|d d df         z  z   }t	          ddg          }t          |                              ||          }t          j        |j        j	        d                   t          j        |j        j	        d                   dz  k    sJ d S )	Nr   rD   )2   rE   r$   r   r.   rw   )
r   randomRandomStateuniformr   r   r6   rx   rP   rQ   )rngr7   r8   r)   r;   s        r   test_anisotropic_kernelr      s    
 )


"
"CB7##A	!!!Q$#!!!Q$-A#s__F
"&
1
1
1
5
5a
;
;C6#+#A&''"&1B11E*F*F*JJJJJJJr   c                     d\  } }t           j                            d          }|                    | |          dz  dz
  }t          j        |                              d          t          j        d|z                                d          z   |                    d|           z   }t          d	d
          t          d	g|z  dg|z            z  t          dd          z   }t           j
         }t          d          D ]u}t          ||d                              ||          }|                    |j        j                  }	|	|t          j        t           j                  j        z
  k    sJ |	}vd S )N)   rE   r   rE   rD   axisrF   r$   )scalesizer   r    )rb   r"   r   r#   )r#         $@)noise_levelnoise_level_boundsrw   )r)   n_restarts_optimizerrandom_state)r   r   r   randnr   sumnormalrC   r   r	   infranger   r6   rO   rP   rQ   rk   float32eps)
	n_samples
n_featuresr   r7   r8   r)   last_lmlr   gprf   s
             r   test_random_startsr      s    "Iz
)


"
"C		)Z((1,q0A
q		1
&Q--



#
#	$
**3Y*
/
/	0  sK  3UZ'k]Z=W$ $ $ EEEFF wH %a  %!5
 
 
 #a))	 	
 (()9::X 4 4 888888 r   c                    t          j        t                    }t          j        t                    }t          |z
  |z  }t	          |           }|                    t          |           t	          | d          }|                    t          t                     |                    t          d          \  }}||z  |z   }||z  }|                    t          d          \  }}	t          ||           t          ||	           |                    t          d          \  }
}||dz  z  }|                    t          d          \  }
}t          ||           dS )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/   rE   N)
r   r~   r8   stdr   r6   r7   r9   r|   r   )r)   ry   r   y_normr;   gpr_normr<   
y_pred_stdy_pred_normy_pred_std_norm_r=   
y_cov_norms                r   test_y_normalizationr      sD    WQZZFF1IIE&jE!F #&
1
1
1CGGAv (v4HHHHLLA RD99FJe^f$Fe#J#+#3#3B4#3#H#H K,,,
O444{{2${//HAuE1HE$$RD$99MAzz*****r   c                  t   dt           z  } ddi}t          di |}t          |d          }|                    t          |            |                    t          d          \  }}t          j        g d          }t          j        g d          }t          ||d	d
           t          ||dd
           dS )a  
    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?Nr&   )
r8   r   r   r6   r7   r9   r|   r   rI   r   )y_large
RBF_paramsr)   r;   r<   r   
y_pred_gpyy_pred_std_gpys           r   test_large_variance_yr   "  s    2 1fG !#&J:F
"&d
C
C
CCGGAwRD99FJ KKK J
 XDDD N FJT::::
 JTBBBBBBr   c                  p   t          j        t          t          dz  f          j        } t	          d          }t          |d d          }|                    t          t                     t          |d d          }|                    t          |            |                    t          d          \  }}|                    t          d          \  }}|                    t          d          \  }}	|                    t          d          \  }}
t          ||d d d	f                    t          ||d d d
f         dz             t          | j        d
                   D ]2}t          ||d|f                    t          |	|
d|f                    3|                    t          d          }|                    t          d          }|j        dk    sJ |j        dk    sJ t          ||d d d	d d f                    t          D ]}t          |d          }|                    t          t                     t          |d          }|                    t          t          j        t          t          f          j                   t          |j        j        |j        j        d           d S )NrE   r   r   F)r)   r   r   Tr   r/   r   rD   .r   r   )rw   r   )rw   rE   r   r      )r   vstackr8   Tr   r   r6   r7   r9   r|   r   r   r]   r}   kernelsrP   rQ   )y_2dr)   r;   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   9aQZ  "D c"""F
"&De
T
T
TCGGAqMMM%VtQVWWWF
JJq$++bT+::Ix ...==Ix++bT+22KAx...55KAx	9QQQT?333	9QQQT?Q#6777 
1&& = =HhsF{&;<<<HhsF{&;<<<<,,rR,00K//"/33K''''
****[Aqqq%9:::  H H&f$GGG1)TJJJ

1biA'')***CK-v~/CQGGGGH Hr   c                     d }t          | |          }|                    t          t                     |                    |j        j                  |                    |j        j                  k    sJ d S )Nc                 |   t           j                            d          }| | |d          }}t          d          D ]{}t          j        |                    t          j        d|d d df                   t          j        d|d d df                                       } | |d          }||k     r||}}|||fS )Nr   FrG   r   rD   )r   r   r   r   
atleast_1dr   maximumminimum)	obj_funcinitial_thetare   r   	theta_optfunc_minr   rQ   r   s	            r   r   z(test_custom_optimizer.<locals>.optimizer  s    i##A&&+XX.
 .
 .
8	 r 	/ 	/AMBJr6!!!Q$<88"*QqqqRSt:U:UVV E e444A8||&+Q8	(""r   r   )r   r6   r7   r8   rO   rP   rQ   r)   )r)   r   r;   s      r   test_custom_optimizerr     s    # # # #&I
F
F
FCGGAqMMM&&s{'899C<W<W
= =      r   c                     t          j        d                              dd          } t          j        d          }t	                      }t          |d          }d|z  }t          j        t           j        j	        t          j        |                    5  |                    | |           d d d            d S # 1 swxY w Y   d S )N      r   r1   r)   alphazThe kernel, %s, is not returning a positive definite matrix. Try gradually increasing the 'alpha' parameter of your GaussianProcessRegressor estimator.match)r   arangereshaper\   r   r   r4   raiseslinalgLinAlgErrorreescaper6   )r7   r8   r)   r;   messages        r   test_gpr_correct_error_messager     s    
	"a$$A


A\\F
"&
<
<
<C	. 17	7  
ry,BIg4F4F	G	G	G  1                 s   B<<C C c                    t          | d          }t          | d          }t          j        t          t          d         f          }t          j        t
          t
          d         dz   f          }|                    ||           t          j        t          t          d         dz   f          }t          j        t
          t
          d         dz   f          }|                    ||           t          j        ddd          d d d f         }|                    |d	          \  }}|                    |d	          \  }}	t          ||           t          ||	           d S )
Nr!   r   r   rD   gV瞯<r   d   Tr   )
r   r   r   r7   hstackr8   r6   linspacer9   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JJ1tLLL	Aqt9		B	Aqtax=	!	!BR   	Aqte|$	%	%B	Aqtax=	!	!B2r"""[B$$QQQW-F 0 8 8D 8 Q QL+$6$>$>vRV$>$W$W!NMn555]33333r   c                     t          dd          t          dd          z  } t                      }|                    t          d          \  }}|                    t          d          \  }}t          |           }|                    t          d          \  }}|                    t          d          \  }}t          ||           t          ||           d S )	Nr   r   )constant_value_boundsr   Tr   r/   r.   )rC   r   r   r9   r7   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00IAvQ400IAv#>:::DQ400IAvQ400IAvff---ff-----r   c                     t          ddg          } t          |           }d}t          j        t          |          5  |                    t          t                     d d d            n# 1 swxY w Y   t          ddg          t          dd	g          z   }t          |          }t          j
        d
          5 }t          j        d           |                    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            n# 1 swxY w Y   t#          j        t          d          }t          ddgddg          }t          |          }t          j
        d
          5 }t          j        d           |                    |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            d S # 1 swxY w Y   d S )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alwaysrE   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.rD   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   r4   warnsr   r6   r7   r8   r	   warningscatch_warningssimplefilterrL   
issubclasscategoryr   argsr   tile)	r)   r;   warning_message
kernel_sumgpr_sumr  X_tilekernel_dimsgpr_dimss	            r   test_warning_boundsr    s   dD\222F
"&
1
1
1C	  
(	@	@	@  1               t=== #JA A A J 'j999G		 	-	-	- 
h'''Aq6{{a&),.@AAAAA1I"1% *1 1 1 1 1 &),.@AAAAA1I"1% *1 1 1 1 1 1%
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4 WQ]]FC:C:NNNK'{;;;H		 	-	-	- 
h'''VQ6{{a&),.@AAAAA1I"1% *1 1 1 1 1 &),.@AAAAA1I"1% *1 1 1 1 1 1%
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
s8    !A--A14A1C
FF F8CKKKc                      dt          d          z  } t          ddd          }| |z   }t          |                              t          t
                     d S )Ng     @g      I@r   r   r   )r   periodicityperiodicity_boundsr.   )r   r   r   r6   r7   r8   )k1k2r)   s      r   %test_bound_check_fixed_hyperparameterr     sf     
3D)))	)B	cg
 
 
B "WFF+++//155555r   c                    t          j        t          j        d         t           j                  }t          | d          }|                    t          |           |j        t          j	        d          k    sJ |
                    t          d          \  }}t          ||           t          t          j        |          dd	           t          j        d         d
}}t           j                            d          }t          j        |                    |df          t          j        |dfd
          gd          }|                    t          |           |
                    t          d          \  }	}
t          |	dddf         d
           t          t          j        |
d                   dd	           |	j        ||fk    sJ |
j        |||fk    sJ dS )a  Check 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   rX   Tr   r   r/   r1   g&.>)r   rE   rD   )r   )r]   
fill_valuer   N).rD   )r   r\   r7   r]   r^   r   r6   _y_train_stdr4   rU   r9   r   r:   r   r   concatenater   full)r)   
y_constantr;   r<   r=   r   	n_targetsr   r8   Y_predY_covs              r   test_constant_targetr(  ,  s    2:666J
"&d
C
C
CCGGAzv}S111111KKdK33MFEFJ'''BGENNCd3333 71:qyI
)


"
"C
JJYNJ++G9a.Q777	
 	 	 	A GGAqMMMKKdK33MFEF111a4L!$$$BGE&M**Cd;;;;<Iy11111;9i;;;;;;;r   c            	      ^   t          dd          t          ddgd          z  t          d          z   } t          | dd	          }t	          j        d
d
gddgdd
gd
dgddgddgg          }t	          j        dgdgdgdgdgdgg          }|                    ||           t	          j        ddgddgddgddgg          }|                    |d          \  }}|                    |d          \  }}t          |t	          j	        t	          j
        |                    d           dS )a
  Check 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   r1   g6~?g6~g6~g6~?g6$}gNխgHx@gR|=gd-ig^ L
@gzgz?Tr   r/   )r   )rC   r   r	   r   r   rI   r6   r9   r   r   diagonal)	r)   r;   X_trainy_trainr   pred1r   pred2covs	            r   2test_gpr_consistency_std_cov_non_invertible_kernelr0  U  s    }m,,s	&0 0 %%%&F #&T
J
J
JCh#J%#+$*%	
	 	G hOO	
	 	G GGGWX+&%*%$		
 F V55JE3V55JE3CS!1!122>>>>>>r   zparams, TypeError, err_msgr   r   zCalpha must be a scalar or an array with same number of entries as yr  rE   )r)   r   z#requires that all bounds are finitec                     t          di | }t          j        ||          5  |                    t          t
                     ddd           dS # 1 swxY w Y   dS )z0Check that expected error are raised during fit.r   Nr&   )r   r4   r   r6   r7   r8   )params	TypeErrorerr_msgr;   s       r   test_gpr_fit_errorr5    s    ( #
,
,V
,
,C	y	0	0	0  1                 s   !AAAc                     t          t                                                    t          t                    } d}t          j        t          |          5  |                     d           ddd           dS # 1 swxY w Y   dS )z7Check that we raise the proper error in the LML method.r.   z.Gradient can only be evaluated for theta!=Noner   TrG   N)	r   r   r6   r7   r8   r4   r   
ValueErrorrO   r;   r4  s     r   test_gpr_lml_errorr9    s    
"#%%
0
0
0
4
4Q
:
:C>G	z	1	1	1 8 8##$#7778 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8s   A<<B B c                      t          t                                                    t          t                    } d}t          j        t          |          5  |                     t          dd           ddd           dS # 1 swxY w Y   dS )z4Check that we raise the proper error during predict.r.   z9At most one of return_std or return_cov can be requested.r   T)r0   r   N)	r   r   r6   r7   r8   r4   r   RuntimeErrorr9   r8  s     r   test_gpr_predict_errorr<    s    
"#%%
0
0
0
4
4Q
:
:CIG	|7	3	3	3 9 9A$48889 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9s   BB
Br   TFr%  )NrD   r   c                    t           j                            d          }d\  }}}|f}|||fz   }|f}||dk    r||fz   }|                    ||          }|                    ||          }	 |j        | }
t	          |           }|                    ||
           |                    |	d          \  }}|                    |	d          \  }}|j        |k    sJ |j        |k    sJ |j        |f|z   k    sJ dS )	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   	   r[   NrD   r   Tr   r/   )r   r   r   r   r   r6   r9   r]   )r   r%  r   r   n_samples_trainn_samples_testy_train_shapey_test_shaper+  r   r,  modelr<   r   r   r=   s                   r   test_predict_shapesrF    s4    )


%
%C29/J$&M%4 #$LQ#yl2ii44GYY~z22Fci'G$===E	IIgwMM&TM::MFE}}V}55HAu<<'''';,&&&&;>+l:::::::r   c                    t           j                            d          }d\  }}d}d}|f}|||fz   }||dk    r|||f}n||f}|                    ||          }	|                    ||          }
 |j        | }t	          |           }|                    |	|           |                    |
|          }|j        |k    sJ dS )	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?  r[   rw   NrD   r@  r   )r   r   r   r   r   r6   r}   r]   )r   r%  r   r   rA  n_samples_X_testn_samples_y_testrC  rD  r+  r   r,  rE  	y_sampless                 r   test_sample_y_shapesrK    s     )


%
%C"&J$&M%4 Q()5EF(*:;ii44GYY'44Fci'G$===E 
IIgwv1ABBI?l******r   )NrD   rE   rF   r   rD   rw   c                 p   t           j                            d          }|                    dd          }|                    d| | nd          }t	          |           }|                    ||          j        }|                    ||           |                    ||          j        }||k    sJ dS )zJCheck the output shape of `sample_y` is consistent before and after `fit`.   r   rF   NrD   r%  r   )r   r   r   r   r   r}   r]   r6   )r%  r   r   r7   r8   rE  shape_before_fitshape_after_fits           r   test_sample_y_shape_with_priorrQ    s     )


%
%C		"aA		"9#8iia@@A$y999E~~a9~==C	IIaOOOnnQ)n<<BO......r   c                 0   t           j                            d          }d}|                    |d          }|                    || | nd          }t	          |           }|                    |d          \  }}|                    |d	          \  }}	|                    ||           |                    |d          \  }
}|                    |d	          \  }}|j        |
j        k    sJ |j        |j        k    sJ |	j        |j        k    sJ dS )
z<Check the output shape of `predict` with prior distribution.rM  r   rF   NrD   rN  Tr/   r   )r   r   r   r   r   r9   r6   r]   )r%  r   n_sampler7   r8   rE  
mean_prior	cov_priorr   	std_prior	mean_postcov_poststd_posts                r   test_predict_shape_with_priorrZ    s    )


%
%CH		(AA		()>IIAFFA$y999E!MM!M==J	==t=44LAy	IIaOOO--d-;;Ix--d-33KAxy....?hn,,,,?hn,,,,,,r   c                  P   t           j                            d          } |                     dd          }|                     dd          }t	          d          }t          j        t          d          5  |                    ||           d	d	d	           d	S # 1 swxY w Y   d	S )
zmCheck that an error is raised when the number of targets seen at fit is
    inconsistent with n_targets.
    r   r   rF   rE   rD   rN  z!The number of targets seen in `y`r   N)	r   r   r   r   r   r4   r   r7  r6   )r   r7   r8   rE  s       r   test_n_targets_errorr\  +  s     )


"
"C		"aA		"aA$q111E	z)L	M	M	M  		!Q                 s   7BB"Bc                       e Zd ZdZd ZdS )CustomKernelz
    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                     |d d df         S )Nr   r&   )selfr7   s     r   r:   zCustomKernel.diag?  s    Awr   N)__name__
__module____qualname____doc__r:   r&   r   r   r^  r^  8  s-             r   r^  c                     t          t                                                    t          t                    } t          j        t                    }|                     t          d          \  }}t          t          |           dS )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^  r6   r7   r8   r   copyr|   r9   r   )r;   X2_copyr   s      r   #test_gpr_predict_input_not_modifiedrh  C  sd     #,..
9
9
9
=
=a
C
CCgbkkG;;rd;++DAqB     r   )Prd  r   r2   r  numpyr   r4   scipy.optimizer   sklearn.exceptionsr   sklearn.gaussian_processr    sklearn.gaussian_process.kernelsr   r   r   r	   r
   rC   4sklearn.gaussian_process.tests._mini_sequence_kernelr   sklearn.utils._testingr   r   r   r   r   
atleast_2dr   r7   r|   rJ   r8   r'   r   non_fixed_kernelsmarkparametrizer>   rM   rS   rV   r`   rh   rp   ru   rz   r   r   r\   r]   r^   r   r   r   r   r   r   r   r   r   r  r  r  r(  r0  zerosr7  r   r5  r9  r<  rF  rK  rQ  rZ  r\  r^  rh  r&   r   r   <module>ru     s   - -
 
			 



       ( ( ( ( ( ( 1 1 1 1 1 1 = = = = = =                 O N N N N N              BM000113R],,,--/AaDDJJLLsAAACSCSk:::Ac;##3KPPPPAc;##3KPPPPakAc;##3KPPPPak	 ML'LLL  7++	- 	- ,+	-- - - #455  65 7++  ,+ 7++; ; ,+; #455
 
 65
 #455
> 
> 65
> 7++	> 	> ,+	> 7++2 2 ,+2 7++  ,+", , , 7++Awrwqwqz'L'L'L#MNN8 8 ON ,+8K K K  6 7++$+ $+ ,+$+N4C 4C 4Cn+H +H +H\ #455  652   7++4 4 ,+4*. . ."F
 F
 F
R	6 	6 	6 7++%< %< ,+%<P*? *? *?Z   hbhsmm$Q	
 &+26'269JKKK()  1	
 $ % $8 8 89 9 9 u66mmm44#; #; 54 76#;L u66mmm44++ ++ 54 76++\ ooo66q!f--/ / .- 76/ ooo66- - 76-*
 
 
    1   ! ! ! ! !r   