
    5[g'                         d dl Zd dlmZ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mZmZ  ej"                  d      d	        Zd
 Z G d d      Zy)    N)assert_allcloseassert_array_less)stats)sobol_indices)BootstrapResult)BootstrapSobolResult
f_ishigami	sample_AB
sample_A_Bsession)scopec                  
   d} d}d| dz  dz  z   |t         j                  dz  z  dz  z   |dz  t         j                  dz  z  dz  z   }d|t         j                  dz  z  dz  z   |dz  t         j                  dz  z  d	z  z   }| dz  dz  }d
}d
}|dz  t         j                  dz  z  dz  dz  }d
}t        j                  |||g      |z  }	t        j                  dd|g|d|g||dgg      |z  }
|	|
j                  d      z   }|	|fS )z_Reference values for Ishigami from Saltelli2007.

    Chapter 4, exercise 5 pages 179-182.
    g      @g?      ?               2   r      g           axis)nppiarraysum)abvarv1v2v3v12v13v23s_firsts_seconds_totals               f/var/www/html/bid-api/venv/lib/python3.12/site-packages/scipy/stats/tests/test_sensitivity_analysis.pyishigami_ref_indicesr+      s/    	AA
1Q,255!8A
%1RUUAXb(8
8C	qz!|	ad255!8mB.	.B	
AaB	
B
C
Q$ruuax-/#
C
ChhB|$S(Gxx	R	b#	c2  	H
 !,,GG    c                      t        |       }||fS )zOutput of shape (2, n).r	   xress     r*   f_ishigami_vecr2   *   s    
