U
    -e                     @   s  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
 d dlmZ d dlmZmZ dd gd d	gd	d	gd	d	ggZeeZd d	d	d	gZd
d	d d gZejdddgejdddgejdddgejdddgdd Zd2ddZdd ZdZd d! Zejd"d#ed$fgd%d& Zejd'ded	 gd(d) Zejd*ed+fd,gd-d. Zejd/ded	 gd0d1 ZdS )3    N)sparse)stats)LogisticRegression)	LinearSVC)l1_min_c)bounded_rand_int_wrapset_seed_wrap      losssquared_hingelogX_labelr   denseY_labeltwo-classesmulti-classintercept_labelno-interceptfit-interceptc           
      C   sT   t td}ttd}ddidddd}|| }|| }|| }	t||| f|	 d S )	N)r   r   )r   r   fit_interceptFT
   )r   intercept_scaling)r   r   )sparse_Xdense_XY1Y2check_l1_min_c)
r   r   r   r   ZXsZYsZ
interceptsXYZintercept_params r!   ^/var/www/html/Darija-Ai-Train/env/lib/python3.8/site-packages/sklearn/svm/tests/test_bounds.pytest_l1_min_c   s    

r#   T      ?c                 C   s   t | ||||d}tdddtddddd| }||_||_||_|| | t|j	d	k
 shtt|jd	k
 st|d
 |_|| | t|j	d	k st|jd	k std S )N)r   r   r   l1Z	liblinear)penaltyZsolverr   F)r   r&   Zdual)r   r   r   g)\(?)r   r   r   r   r   CfitnpZasarrayZcoef_allAssertionErrorZ
intercept_any)r   yr   r   r   Zmin_cZclfr!   r!   r"   r   $   s*    	

r   c               	   C   s<   ddgddgg} ddg}t t t| | W 5 Q R X d S )Nr   r
   )pytestraises
ValueErrorr   )r   r-   r!   r!   r"   test_ill_posed_min_c?   s    r1   l    c                      sF   dd t dD  tdd  D s(tt fdd D rBtdS )a  Test that bounded_rand_int_wrap without seeding respects the range

    Note this test should pass either if executed alone, or in conjunctions
    with other tests that call set_seed explicit in any order: it checks
    invariants on the RNG instead of specific values.
    c                 S   s   g | ]}t d qS )d   r   .0_r!   r!   r"   
<listcomp>P   s     z(test_newrand_default.<locals>.<listcomp>r   c                 s   s&   | ]}d |  kodk n  V  qdS )r   r2   Nr!   r5   xr!   r!   r"   	<genexpr>Q   s     z'test_newrand_default.<locals>.<genexpr>c                 3   s   | ]}| d  kV  qdS )r   Nr!   r8   	generatedr!   r"   r:   R   s     N)ranger*   r+   r!   r!   r;   r"   test_newrand_defaultI   s    r>   zseed, expected)r   6   	   c                 C   s    t |  td}||kstdS )z3Test that `set_seed` produces deterministic resultsr2   N)r   r   r+   )seedexpectedr<   r!   r!   r"   test_newrand_set_seedU   s    rC   rA   c              	   C   s"   t t t|  W 5 Q R X dS )z=Test that `set_seed_wrap` is defined for unsigned 32bits intsN)r.   r/   OverflowErrorr   )rA   r!   r!   r"   test_newrand_set_seed_overflow]   s    rE   zrange_, n_ptsi'  )r2      c                    s   t d d}g }tjd d}t|D ]4} fddt|D }t||j}||j q&tjddd}t||j}	|	jdkstd	|	j d
t	j
|dd}
|
dkstd|
 ddS )z;Test that `bounded_rand_int` follows a uniform distribution*   r2   r   )locscalec                    s   g | ]}t  qS r!   r3   r4   range_r!   r"   r7   p   s     z1test_newrand_bounded_rand_int.<locals>.<listcomp>r
   g?zNull hypothesis rejected: generated random numbers are not uniform. Details: the (meta) p-value of the test of uniform distribution of p-values is z which is not > 0.05r   )qzlNull hypothesis rejected: generated random numbers are not uniform. Details: lower 10th quantile p-value of z not > 0.05.N)r   r   uniformr=   ZkstestZcdfappendZpvaluer+   r)   Z
percentile)rK   Zn_ptsZn_iterZks_pvalsZuniform_distr6   sampleresZuniform_p_vals_distZ	res_pvalsZmin_10pct_pvalr!   rJ   r"   test_newrand_bounded_rand_intd   s"    

rQ   rK   c              	   C   s"   t t t|  W 5 Q R X dS )zETest that `bounded_rand_int_wrap` is defined for unsigned 32bits intsN)r.   r/   rD   r   rJ   r!   r!   r"   $test_newrand_bounded_rand_int_limits   s    rR   )Tr$   ) numpyr)   r.   Zscipyr   spr   Zsklearn.linear_modelr   Zsklearn.svmr   Zsklearn.svm._boundsr   Zsklearn.svm._newrandr   r   r   Z
csr_matrixr   r   r   markZparametrizer#   r   r1   Z_MAX_UNSIGNED_INTr>   rC   rE   rQ   rR   r!   r!   r!   r"   <module>   s8   




'