U
    3d7                     @   s~  d dl Zd dlmZ d dlm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 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d1ddZdd ZdZejd 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d/d0 ZdS )2    N)sparse)stats)l1_min_c)	LinearSVC)LogisticRegression)set_seed_wrapbounded_rand_int_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!   A/tmp/pip-unpacked-wheel-zrfo1fqw/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   CZ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_cA   s    r0   l    z	seed, val)NQ   )r   6   	   c                 C   s:   | dk	rt |  td}||ks6td| d| ddS )z3Test that `set_seed` produces deterministic resultsNd   z	Expected z	 but got z instead)r   r   r*   )seedvalxr!   r!   r"   test_newrand_set_seedK   s    r8   r5   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   )r5   r!   r!   r"   test_newrand_set_seed_overflowT   s    r:   zrange_, n_ptsi'  )r4      c                    s   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 distributionr4   r   )locZscalec                    s   g | ]}t  qS r!   )r   ).0_range_r!   r"   
<listcomp>d   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   uniformrangeZkstestZcdfappendZpvaluer*   r(   Z
percentile)r@   Zn_ptsZn_iterZks_pvalsZuniform_distr>   sampleresZuniform_p_vals_distZ	res_pvalsZmin_10pct_pvalr!   r?   r"   test_newrand_bounded_rand_int[   s     

rH   r@   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.   r9   r   r?   r!   r!   r"   $test_newrand_bounded_rand_int_limits   s    rI   )Tr$   )Znumpyr(   Zscipyr   spr   r-   Zsklearn.svm._boundsr   Zsklearn.svmr   Zsklearn.linear_modelr   Zsklearn.svm._newrandr   r   r   Z
csr_matrixr   r   r   markZparametrizer#   r   r0   Z_MAX_UNSIGNED_INTr8   r:   rH   rI   r!   r!   r!   r"   <module>   s6   




$