Q-C8Or,   c            
          e Zd Z ej                  ej                   dej                  z        gdz  Zd Ze	j                  j                  e	j                  j                  d      e	j                  j                  de e	j                  ee	j                  j"                        gdd	g
      d                      Zd Zd Zd Zd Ze	j                  j                  d      d        Zd Zy)TestSobolIndicesr   locscale   c                     t        j                  g dg dg dg      }|dz   }t        j                  g dg dg dgg dg dg dgg dg dg dgg      }t        ||      }t        ||       y )	N)r   r      
   )r   r   r      )r8      	      d   )e   h   k   n   )f   i   l   o   )g   j   m   p   AB)r   r   r
   r   )selfrN   rO   refABs        r*   test_sample_ABzTestSobolIndices.test_sample_AB6   s    HH

 Ghh" " "$%

 a C r,   z!Can't create large array for testfunc)marksscalarvector)idsc                    t         j                  j                  d      }t        |d| j                  |      }|j
                  dk(  r|d   |d   g|d   |d   gg}t        |j                  |d   d       t        |j                  |d   d       |j                  J |j                  d	
      }t        |t              sJ t        |j                  t              sJ |j                  j                  j                  j                   d   dk(  sJ |j                  j                  j                  d   j                   |j                  j                   k(  sJ |j                  j                  j                  j                   |j                  j                   k(  sJ |j                  j                  j                  j                   |j                  j                   k(  sJ t#        |j                  j                  j                  |j                         t#        |j                  |j                  j                  j$                         t#        |j                  j                  j                  |j                         t#        |j                  |j                  j                  j$                         t        |j                  dd	      t              sJ t        |j                  t              sJ y )N	   ;m~|W2LE    rT   ndistsrandom_stater2   r   r   {Gz?atolc   )n_resamplesr   g?)confidence_levelrd   )r   randomdefault_rngr   r^   __name__r   first_ordertotal_order_bootstrap_result	bootstrap
isinstancer   r   confidence_intervallowshaper   high)rP   r+   rT   rngr1   bootstrap_ress         r*   test_ishigamizTestSobolIndices.test_ishigamiM   s    ii##$JK**
 ==,,)!,.B1.EF)!,.B1.EF$ 
 	)=a)@tL)=a)@tL$$,,,"5-)=>>>#//AAA$$88<<BB1EJJJ$$88<<Q?EE//''( 	( ( ((<<@@FF//''( 	( (((<<@@FF//''( 	( ( 	%%99==s	
 	OO]66JJOO	
 	%%99==s	
 	OO]66JJOO	

 MM3BM? 
 	
 
 #//AAAr,   c                    t         j                  j                  d      }d}t        j                  t         j
                   dt         j
                  z        t        j                  t         j
                   dt         j
                  z        t        j                  t         j
                   dt         j
                  z        g}t        |||      \  }}t        ||      }t        |      j                  dd      t        |      j                  dd      t        |      j                  d	      d
}t        ||||      }	t        |	j                  |d   d       t        |||      }	t        |	j                  |d   d       y )NrZ   r[   r   r5   )r]   r^   r_   rM   r   )r8   r   rv   f_Af_Bf_ABr\   r   r`   ra   )rT   r]   r_   )r   rf   rg   r   uniformr   r   r
   r	   reshaper   r   ri   )
rP   r+   rr   r]   r^   rN   rO   rR   rT   r1   s
             r*   test_func_dictzTestSobolIndices.test_func_dict   s3   ii##$JKMMruufAbeeG4MMruufAbeeG4MMruufAbeeG4
 AU=1a  a=((B/a=((B/rN**:6
 

 	)=a)@tL
 	)=a)@tLr,   c           
         d t         j                  j                  d      }t        t        d| j
                  |      }t        |j                  |d   d       t        |j                  |d   d       d	t         j                  d
t         j                  dt         j                  dt        t         j                  t         j                  f   ffd}t        t        d| j
                  ||      }y )Nc                     t        j                  | |gd      }|dt        j                  ||z
  dz  d      z  z
  |z  }t        j                  | | |z
  z  d      |z  }|j                  |j                  fS )zaJansen for S and Sobol' for St.

            From Saltelli2010, table 2 formulations (c) and (e).)r   rv   r   r   r   rv   )r   r    meanT)rx   ry   rz   r    ssts         r*   jansen_sobolz2TestSobolIndices.test_method.<locals>.jansen_sobol   so     &&#s'2Cs277C$J?<<<CAcDj)3c9B339r,   rZ   r[   )rT   r]   r^   methodr_   r   r`   ra   r   rx   ry   rz   returnc                      | ||      S N )rx   ry   rz   r   s      r*   jansen_sobol_typedz8TestSobolIndices.test_method.<locals>.jansen_sobol_typed   s      S$//r,   r   )r   rf   rg   r   r	   r^   r   ri   rj   ndarraytuple)rP   r+   rr   r1   r   _r   s         @r*   test_methodzTestSobolIndices.test_method   s    		 ii##$JKt**	
 	)=a)@tL)=a)@tL	0	0"$**	046JJ	02::rzz)*	0
 q**%	
