
    ZPh                        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             Zej                            dej        ej        ej        ej        g          ej                            d	g d
          ej                            dddg          ej                            dddg          d                                                 Zej                            dej        ej        ej        ej        g          ej                            d	g d
          ej                            dddg          ej                            dddg          d                                                 Zd Zd Zd Zd ZdS )z@Test for the metrics that perform pairwise distance computation.    N)NotFittedError)LabelEncoderOrdinalEncoder)_convert_container)ValueDifferenceMetricc                     t           j                            d          } dgdz  dgdz  z   dgdz  z   }dgdz  dgdz  z   }dgdz  dgdz  z   dgdz  z   d	gdz  z   }t          j        |||gt          
          j        }|                     |           |                     dd|j        d                   }t          j        ddgt          
          }||         }||fS )Nr   A
   B   C   (   Ddtype   )lowhighsize	not appleapple)	nprandomRandomStatearrayobjectTshufflerandintshape)rng	feature_1	feature_2	feature_3Xyy_labelss          d/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/imblearn/metrics/tests/test_pairwise.pydatar*      s    
)


"
"C
cURZ'3%"*4I
cURZ'I
cURZ'3%"*4urzAI
)Y	2&AAACAKKNNN
33Axg.f===HAa4K    r   zk, r))   r,   )r,   r   )r   r,   )r   r   y_typelistr   encode_labelTFc                 8   | \  }}t          ||          }|r!t                                          |          }t          |          }|                    |          }	t	          ||          }
|
                    |	|           |
                    |	          }|
                    |	|	          }t          j        	                    ||           |j
        |j
        d         |j
        d         fk    sJ |j
        |j
        d         |j
        d         fk    sJ d S )Nr   krr   )r   r   fit_transformr   r   fitpairwiser   testingassert_allcloser!   )r*   r   r2   r3   r-   r/   r&   r'   encoder	X_encodedvdmdist_1dist_2s                r)   test_value_difference_metricr>      s    DAq1f%%A ,NN((++5)))G%%a((I
!q
)
)
)CGGIq\\)$$F\\)Y//FJvv...<AGAJ
33333<AGAJ
3333333r+   c                 `   t          j        dgdz  dgdz  z   dgdz  z                                 dd          }t          j        dgdz  dgd	z  z   dgd
z  z   dgdz  z   dgz             }t          j        ddgt                    }||         }t	          ||          }|r!t                                          |          }t          |           }|                    |          }	t          ||          }
|
	                    |	|           |
                    dgg          }|
                    dgg          }|
                    dgg          }|||fD ]C}|
                    |                                          }|t          j        d          k    sJ D|
                    ||                                          }|
                    ||                                          }|
                    ||                                          }||k     sJ ||k     sJ ||k     sJ d S )Ngreenr
   redbluer,      r         	   r   r   r   r1   )r   r   reshaper   r   r   r4   r   r   r5   	transformr6   squeezepytestapprox)r   r2   r3   r-   r/   r&   r'   r(   r9   r:   r;   sample_green
sample_redsample_bluesampledistr<   r=   dist_3s                      r)   %test_value_difference_metric_propertyrS   :   s9     	'R5'B,.&B>??GGANNA
!qA37"aS1W,sQw6!<==Axg.f===HA1f%%A ,NN((++5)))G%%a((I
!q
)
)
)CGGIq$$wi[11L""UG9--J##fXJ//K[9 ( ( ||F##++--v}Q''''''' \\,
33;;==F\\+z22::<<F\\+|44<<>>F F????F????F??????r+   c                    | \  }}t          t          j                  }|                    |          }t          j        d |j        D                       }t                                          ||          }t          |          }|                    ||           t          j        	                    |j
        |           t          j        	                    |j
        |j
                   d S )Nr   c                 ,    g | ]}t          |          S  len.0cats     r)   
<listcomp>z;test_value_difference_metric_categories.<locals>.<listcomp>v       EEE#SXXEEEr+   n_categories)r   r   int32r4   r   categories_r   r5   r7   assert_array_equaln_categories_)r*   r&   r'   r9   r:   r_   vdm_autovdm_categoriess           r)   'test_value_difference_metric_categoriesrf   o   s     DAq28,,,G%%a((I8EE1DEEEFFL$&&**9a88H*EEENy!$$$J!!("8,GGGJ!!("8.:VWWWWWr+   c                 .   | \  }}t          t          j                  }|                    |          }ddg}t	          |          }d}t          j        t          |          5  |                    ||           d d d            d S # 1 swxY w Y   d S )Nr   r,   r   r^   z<The length of n_categories is not consistent with the number)match)	r   r   r`   r4   r   rK   raises
ValueErrorr5   )r*   r&   r'   r9   r:   r_   r;   err_msgs           r)   -test_value_difference_metric_categories_errorrl      s     DAq28,,,G%%a((Iq6L
\
:
:
:CLG	z	1	1	1  	1                 s   &B

BBc                 4   | \  }}t          t          j                  }|                    |          }t          j        d |j        D                       }d||d d df         dk    <   t          j                            t          j        |d d df                   g d           t          |          }|
                    ||           t          ||j                  D ]3\  }}|j        |t          t          j        |                    fk    sJ 4d S )Nr   c                 ,    g | ]}t          |          S rV   rW   rY   s     r)   r\   zCtest_value_difference_metric_missing_categories.<locals>.<listcomp>   r]   r+   r   rC   r,   )r   r      r^   )r   r   r`   r4   r   ra   r7   rb   uniquer   r5   zipproba_per_class_r!   rX   )	r*   r&   r'   r9   r:   r_   r;   n_catsprobas	            r)   /test_value_difference_metric_missing_categoriesru      s    DAq28,,,G%%a((I8EE1DEEEFFL ()Ii2!#$J!!")Iaaae,<"="=yyyIII
\
:
:
:CGGIq\3+?@@ : :{vs29Q<<'8'8999999: :r+   c                    | \  }}t          t          j                  }|                    |          }t	          j        t                    5  t                                          |           d d d            d S # 1 swxY w Y   d S )Nr   )	r   r   r`   r4   rK   ri   r   r   r6   )r*   r&   r'   r9   r:   s        r)   $test_value_difference_value_unfittedrw      s     DAq28,,,G%%a((I	~	&	& 4 4((3334 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4s   "A==BB)__doc__numpyr   rK   sklearn.exceptionsr   sklearn.preprocessingr   r   sklearn.utils._testingr   imblearn.metrics.pairwiser   fixturer*   markparametrizer`   int64float32float64r>   rS   rf   rl   ru   rw   rV   r+   r)   <module>r      s'   F F
      - - - - - - > > > > > > > > 5 5 5 5 5 5 ; ; ; ; ; ;    28RXrz2:"NOO!A!A!ABBFG#455$774 4 87 65 CB PO40 28RXrz2:"NOO!A!A!ABBFG#455$77. . 87 65 CB PO.bX X X"  : : :(	4 	4 	4 	4 	4r+   