
    {Kg&                        d Z ddlZddlZddlZddlmZ ddlmZ ddl	m
Z
 ddlmZmZmZ ddlmZ ddlmZ dd	lmZmZ d
 Z ej.                   ej0                  ddd            j2                  Z ej.                  g d      j2                  Z ej8                   ee      j;                         dkD  e      Z ee      j;                         Z  ejB                  ejD                  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jN                  jQ                  de%      d        Z)d Z*ejN                  jQ                  de&      d        Z+ejN                  jQ                  de%      d        Z,ejN                  jQ                  de%      d        Z-ejN                  jQ                  de&      d         Z.ejN                  jQ                  de%      d!        Z/d" Z0ejN                  jQ                  de&      d#        Z1ejN                  jQ                  de%      d$        Z2ejN                  jQ                  de%      d%        Z3d& Z4ejN                  jQ                  d'd ed      ie5d(fg      d)        Z6yc c} w )*z+Testing for Gaussian process classification    N)approx_fprime)ConvergenceWarning)GaussianProcessClassifier)RBFCompoundKernelWhiteKernel)ConstantKernel)MiniSeqKernel)assert_almost_equalassert_array_equalc                 ,    t        j                  |       S )N)npsin)xs    k/home/alanp/www/video.onchill/myenv/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_consistentr/   2   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$   r.   s       r   "test_predict_consistent_structuredr6   9   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_improvingr;   B   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   r8   r9   r:   r-   s     r   test_lml_precomputedr>   K   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_kernelr=   )r   r(   r)   r*   r   onesr9   r:   shapefloat64r8   r   )r$   r.   input_thetas      r   test_lml_without_cloning_kernelrE   T   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*   r8   r9   r:   r   allabsbounds)r$   r.   lmllml_gradients       r   test_converged_to_local_maximumrM   ^   s     $6
2
6
6q!
<C33CKK4E4EtLC66			$;; 2 21a4 88	:;; 2 21a4 88	:  r   c                     t        |       j                  t        t              j	                  | j
                  d      \  }}t        | j
                  fdd      }t        ||d       y )Nr&   Tc                 (    j                  | d      S )NF)r8   )r:   r.   s    r   <lambda>z#test_lml_gradient.<locals>.<lambda>s   s    C$?$?u$Mr   g|=   )r   r(   r)   r*   r8   r:   r   r   )r$   rK   rL   lml_gradient_approxr.   s       @r   test_lml_gradientrS   l   s]     $6
2
6
6q!
<C33FLL$GC'Mu &91=r   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   )axisrQ   r   r   r"   r    )rG   r#   r      )r$   n_restarts_optimizerrandom_state)r   randomRandomStaterandnr   sumCr   infranger   r(   r8   r9   r:   finfofloat32eps)global_random_seed	n_samples
n_featuresrngr)   r*   r$   last_lmlrX   gprK   s              r   test_random_startsrj   y   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 )NF)eval_gradientr   r   r   )r   rZ   r[   r`   
atleast_1duniformmaximumminimum)
obj_funcinitial_thetarJ   rg   	theta_optfunc_min_r:   r   rd   s
            r   	optimizerz(test_custom_optimizer.<locals>.optimizer   s    ii##$67+X.
8	 rAMMBJJr6!Q$<8"**QqRSt:UVE e4A8|&+Q8	  (""r   )r$   rx   )r   r(   r)   y_mcr8   r9   r:   )r$   rd   rx   r.   s    `  r   test_custom_optimizerrz      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)   ry   r,   X2r   r]   r+   r   r   argmax)r$   r.   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)   ry   r,   r|   r   )r$   r.   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$   r.   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   N )r   r   raisesr(   r)   r*   )params
error_typeerr_msgr.   s       r   test_gpc_fit_errorr     s8     $
-f
-C	z	11 
2	1	1s   AA)7__doc__r   numpyr   r   scipy.optimizer   sklearn.exceptionsr   sklearn.gaussian_processr    sklearn.gaussian_process.kernelsr   r   r   r	   r^   4sklearn.gaussian_process.tests._mini_sequence_kernelr
   sklearn.utils._testingr   r   r   
atleast_2dlinspaceTr)   r|   r5   ravelintr*   fXemptyrB   ry   fixed_kernelkernelsnon_fixed_kernelsmarkparametrizer/   r6   r;   r>   rE   rM   rS   rj   rz   r   r   r   
ValueErrorr   r&   s   0r   <module>r      s   1
    ( 1 > 
 O J 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
 7+	> ,	>. #453 632 7+	5 ,	5 7+
* ,
*F
R ! ~a()/	
		S Ms    
J<J<