o
    tBh&                     @   sR  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	d
 ZeedddjZeg djZejee dkedZee Z ej!ej"edZ#de#e dk < de#e dke dk @ < de#e dk< e
dddZ$e
dde$e
dddedde
ddd gZ%dd e%D Z&ej'(de%dd Z)dd  Z*ej'(de&d!d" Z+ej'(de%d#d$ Z,ej'(de%d%d& Z-ej'(de&d'd( Z.ej'(de%d)d* Z/d+d, Z0ej'(de&d-d. Z1ej'(de%d/d0 Z2ej'(de%d1d2 Z3d3d4 Z4ej'(d5dedie5d6fgd7d8 Z6dS )9z,Testing for Gaussian process classification     N)approx_fprime)GaussianProcessClassifier)RBFCompoundKernelConstantKernelWhiteKernel)MiniSeqKernel)ConvergenceWarning)assert_almost_equalassert_array_equalc                 C   s
   t | S )N)npsin)x r   ~/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/sklearn/gaussian_process/tests/test_gpc.pyf   s   
r   
      )       @g      @g      @g      @g      @dtypegffffffֿ   gffffff?         ?fixedlength_scalelength_scale_boundsg?)r   )MbP?     @@g{Gz?      Y@c                 C   s   g | ]}|t kr|qS r   )fixed_kernel).0kernelr   r   r   
<listcomp>/   s    r%   r$   c                 C   s<   t | dtt}t|t|td d df dk d S )Nr$   r         ?)r   fitXyr   predictpredict_probar$   gpcr   r   r   test_predict_consistent2   s   *r/   c                  C   s\   g d} t g d}tdd}t|d| |}t|| || d d df dk d S )N)AABB)TFTr   )baseline_similarity_boundsr&   r   r'   )r   arrayr   r   r(   r   r+   r,   )r)   r*   r$   r.   r   r   r   "test_predict_consistent_structured9   s
   
*r5   c                 C   s4   t | dtt}||jj|| jksJ d S )Nr&   )r   r(   r)   r*   log_marginal_likelihoodkernel_thetar-   r   r   r   test_lml_improvingB   s   r9   c                 C   s0   t | dtt}t||jj| d d S )Nr&      )r   r(   r)   r*   r
   r6   r7   r8   r-   r   r   r   test_lml_precomputedK   s   r;   c                 C   sJ   t | dtt}tj|jjjtj	d}|j
|dd t|jj|d d S )Nr&   r   F)clone_kernelr:   )r   r(   r)   r*   r   onesr7   r8   shapefloat64r6   r
   )r$   r.   input_thetar   r   r   test_lml_without_cloning_kernelT   s   rA   c                 C   sz   t | dtt}||jjd\}}tt	|dk |jj|jj
d d df kB |jj|jj
d d df kB s;J d S )Nr&   T-C6?r   r   )r   r(   r)   r*   r6   r7   r8   r   allabsbounds)r$   r.   lmllml_gradientr   r   r   test_converged_to_local_maximum^   s   rH   c                    sJ   t | dtt  | jd\}}t| j fddd}t||d d S )Nr&   Tc                    s     | dS )NF)r6   )r8   r.   r   r   <lambda>s   s    z#test_lml_gradient.<locals>.<lambda>g|=   )r   r(   r)   r*   r6   r8   r   r
   )r$   rF   rG   lml_gradient_approxr   rI   r   test_lml_gradientl   s   rM   c            
      C   s   d\} }t jd}|| |d d }t |jddt d| jdd dk}tddtd	g| d
g| d }t j }t	dD ]#}t
||dd||}||jj}	|	|t t jj ksdJ |	}qCd S )N)   r   r   r   r   )axisrK   r   r    r   )rB   r!   r      )r$   n_restarts_optimizerrandom_state)r   randomRandomStaterandnr   sumCr   infranger   r(   r6   r7   r8   finfofloat32eps)
	n_samples
n_featuresrngr)   r*   r$   last_lmlrQ   gprF   r   r   r   test_random_startsy   s$   ,
rb   c                 C   sB   dd }t | |d}|tt ||jj|| jksJ d S )Nc           	      S   s   t jd}|| |dd}}tdD ].}t |t d|d d df t d|d d df }| |dd}||k rA||}}q||fS )Nr   F)eval_gradientr   r   )r   rS   rT   rY   
atleast_1duniformmaximumminimum)	obj_funcinitial_thetarE   r_   	theta_optfunc_min_r8   r   r   r   r   	optimizer   s   
2
z(test_custom_optimizer.<locals>.optimizer)r$   rn   )r   r(   r)   y_mcr6   r7   r8   )r$   rn   r.   r   r   r   test_custom_optimizer   s   rp   c                 C   sP   t | d}|tt |t}t|dd |t}t	t
|d| d S )Nr&   r   )r   r(   r)   ro   r,   X2r
   rV   r+   r   r   argmax)r$   r.   y_proby_predr   r   r   test_multi_class   s   


ru   c                 C   sP   t | d}|tt t | dd}|tt |t}|t}t|| d S )Nr&   r   )r$   n_jobs)r   r(   r)   ro   r,   rq   r
   )r$   r.   gpc_2rs   y_prob_2r   r   r   test_multi_class_n_jobs   s   


ry   c            	      C   s   t ddgd} t| d}d}tjt|d |tt W d    n1 s&w   Y  tddgdt dd	gd }t|d}t	j
d
dG}t	d |tt t|dksXJ t|d jtsbJ |d jjd dksnJ t|d jtsxJ |d jjd dksJ W d    n1 sw   Y  ttd}t ddgddgd}t|d}t	j
d
dH}t	d ||t t|dksJ t|d jtsJ |d jjd dksJ t|d jtsJ |d jjd dksJ W d    d S 1 sw   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$   r.   warning_message
kernel_sumgpc_sumr}   X_tilekernel_dimsgpc_dimsr   r   r   test_warning_bounds   sP   


	


	
"r   zparams, error_type, err_msgz!kernel cannot be a CompoundKernelc                 C   sN   t di | }tj||d |tt W d   dS 1 s w   Y  dS )z0Check that expected error are raised during fit.rz   Nr   )r   r   raisesr(   r)   r*   )params
error_typeerr_msgr.   r   r   r   test_gpc_fit_error  s   "r   )7__doc__r   numpyr   scipy.optimizer   r   sklearn.gaussian_processr    sklearn.gaussian_process.kernelsr   r   r   rW   r   4sklearn.gaussian_process.tests._mini_sequence_kernelr   sklearn.exceptionsr	   sklearn.utils._testingr
   r   r   
atleast_2dlinspaceTr)   rq   r4   ravelintr*   fXemptyr>   ro   r"   kernelsnon_fixed_kernelsmarkparametrizer/   r5   r9   r;   rA   rH   rM   rb   rp   ru   ry   r   
ValueErrorr   r   r   r   r   <module>   sp    

	


	




M

