
    \!h|                     r    S SK JrJr  S SKJr  S SKr S SKJr  \     SS j5       r
g! \	 a    S r Nf = f)    )combinationsproduct)	factorialN)nottestc                     U $ N )fs    oC:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\mlxtend/evaluate/permutation.pyr   r      s        c                    US;  a  [        SU-  5      e[        U[        5      (       a(  US;  a  [        S5      eUS:X  a  S nOUS:X  a  S nOS	 n[        R                  R                  U5      n[        U 5      [        U5      pU(       a=  X:w  a  [        S
5      e[        R                  " U5      n
[        R                  " U	5      nO[        R                  " X45      nSnU" X5      nUS:X  GaC  U(       a  [        SS/US9 Hu  n[        U5       H1  u  nnU(       a  UU   U U   sW
U'   WU'   M   U U   UU   sW
U'   WU'   M3     U" W
W5      nUU:  d  [        R                  " UU5      (       d  Mp  US-  nMw     SU	-  nX-  $ [        [        X-   5      U5       Hi  n[        X-   5       Vs/ s H  nUU;  d  M  UPM     nnU" W[        U5         UU   5      nUU:  d  [        R                  " UU5      (       d  Md  US-  nMk     [!        X-   5      [!        U5      [!        U	5      -  -  n X-  $ U(       a  [        U5       H  nUR#                  U5      S:  n[        U5       H1  u  nnU(       a  UU   U U   sW
U'   WU'   M   U U   UU   sW
U'   WU'   M3     U" W
W5      nUU:  d  [        R                  " UU5      (       d  M  US-  nM     US-  nUS-  nX-  $ [        U5       HK  nUR%                  W5        U" USU XS 5      nUU:  d  [        R                  " UU5      (       d  MF  US-  nMM     US-  nUS-  nX-  $ s  snf )aG  
Nonparametric permutation test

Parameters
-------------
x : list or numpy array with shape (n_datapoints,)
    A list or 1D numpy array of the first sample
    (e.g., the treatment group).

y : list or numpy array with shape (n_datapoints,)
    A list or 1D numpy array of the second sample
    (e.g., the control group).

func : custom function or str (default: 'x_mean != y_mean')
    function to compute the statistic for the permutation test.
    - If 'x_mean != y_mean', uses
      `func=lambda x, y: np.abs(np.mean(x) - np.mean(y)))`
       for a two-sided test.
    - If 'x_mean > y_mean', uses
      `func=lambda x, y: np.mean(x) - np.mean(y))`
       for a one-sided test.
    - If 'x_mean < y_mean', uses
      `func=lambda x, y: np.mean(y) - np.mean(x))`
       for a one-sided test.

method : 'approximate' or 'exact' (default: 'exact')
    If 'exact' (default), all possible permutations are considered.
    If 'approximate' the number of drawn samples is
    given by `num_rounds`.
    Note that 'exact' is typically not feasible unless the dataset
    size is relatively small.

paired : bool
    If True, a paired test is performed by only exchanging each
    datapoint with its associate.

num_rounds : int (default: 1000)
    The number of permutation samples if `method='approximate'`.

seed : int or None (default: None)
    The random seed for generating permutation samples if
    `method='approximate'`.

Returns
----------
p-value under the null hypothesis
Examples

-----------
For usage examples, please see
https://rasbt.github.io/mlxtend/user_guide/evaluate/permutation_test/

)approximateexactz/method must be "approximate" or "exact", got %s)x_mean != y_meanx_mean > y_meanzx_mean < y_meanzsProvide a custom function lambda x,y: ... or a string in ("x_mean != y_mean", "x_mean > y_mean", "x_mean < y_mean")r   c                     [         R                  " [         R                  " U 5      [         R                  " U5      -
  5      $ r   )npabsmeanxys     r   funcpermutation_test.<locals>.funch   s&    vvbggaj2771:566r   r   c                 \    [         R                  " U 5      [         R                  " U5      -
  $ r   r   r   r   s     r   r   r   m       wwqzBGGAJ..r   c                 \    [         R                  " U5      [         R                  " U 5      -
  $ r   r   r   s     r   r   r   r   r   r   z2x and y must have the same length if `paired=True`g        r   TF)repeatg      ?   N)AttributeError
isinstancestrr   randomRandomStatelen
ValueErroremptyhstackr   	enumerateiscloser   rangelistr   randnshuffle)r   r   r   method
num_roundsseedpairedrngmnsample_xsample_ycombinedat_least_as_extremereference_statflipir
   diff	indices_x	indices_ys                        r   permutation_testrA      s   @ --@6I
 	
 $QQ 8  ''7 &&/
/ ))


%Cq63q6q6TUU88A;88A; 99aV$!ZN  ua8%dODAq34Q410Xa[34Q410Xa[	 , Hh/.(BJJt^,L,L'3.' 9 AJT ++O *%,:	(-aeK18JQ	KHT)_5x	7JK.(BJJt^,L,L'3.' ; #15)Yq\IaL-HIJB ++= :&yy|c)%dODAq34Q410Xa[34Q410Xa[	 , Hh/.(BJJt^,L,L'3.' '  3&#J ++ :&H%HRaL(2,7.(BJJt^,L,L'3.' '  3&#J++M Ls   0
M
>M
)r   r   i  NF)	itertoolsr   r   mathr   numpyr   
nose.toolsr   ImportErrorrA   r	   r   r   <module>rG      sU    ,  " 	 
	q, 	q,  s   * 	66