
    _nd&                        d Z ddlZddlZddlmZ ddl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 d	 Z ej         ej        dd
d                    j        Z ej        g d          j        Z ej         ee                                          dk    e          Z ee                                          Z  ej!        ej"        e          Z#de#e dk     <   de#e dk    e dk     z  <   de#e dk    <    e
dd          Z$ e
d          e$ e
dd           edd           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/d" Z0ej'        (                    de&          d#             Z1ej'        (                    de%          d$             Z2ej'        (                    de%          d%             Z3d& Z4ej'        (                    d'd ed          ie5d(fg          d)             Z6dS )*z,Testing for Gaussian process classification     N)approx_fprime)GaussianProcessClassifier)RBFCompoundKernelConstantKernelWhiteKernel)MiniSeqKernel)ConvergenceWarning)assert_almost_equalassert_array_equalc                 *    t          j        |           S )N)npsin)xs    Glib/python3.11/site-packages/sklearn/gaussian_process/tests/test_gpc.pyfr      s    6!99    
      )       @g      @g      @g      @g      @dtypegffffffֿ   gffffff?         ?fixedlength_scalelength_scale_boundsg?)r   )MbP?     @@g{Gz?      Y@c                 (    g | ]}|t           k    |S  )fixed_kernel).0kernels     r   
<listcomp>r)   /   s"    LLLV|5K5KV5K5K5Kr   r(   c                     t          |                               t          t                    }t	          |                    t                    |                    t                    d d df         dk               d S )Nr(   r         ?)r   fitXyr   predictpredict_probar(   gpcs     r   test_predict_consistentr4   2   sd     $6
2
2
2
6
6q!
<
<Cs{{1~~s'8'8';';AAAqD'AS'HIIIIIr   c                  *   g d} t          j        g d          }t          d          }t          |                              | |          }t          |                    |           |                    |           d d df         dk               d S )N)AABB)TFTr   )baseline_similarity_boundsr+   r   r,   )r   arrayr	   r   r-   r   r0   r1   )r.   r/   r(   r3   s       r   "test_predict_consistent_structuredr;   9   s    A
$$$%%Ag>>>F
#6
2
2
2
6
6q!
<
<Cs{{1~~s'8'8';';AAAqD'AS'HIIIIIr   c                     t          |                               t          t                    }|                    |j        j                  |                    | j                  k    sJ d S )Nr+   )r   r-   r.   r/   log_marginal_likelihoodkernel_thetar2   s     r   test_lml_improvingr@   B   so     $6
2
2
2
6
6q!
<
<C&&s{'899C<W<W= =      r   c                     t          |                               t          t                    }t	          |                    |j        j                  |                                d           d S )Nr+      )r   r-   r.   r/   r   r=   r>   r?   r2   s     r   test_lml_precomputedrC   K   sg     $6
2
2
2
6
6q!
<
<C##CK$5668S8S8U8UWX    r   c                 $   t          |                               t          t                    }t	          j        |j        j        j        t          j	                  }|
                    |d           t          |j        j        |d           d S )Nr+   r   F)clone_kernelrB   )r   r-   r.   r/   r   onesr>   r?   shapefloat64r=   r   )r(   r3   input_thetas      r   test_lml_without_cloning_kernelrJ   T   sx     $6
2
2
2
6
6q!
<
<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   r   )r   r-   r.   r/   r=   r>   r?   r   allabsbounds)r(   r3   lmllml_gradients       r   test_converged_to_local_maximumrR   ^   s     $6
2
2
2
6
6q!
<
<C33CK4EtLLC6				$; 2111a4 88	:; 2111a4 88	:      r   c                     t          |                               t          t                                        | j        d          \  }}t          | j        fdd          }t          ||d           d S )Nr+   Tc                 0                         | d          S )NF)r=   )r?   r3   s    r   <lambda>z#test_lml_gradient.<locals>.<lambda>s   s    C$?$?u$M$M r   g|=   )r   r-   r.   r/   r=   r?   r   r   )r(   rP   rQ   lml_gradient_approxr3   s       @r   test_lml_gradientrX   l   s     $6
2
2
2
6
6q!
<
<C33FL$GGC'MMMMu  &91=====r   c                     d\  } }t           j                            d          }|                    | |          dz  dz
  }t          j        |                              d          t          j        d|z                                d          z   dk    }t          dd          t          d	g|z  d
