<s> """<STR_LIT>""" <EOL> from __future__ import print_function <EOL> import warnings <EOL> import numpy as np <EOL> from numpy . testing import assert_almost_equal <EOL> from scipy import stats , special <EOL> from statsmodels . sandbox . distributions . extras import ( <EOL> lognormalg , squarenormalg , absnormalg , negsquarenormalg , squaretg ) <EOL> stats . distributions . rv_frozen . name = property ( lambda self : self . dist . name ) <EOL> def f_stats ( self , dfn , dfd ) : <EOL> arr , where , inf , sqrt , nan = np . array , np . where , np . inf , np . sqrt , np . nan <EOL> v2 = arr ( dfd * <NUM_LIT:1.0> ) <EOL> v1 = arr ( dfn * <NUM_LIT:1.0> ) <EOL> mu = where ( v2 > <NUM_LIT:2> , v2 / arr ( v2 - <NUM_LIT:2> ) , inf ) <EOL> mu2 = <NUM_LIT:2> * v2 * v2 * ( v2 + v1 - <NUM_LIT:2> ) / ( v1 * ( v2 - <NUM_LIT:2> ) ** <NUM_LIT:2> * ( v2 - <NUM_LIT:4> ) ) <EOL> mu2 = where ( v2 > <NUM_LIT:4> , mu2 , inf ) <EOL> g1 = <NUM_LIT:2> * ( v2 + <NUM_LIT:2> * v1 - <NUM_LIT> ) / ( v2 - <NUM_LIT> ) * np . sqrt ( <NUM_LIT:2> * ( v2 - <NUM_LIT> ) / ( v1 * ( v2 + v1 - <NUM_LIT> ) ) ) <EOL> g1 = where ( v2 > <NUM_LIT:6> , g1 , nan ) <EOL> g2 = <NUM_LIT:3> / ( <NUM_LIT> * v2 - <NUM_LIT:16> ) * ( <NUM_LIT:8> + g1 * g1 * ( v2 - <NUM_LIT> ) ) <EOL> g2 = where ( v2 > <NUM_LIT:8> , g2 , nan ) <EOL> return mu , mu2 , g1 , g2 <EOL> stats . f . __class__ . _stats = f_stats <EOL> def foldnorm_stats ( self , c ) : <EOL> arr , where , inf , sqrt , nan = np . array , np . where , np . inf , np . sqrt , np . nan <EOL> exp = np . exp <EOL> pi = np . pi <EOL> fac = special . erf ( c / sqrt ( <NUM_LIT:2> ) ) <EOL> mu = sqrt ( <NUM_LIT> / pi ) * exp ( - <NUM_LIT:0.5> * c * c ) + c * fac <EOL> mu2 = c * c + <NUM_LIT:1> - mu * mu <EOL> c2 = c * c <EOL> g1 = sqrt ( <NUM_LIT:2> / pi ) * exp ( - <NUM_LIT> * c2 ) * ( <NUM_LIT:4> - pi * exp ( c2 ) * ( <NUM_LIT:2> * c2 + <NUM_LIT:1.0> ) ) <EOL> g1 += <NUM_LIT:2> * c * fac * ( <NUM_LIT:6> * exp ( - c2 ) + <NUM_LIT:3> * sqrt ( <NUM_LIT:2> * pi ) * c * exp ( - c2 / <NUM_LIT> ) * fac + pi * c * ( fac * fac - <NUM_LIT:1> ) ) <EOL> g1 /= pi * mu2 ** <NUM_LIT> <EOL> g2 = c2 * c2 + <NUM_LIT:6> * c2 + <NUM_LIT:3> + <NUM_LIT:6> * ( c2 + <NUM_LIT:1> ) * mu * mu - <NUM_LIT:3> * mu ** <NUM_LIT:4> <EOL> g2 -= <NUM_LIT:4> * exp ( - c2 / <NUM_LIT> ) * mu * ( sqrt ( <NUM_LIT> / pi ) * ( c2 + <NUM_LIT:2> ) + c * ( c2 + <NUM_LIT:3> ) * exp ( c2 / <NUM_LIT> ) * fac ) <EOL> g2 /= mu2 ** <NUM_LIT> <EOL> g2 -= <NUM_LIT> <EOL> return mu , mu2 , g1 , g2 <EOL> stats . foldnorm . __class__ . _stats = foldnorm_stats <EOL> DECIMAL = <NUM_LIT:5> <EOL> class Test_Transf2 ( object ) : <EOL> def __init__ ( self ) : <EOL> self . dist_equivalents = [ <EOL> ( squarenormalg , stats . chi2 ( <NUM_LIT:1> ) ) , <EOL> ( absnormalg , stats . halfnorm ) , <EOL> ( absnormalg , stats . foldnorm ( <NUM_LIT> ) ) , <EOL> ( squaretg ( <NUM_LIT:10> ) , stats . f ( <NUM_LIT:1> , <NUM_LIT:10> ) ) <EOL> ] <EOL> l , s = <NUM_LIT:0.0> , <NUM_LIT:1.0> <EOL> self . ppfq = [ <NUM_LIT:0.1> , <NUM_LIT:0.5> , <NUM_LIT> ] <EOL> self . xx = [ <NUM_LIT> , <NUM_LIT:1.0> , <NUM_LIT> ] <EOL> self . nxx = [ - <NUM_LIT> , - <NUM_LIT:1.0> , - <NUM_LIT> ] <EOL> def test_equivalent ( self ) : <EOL> xx , ppfq = self . xx , self . ppfq <EOL> for d1 , d2 in self . dist_equivalents : <EOL> assert_almost_equal ( d1 . cdf ( xx ) , d2 . cdf ( xx ) , err_msg = '<STR_LIT>' + d1 . name ) <EOL> assert_almost_equal ( d1 . pdf ( xx ) , d2 . pdf ( xx ) , <EOL> err_msg = '<STR_LIT>' + d1 . name + d2 . name ) <EOL> assert_almost_equal ( d1 . sf ( xx ) , d2 . sf ( xx ) , <EOL> err_msg = '<STR_LIT>' + d1 . name + d2 . name ) <EOL> assert_almost_equal ( d1 . ppf ( ppfq ) , d2 . ppf ( ppfq ) , <EOL> err_msg = '<STR_LIT>' + d1 . name + d2 . name ) <EOL> assert_almost_equal ( d1 . isf ( ppfq ) , d2 . isf ( ppfq ) , <EOL> err_msg = '<STR_LIT>' + d1 . name + d2 . name ) <EOL> self . d1 = d1 <EOL> self . d2 = d2 <EOL> if hasattr ( d2 , '<STR_LIT>' ) : <EOL> d2mom = d2 . dist . moment ( <NUM_LIT:3> , * d2 . args ) <EOL> else : <EOL> d2mom = d2 . moment ( <NUM_LIT:3> ) <EOL> assert_almost_equal ( d1 . moment ( <NUM_LIT:3> ) , d2mom , <EOL> DECIMAL , <EOL> err_msg = '<STR_LIT>' + d1 . name + d2 . name ) <EOL> orig_filter = warnings . filters [ : ] <EOL> warnings . simplefilter ( '<STR_LIT:ignore>' ) <EOL> try : <EOL> s1 = d1 . stats ( moments = '<STR_LIT>' ) <EOL> s2 = d2 . stats ( moments = '<STR_LIT>' ) <EOL> finally : <EOL> warnings . filters = orig_filter <EOL> assert_almost_equal ( s1 [ : <NUM_LIT:2> ] , s2 [ : <NUM_LIT:2> ] , <EOL> err_msg = '<STR_LIT>' + d1 . name + d2 . name ) <EOL> assert_almost_equal ( s1 [ <NUM_LIT:2> : ] , s2 [ <NUM_LIT:2> : ] , <EOL> decimal = <NUM_LIT:2> , <EOL> err_msg = '<STR_LIT>' + d1 . name + d2 . name ) <EOL> def test_equivalent_negsq ( self ) : <EOL> xx , nxx , ppfq = self . xx , self . nxx , self . ppfq <EOL> d1 , d2 = ( negsquarenormalg , stats . chi2 ( <NUM_LIT:1> ) ) <EOL> assert_almost_equal ( d1 . cdf ( nxx ) , <NUM_LIT:1> - d2 . cdf ( xx ) , err_msg = '<STR_LIT>' + d1 . name ) <EOL> assert_almost_equal ( d1 . pdf ( nxx ) , d2 . pdf ( xx ) ) <EOL> assert_almost_equal ( d1 . sf ( nxx ) , <NUM_LIT:1> - d2 . sf ( xx ) ) <EOL> assert_almost_equal ( d1 . ppf ( ppfq ) , - d2 . ppf ( ppfq ) [ : : - <NUM_LIT:1> ] ) <EOL> assert_almost_equal ( d1 . isf ( ppfq ) , - d2 . isf ( ppfq ) [ : : - <NUM_LIT:1> ] ) <EOL> assert_almost_equal ( d1 . moment ( <NUM_LIT:3> ) , - d2 . moment ( <NUM_LIT:3> ) ) <EOL> ch2oddneg = [ v * ( - <NUM_LIT:1> ) ** ( i + <NUM_LIT:1> ) for i , v in <EOL> enumerate ( d2 . stats ( moments = '<STR_LIT>' ) ) ] <EOL> assert_almost_equal ( d1 . stats ( moments = '<STR_LIT>' ) , ch2oddneg , <EOL> err_msg = '<STR_LIT>' + d1 . name + d2 . name ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> tt = Test_Transf2 ( ) <EOL> tt . test_equivalent ( ) <EOL> tt . test_equivalent_negsq ( ) <EOL> debug = <NUM_LIT:0> <EOL> if debug : <EOL> print ( negsquarenormalg . ppf ( [ <NUM_LIT:0.1> , <NUM_LIT:0.5> , <NUM_LIT> ] ) ) <EOL> print ( stats . chi2 . ppf ( [ <NUM_LIT:0.1> , <NUM_LIT:0.5> , <NUM_LIT> ] , <NUM_LIT:1> ) ) <EOL> print ( negsquarenormalg . a ) <EOL> print ( negsquarenormalg . b ) <EOL> print ( absnormalg . stats ( moments = '<STR_LIT>' ) ) <EOL> print ( stats . foldnorm ( <NUM_LIT> ) . stats ( moments = '<STR_LIT>' ) ) <EOL> print ( stats . halfnorm . stats ( moments = '<STR_LIT>' ) ) </s>
