
    _Mh)                         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dS )    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  }
|	|
                    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               k/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/scipy/stats/tests/test_sensitivity_analysis.pyishigami_ref_indicesr+      s,    	AA
1Q,25!8A
%1RUAXb(8
8C	qz!|	ad25!8mB.	.B	
AaB	
B
C
Q$ruax-/#
C
ChB|$$S(Gx	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
                            d          e	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
                            d          d             Zd ZdS )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          ||           d S )	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    H]]]]]]
 

 Gh"""mmmm mm"""mm mmmm"""$%

 

 a   C     r,   z!Can't create large array for testfunc)marksscalarvector)idsc                    t           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 |
                    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          |
                    dd	          t                    sJ t          |j	        t                    sJ d S )N	   ;m~|W2LE    rT   ndistsrngr2   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   r_   r1   bootstrap_ress         r*   test_ishigamizTestSobolIndices.test_ishigamiM   s    i##$JKK*
 
 
 =,,,)!,.B1.EF)!,.B1.EF$ 
 	)=a)@tLLLL)=a)@tLLLL$,,,"55-)=>>>>>#/AAAAA$8<B1EJJJJ$8<Q?E/'( ( ( ( (<@F/'( ( ( ((<@F/'( ( ( ( 	%9=s	
 	
 	
 	O]6JO	
 	
 	
 	%9=s	
 	
 	
 	O]6JO	
 	
 	

 MM3BM?? 
 
 	
 	
 	
 #/AAAAAAAr,   c                 |   t           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          |          	                    dd          t          |          	                    dd          t          |          	                    d	          d
}t          ||||          }	t          |	j        |d         d           t          |||          }	t          |	j        |d         d           t          t          |          	                    dd          |d                    t          t          |          	                    dd          |d                    t          t          |          	                    d	          |d                    d S )NrZ   r[   r   r5   )r]   r^   r_   rM   r   )r8   r   ru   f_Af_Bf_ABr\   r   r`   ra   )rT   r]   r_   rw   rx   ry   )r   rf   rg   r   uniformr   r   r
   r	   reshaper   r   ri   )
rP   r+   r_   r]   r^   rN   rO   rR   rT   r1   s
             r*   test_func_dictzTestSobolIndices.test_func_dict   s   i##$JKKMrufAbeG444MrufAbeG444MrufAbeG444
 AU4441a    a==((B//a==((B//rNN**:66
 
 
 
 

 	)=a)@tLLLL
 
 
 	)=a)@tLLLL 	
1--a44d5kBBB
1--a44d5kBBB
2..z::DLIIIIIr,   c           
         d t           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        ||          }d S )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   ru   r   r   r   ru   )r   r    meanT)rw   rx   ry   r    ssts         r*   jansen_sobolz2TestSobolIndices.test_method.<locals>.jansen_sobol   sw     &#s'222Cs27C$J?<<<<<CAcDj)333c9B39r,   rZ   r[   )rT   r]   r^   methodr_   r   r`   ra   r   rw   rx   ry   returnc                      | ||          S N )rw   rx   ry   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+   r_   r1   r   _r   s         @r*   test_methodzTestSobolIndices.test_method   s   		 		 		 i##$JKKt*	
 
 
 	)=a)@tLLLL)=a)@tLLLL	0	0"$*	046J	02:rz)*	0 	0 	0 	0 	0 	0
 q*%	
 
 
r,   c                     t           j                            d          }t          d d| j        |          }t          |j        |d         d           t          |j        |d         d           d S )	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+   r_   r1   s       r*   test_normalizationz#TestSobolIndices.test_normalization   s~    i##$JKK//4*
 
 
 	)=a)@tLLLL)=a)@tLLLLLLr,   c                 :   d }t           j                            d          }t          |d| j        |          }|d         g d|d         g|d         g d|d         gg}t          |j        |d         d	           t          |j        |d         d	           d S )
Nc                 6    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   r_   r1   ishigami_vec_indicess         r*   test_constant_functionz'TestSobolIndices.test_constant_function   s    	* 	* 	*
 i##$JKK%*
 
 
 &a()))5I!5LM%a()))5I!5LM 

 	)=a)@tLLLL)=a)@tLLLLLLr,   c                     t           j                            d          }t          t          d| j        |          }t          |j        |d         d           t          |j        |d         d           d S )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{    i##$JKKu*
 
 
 	)=a)@tLLLL)=a)@tLLLLLLr,   c                    d}t          j        t          |          5  t          dt          d           d d d            n# 1 swxY w Y   t          j        t          |          5  t          dt          d g           d d d            n# 1 swxY w Y   d}t          j        t          |          5  t          dt          t          j                    g           d d d            n# 1 swxY w Y   t          j        t          |          5  t          d	t          t          j                    g           d d d            n# 1 swxY w Y   d
}t          j        t          |          5  t          dt          d           d d d            n# 1 swxY w Y   d}t          j        t          |          5  t          dt          d            d d d            n# 1 swxY w Y   d}t          j        t          |          5  t          dt                     d d d            n# 1 swxY w Y   d }d}t          j        t          |          5  t          d|t          j                    g           d d d            n# 1 swxY w Y   d}t          j        t          |          5  t          dg g dt          j                    g           d d d            n# 1 swxY w Y   t          j        t          |          5  t          dddgdgg dd           d d d            n# 1 swxY w Y   t          j        t          |          5  t          dddgddgg dd           d d d            d S # 1 swxY w Y   d S )Nz3Each distribution in `dists` must have method `ppf`)matchr   rz   )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                 .    |                      dd          S )Nru   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)rw   ry   r   r8   )r   r=   r:   r   rv   r   )r   r=   r:   )pytestraises
ValueErrorr   r	   r   rz   )rP   messager   s      r*   test_raiseszTestSobolIndices.test_raises   s   H]:W555 	A 	AAJi@@@@	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A ]:W555 	E 	EAJ{{mDDDD	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 6]:W555 	I 	IAJu}6GHHHH	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I ]:W555 	K 	KCj8IJJJJ	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 4]:W555 	? 	?AJv>>>>	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 7]:W555 	D 	DAJ{{CCCC	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D G]:W555 	0 	0AJ////	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0	$ 	$ 	$ 7]:W555 	 	1%-//9J   	 	 	 	 	 	 	 	 	 	 	 	 	 	 	
 1]:W555 	 	"b11%-//9J   	 	 	 	 	 	 	 	 	 	 	 	 	 	 	
 ]:W555 	 	VQCFF   	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ]:W555 	 	VQFIIIFF   	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   AA	A(BBB6*C,,C03C0*EEE0FFF<G!!G%(G%	H,,H03H0%JJJ0(K$$K(+K(
L11L58L5N  NNN)rh   
__module____qualname__r   rz   r   r   r^   rS   r   markxslowxfail_on_32bitparametrizer	   paramr2   slowrs   r|   r   r   r   r   r   r   r,   r*   r4   r4   0   sh        	25&"%000	
E! ! !. [[ CDD[	\V\.8HIIIJx    
1B 1B  ED 1Bf&J &J &JP!
 !
 !
F	M 	M 	MM M M, [ CDD	M 	M ED	M7 7 7 7 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      s       < < < < < < < <        % % % % % % 3 3 3 3 3 3           
 i     ! 8  F F F F F F F F F Fr,   