B
    Zvd                 @   s:  d Z ddlZddlZddlmZ ddlmZmZ ddl	m
Z
 ddlmZ ejdd Zejd	ejejejejgejd
ddddgejdddgejdddgdd Zejd	ejejejejgejd
ddddgejdddgejdddgdd Zdd Zdd Zdd Zdd  ZdS )!z@Test for the metrics that perform pairwise distance computation.    N)NotFittedError)LabelEncoderOrdinalEncoder)_convert_container)ValueDifferenceMetricc              C   s   t jd} dgd dgd  dgd  }dgd dgd  }dgd dgd  dgd  d	gd  }t j|||gtd
j}| | | jdd|jd d}t jddgtd
}|| }||fS )Nr   A
   B   C   (   D)dtype   )lowhighsizez	not appleapple)	nprandomZRandomStatearrayobjectTshufflerandintshape)rngZ	feature_1Z	feature_2Z	feature_3Xyy_labels r!   V/var/www/html/venv/lib/python3.7/site-packages/imblearn/metrics/tests/test_pairwise.pydata   s    (
r#   r   zk, r)   r$   )r$   r   )r   r$   )r   r   y_typelistr   encode_labelTFc             C   s   | \}}t ||}|r"t |}t|d}||}	t||d}
|
|	| |
|	}|
|	|	}tj	|| |j
|j
d |j
d fkst|j
|j
d |j
d fkstd S )N)r   )krr   )r   r   fit_transformr   r   fitpairwiser   testingZassert_allcloser   AssertionError)r#   r   r(   r)   r%   r'   r   r   encoder	X_encodedvdmdist_1dist_2r!   r!   r"   test_value_difference_metric   s    	



r4   c             C   s|  t dgd dgd  dgd  dd}t dgd dgd	  dgd
  dgd  dg }t jddgtd}|| }t||}|rt |}t| d}||}	t||d}
|
	|	| |
dgg}|
dgg}|
dgg}x2|||fD ]$}|
| }|tdkstqW |
|| }|
|| }|
|| }||k s\t||k sjt||k sxtd S )Ngreenr   redbluer$      r         	   z	not appler   )r   )r(   r)   )r   r   Zreshaper   r   r   r*   r   r   r+   Z	transformr,   ZsqueezepytestZapproxr.   )r   r(   r)   r%   r'   r   r   r    r/   r0   r1   Zsample_greenZ
sample_redZsample_bluesampledistr2   r3   Zdist_3r!   r!   r"   %test_value_difference_metric_property:   s.    ,4


r@   c             C   s~   | \}}t tjd}||}tdd |jD }t ||}t|d}||| tj	|j
| tj	|j
|j
 d S )N)r   c             S   s   g | ]}t |qS r!   )len).0catr!   r!   r"   
<listcomp>v   s    z;test_value_difference_metric_categories.<locals>.<listcomp>)n_categories)r   r   int32r*   r   categories_r   r+   r-   assert_array_equalZn_categories_)r#   r   r   r/   r0   rE   Zvdm_autoZvdm_categoriesr!   r!   r"   'test_value_difference_metric_categorieso   s    

rI   c          	   C   s^   | \}}t tjd}||}ddg}t|d}d}tjt|d ||| W d Q R X d S )N)r   r$   r   )rE   z<The length of n_categories is not consistent with the number)match)	r   r   rF   r*   r   r=   raises
ValueErrorr+   )r#   r   r   r/   r0   rE   r1   err_msgr!   r!   r"   -test_value_difference_metric_categories_error   s    

rN   c       	      C   s   | \}}t tjd}||}tdd |jD }d||d d df dk< tjt|d d df dddg t	|d	}|
|| x4t||jD ]$\}}|j|tt|fkstqW d S )
N)r   c             S   s   g | ]}t |qS r!   )rA   )rB   rC   r!   r!   r"   rD      s    zCtest_value_difference_metric_missing_categories.<locals>.<listcomp>r   r8   r$   r      )rE   )r   r   rF   r*   r   rG   r-   rH   uniquer   r+   zipZproba_per_class_r   rA   r.   )	r#   r   r   r/   r0   rE   r1   Zn_catsZprobar!   r!   r"   /test_value_difference_metric_missing_categories   s    
&
rR   c          	   C   sD   | \}}t tjd}||}tt t | W d Q R X d S )N)r   )	r   r   rF   r*   r=   rK   r   r   r,   )r#   r   r   r/   r0   r!   r!   r"   $test_value_difference_value_unfitted   s
    
rS   )__doc__numpyr   r=   Zsklearn.exceptionsr   Zsklearn.preprocessingr   r   Zsklearn.utils._testingr   Zimblearn.metrics.pairwiser   Zfixturer#   markZparametrizerF   Zint64Zfloat32Zfloat64r4   r@   rI   rN   rR   rS   r!   r!   r!   r"   <module>   s&     2