o
    i                     @   sl   d dl Z d dl mZmZ d dlZd dlmZm	Z	m
Z
 d dlmZ d dlmZ G dd dZG dd	 d	ZdS )
    N)raiseswarns)assert_approx_equalassert_allcloseassert_equal)cdist)statsc                   @   sb   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Ze	j
dddgdd Zdd Zdd ZdS )TestMGCErrorWarningsz1 Tests errors and warnings derived from MGC.
    c                 C   s8   t d}dgd }tttj|| tttj|| d S )N      nparangeassert_raises
ValueErrorr   multiscale_graphcorrselfxy r   T/home/kim/smarthome/.venv/lib/python3.10/site-packages/scipy/stats/tests/test_mgc.pytest_error_notndarray   s   

z*TestMGCErrorWarnings.test_error_notndarrayc                 C   s2   t ddd}|dd}tttj|| d S )Nd         
   )r   r   Zreshaper   r   r   r   r   r   r   r   test_error_shape   s   z%TestMGCErrorWarnings.test_error_shapec                 C   s(   t d}t d}tttj|| d S )N   r   r   r   r   r   test_error_lowsamples   s   

z*TestMGCErrorWarnings.test_error_lowsamplesc                 C   sF   t jdtd}t j|d< tttj|| t d}tttj|| d S )Nr
   )Zdtyper   )r   r   floatnanr   r   r   r   r   r   r   r   test_error_nans    s
   

z$TestMGCErrorWarnings.test_error_nansc                 C   &   t d}d}tttj|||d d S )Nr
   r   )compute_distancer   )r   r   r$   r   r   r   test_error_wrongdisttype)   s
   

z-TestMGCErrorWarnings.test_error_wrongdisttypereps1c                 C   s"   t d}tttj|||d d S )Nr
   r&   r   )r   r&   r   r   r   r   test_error_reps0   s   
z$TestMGCErrorWarnings.test_error_repsc                 C   r#   )Nr
   r   r)   )r   r   assert_warnsRuntimeWarningr   r   )r   r   r&   r   r   r   test_warns_reps9   s   
z$TestMGCErrorWarnings.test_warns_repsc                 C   s.   t d}t dt j }tttj|| d S )Nr
   )r   r   Zonesinfr   r   r   r   r   r   r   r   test_error_infty?   s   
z%TestMGCErrorWarnings.test_error_inftyN)__name__
__module____qualname____doc__r   r   r   r"   r%   pytestmarkparametrizer*   r-   r/   r   r   r   r   r	   
   s    	
r	   c                   @   s   e Zd ZdZdddZejjejdg dd	d
 Z	ejjejdddgdd Z
ejjdd Zejjdd Zejjdd Zejjdd Zejdejjdd Zejjdd ZdS )TestMGCStatz) Test validity of MGC test statistic
    r       c                 C   sp  |dkrt jjdd|dfd}|dt jj|jdfd  }n||dkrQt t jjdd|dfd}|t t j|  }|t t j|  d	t jj|jdfd  }nI|d
krt jj	dd|dfd}t jj	dd|dfd}t jj
dd|dfd}	t jj
dd|dfd}
|d d|	  d }|d d|
  d }ntd|dkrt jj	dd||d fd}t j||fdd}||fS )Nlinearr'   r8   sizeg333333?	nonlinearr   r   g?independence      ?)pr<   r      z3sim_type must be linear, nonlinear, or independence)Zaxis)r   randomuniformZrandom_sampler<   arraycospisinnormalbinomialr   Zconcatenate)r   sampsdimssim_typer   r   ZunifuvZu_2Zv_2Z
dims_noiser   r   r   _simulationsI   s*   zTestMGCStat._simulationszsim_type, obs_stat, obs_pvalue))r:   
ףp=
?MbP?)r=   w/?rQ   )r>   gUN@g(\?c           	      C   sR   t jd | jdd|d\}}t||\}}}t||dd t||dd d S )NNa r   r8   rJ   rK   rL   Zsignificantr   rB   seedrO   r   r   r   	r   rL   Zobs_statZ
obs_pvaluer   r   statpvalue_r   r   r   	test_onedk   s
   zTestMGCStat.test_oned)r:   gZd;O?rQ   )r=   g~jt?gʡE?c           	      C   sR   t jd | jdd|d\}}t||\}}}t||dd t||dd d S )NrS   r   r   rT   r8   rU   rV   rX   r   r   r   
test_fived|   s
   zTestMGCStat.test_fivedc                 C   s   t jd t jjdddd}t jjdddd}t||\}}}t|d	dd
 t|ddd
 t jjdddd}tj||dd\}}}t|d	dd
 t|ddd
 d S )NrS   r   r?   )r   r   r;   r   r8   )P   r   g      ?rU   rQ   T)Z
is_twosamp)r   rB   rW   rI   rH   r   r   r   r   r   r   rY   rZ   r[   r   r   r   test_twosamp   s   zTestMGCStat.test_twosampc                 C   sV   t jd | jdddd\}}tj||dd\}}}t|ddd	 t|d
dd	 d S )NrS   r   r8   r:   rT   rA   )workersrP   rU   rQ   rV   r_   r   r   r   test_workers   s
   zTestMGCStat.test_workersc                 C   sJ   | j dddd\}}tj||dd\}}}t|ddd t|ddd d S )	Nr   r8   r:   rT   random_staterP   rU   rQ   )rO   r   r   r   r_   r   r   r   test_random_state   s   zTestMGCStat.test_random_statec                 C   st   t jd | jdddd\}}t||dd}t||dd}tj||d dd\}}}t|d	dd
 t|ddd
 d S )NrS   r   r8   r=   rT   Z	euclidean)Zmetric)r$   rd   rR   rU   rQ   )r   rB   rW   rO   r   r   r   r   )r   r   r   ZdistxZdistyZ	stat_distZpvalue_distr[   r   r   r   test_dist_perm   s   zTestMGCStat.test_dist_permr
   c                 C   sD   t jd | jdddd\}}tj||dd\}}}t|d d S )NrS   r   r8   r:   rT   rc   g'^P?)r   rB   rW   rO   r   r   r   )r   r   r   r[   rZ   r   r   r   test_pvalue_literature   s   z"TestMGCStat.test_pvalue_literaturec                 C   sB   t jd | jdddd\}}tj||dd}t|j|j d S )NrS   r   r8   r:   rT   rc   )	r   rB   rW   rO   r   r   r   rY   Z	statistic)r   r   r   resr   r   r   
test_alias   s   zTestMGCStat.test_aliasN)r   r8   r9   )r0   r1   r2   r3   rO   r4   r5   Zxslowr6   r\   r]   r`   rb   re   rf   Z	fail_slowZslowrg   ri   r   r   r   r   r7   F   s2    
"


	


r7   )r4   r   r   r   r+   numpyr   Znumpy.testingr   r   r   Zscipy.spatial.distancer   Zscipyr   r	   r7   r   r   r   r   <module>   s    <