g|z            z  }t           j         }t          d          D ]u}t          ||d                              ||          }|                    |j        j                  }	|	|t          j        t           j                  j        z
  k    sJ |	}vd S )N)   r   r   r   r   )axisrV   r   r"   r    )rL   r#   r      )r(   n_restarts_optimizerrandom_state)r   randomRandomStaterandnr   sumCr   infranger   r-   r=   r>   r?   finfofloat32eps)
	n_samples
n_featuresrngr.   r/   r(   last_lmlr]   gprP   s
             r   test_random_startsrn   y   sX    "Iz
)


"
"C		)Z((1,q0A	A		A!2!2!2!:!:	:a?AsK  3Vj({mj>X$ $ $ F wH %a  &0DST
 
 

#a)) 	 (()9::X 4 4 888888 r   c                     d }t          | |          }|                    t          t                     |                    |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   F)eval_gradientr   r   )r   r_   r`   re   
atleast_1duniformmaximumminimum)	obj_funcinitial_thetarO   rk   	theta_optfunc_min_r?   r   s	            r   	optimizerz(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|   )r   r-   r.   y_mcr=   r>   r?   )r(   r|   r3   s      r   test_custom_optimizerr~      s    # # # $6Y
G
G
GCGGAt&&s{'899C<W<W= =      r   c                 Z   t          |           }|                    t          t                     |                    t
                    }t          |                    d          d           |                    t
                    }t          t          j        |d          |           d S )Nr+   r   )r   r-   r.   r}   r1   X2r   rb   r0   r   r   argmax)r(   r3   y_proby_preds       r   test_multi_classr      s     $6
2
2
2CGGAtr""F

1q)))[[__Fry++V44444r   c                 P   t          |           }|                    t          t                     t          | d          }|                    t          t                     |                    t
                    }|                    t
                    }t          ||           d S )Nr+   r   )r(   n_jobs)r   r-   r.   r}   r1   r   r   )r(   r3   gpc_2r   y_prob_2s        r   test_multi_class_n_jobsr      s     $6
2
2
2CGGAt%VA>>>E	IIar""F""2&&H)))))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 )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(   r3   warning_message
kernel_sumgpc_sumr   X_tilekernel_dimsgpc_dimss	            r   test_warning_boundsr      s   dD\222F
#6
2
2
2C	  
(	@	@	@  1               t=== #JA A A J (z:::G		 	-	-	- 
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'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8 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zparams, error_type, err_msgz!kernel cannot be a CompoundKernelc                     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   r   raisesr-   r.   r/   )params
error_typeerr_msgr3   s       r   test_gpc_fit_errorr     s     $
-
-f
-
-C	z	1	1	1  1                 s   !AAA)7__doc__r   numpyr   scipy.optimizer   r   sklearn.gaussian_processr    sklearn.gaussian_process.kernelsr   r   r   rc   r   4sklearn.gaussian_process.tests._mini_sequence_kernelr	   sklearn.exceptionsr
   sklearn.utils._testingr   r   r   
atleast_2dlinspaceTr.   r   r:   ravelintr/   fXemptyrG   r}   r&   kernelsnon_fixed_kernelsmarkparametrizer4   r;   r@   rC   rJ   rR   rX   rn   r~   r   r   r   
ValueErrorr   r%   r   r   <module>r      sY   2 2
      ( ( ( ( ( (  > > > > > >            O N N N N N 1 1 1 1 1 1 J J J J J J J J   BM+"+aR(())+R],,,--/BHQQqTTZZ\\AS)))QqTTZZ\\rxs###R%Z $%bEkb4i  !R$Y sAAACSCSk:::Ac;##3KPPPP	 ML'LLL  7++J J ,+JJ J J #455  65 7++  ,+ 7++; ; ,+; #455
 
 65
 7++	> 	> ,+	>  * #455  652 7++	5 	5 ,+	5 7++
* 
* ,+
*J
 J
 J
Z ! ~~a(()/	
	 	 	 	  r   