r,   c                     t         j                  j                  d      }t        d d| j                  |      }t        |j                  |d   d       t        |j                  |d   d       y )	NrZ   c                     t        |       dz   S )Ni  r.   r0   s    r*   <lambda>z5TestSobolIndices.test_normalization.<locals>.<lambda>   s    :a=4/r,   r[   r\   r   r`   ra   r   r   rf   rg   r   r^   r   ri   rj   rP   r+   rr   r1   s       r*   test_normalizationz#TestSobolIndices.test_normalization   s^    ii##$JK/4**
 	)=a)@tL)=a)@tLr,   c                    d }t         j                  j                  d      }t        |d| j                  |      }|d   g d|d   g|d   g d|d   gg}t        |j                  |d   d	       t        |j                  |d   d	       y )
Nc                 .    t        |       }||dz  dz   |fS )zOutput of shape (3, n).r   r;   r.   r/   s     r*   f_ishigami_vec_constzETestSobolIndices.test_constant_function.<locals>.f_ishigami_vec_const   s     Q-Ca"c))r,   rZ   r[   r\   r   )r   r   r   r   r`   ra   r   )rP   r+   r   rr   r1   ishigami_vec_indicess         r*   test_constant_functionz'TestSobolIndices.test_constant_function   s    	*
 ii##$JK%**
 &a()5I!5LM%a()5I!5LM 

 	)=a)@tL)=a)@tLr,   c                     t         j                  j                  d      }t        t        d| j
                  |      }t        |j                  |d   d       t        |j                  |d   d       y )NrZ   i   r\   r   g-C6?ra   r   )	r   rf   rg   r   r	   r^   r   ri   rj   r   s       r*   test_more_convergedz$TestSobolIndices.test_more_converged   s^    ii##$JKu**
 	)=a)@tL)=a)@tLr,   c                    d}t        j                  t        |      5  t        dt        d       d d d        t        j                  t        |      5  t        dt        d g       d d d        d}t        j                  t        |      5  t        dt        t        j                         g       d d d        t        j                  t        |      5  t        d	t        t        j                         g       d d d        d
}t        j                  t        |      5  t        dt        d       d d d        d}t        j                  t        |      5  t        dt        d        d d d        d}t        j                  t        |      5  t        dt               d d d        d }d}t        j                  t        |      5  t        d|t        j                         g       d d d        d}t        j                  t        |      5  t        dg g dt        j                         g       d d d        t        j                  t        |      5  t        dddgdgg dd       d d d        t        j                  t        |      5  t        dddgddgg dd       d d d        y # 1 sw Y   xY w# 1 sw Y   ]xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   bxY w# 1 sw Y   %xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   y xY w)Nz3Each distribution in `dists` must have method `ppf`)matchr   r{   )r]   rT   r^   c                     | S r   r   r   s    r*   r   z.TestSobolIndices.test_raises.<locals>.<lambda>       r,   z The balance properties of Sobol'r:   gffffff@z'toto' is not a valid 'method'toto)r]   rT   r   z!must have the following signaturec                     | S r   r   r   s    r*   r   z.TestSobolIndices.test_raises.<locals>.<lambda>  r   r,   z1'dists' must be defined when 'func' is a callable)r]   rT   c                 &    | j                  dd      S )Nrv   r   )r|   r   s    r*   func_wrong_shape_outputz=TestSobolIndices.test_raises.<locals>.func_wrong_shape_output  s    99R##r,   z!'func' output should have a shaper   zWhen 'func' is a dictionary)rx   rz   r   r8   )r   r=   r:   r   rw   r   )r   r=   r:   )pytestraises
ValueErrorr   r	   r   r{   )rP   messager   s      r*   test_raiseszTestSobolIndices.test_raises   sK   H]]:W5AJi@ 6 ]]:W5AJ{mD 6 6]]:W5AJu}}6GH 6 ]]:W5Cj8IJ 6 4]]:W5AJv> 6 7]]:W5AJ{C 6 G]]:W5AJ/ 6	$ 7]]:W51%--/9J 6
 1]]:W5"b1%--/9J 6
 ]]:W5VQCF 6 ]]:W5VQFIF 65_ 65 65 65 65 65 65 65 65 65
 65 65s   J7K&K&K"K+K8L"L%LL+L77KKKK(+K58LLLL(+L47M N)rh   
__module____qualname__r   r{   r   r   r^   rS   r   markxslowxfail_on_32bitparametrizer	   paramr2   slowrt   r}   r   r   r   r   r   r   r,   r*   r4   r4   0   s     	255&"%%0	
E!. [[[[ CD[[	\V\\.8H8HIJx   
1B E 1BfM>!
F	MM, [[ CD	M E	M7r,   r4   )numpyr   numpy.testingr   r   r   scipyr   scipy.statsr   scipy.stats._resamplingr   !scipy.stats._sensitivity_analysisr   r	   r
   r   fixturer+   r2   r4   r   r,   r*   <module>r      sQ     <   % 3 
 i  !8} }r,   