#NEWLINE# def tukeylambda_variance( lam ) : #NEWLINE# #INDENT# 'Variance of the Tukey Lambda distribution.\n\n    Parameters\n    ----------\n    lam : array_like\n        The lambda values at which to compute the variance.\n\n    Returns\n    -------\n    v : ndarray\n        The variance.  For lam < -0.5, the variance is not defined, so\n        np.nan is returned.  For lam = 0.5, np.inf is returned.\n\n    Notes\n    -----\n    In an interval around lambda=0, this function uses the [4,4] Pade\n    approximation to compute the variance.  Otherwise it uses the standard\n    formula (http://en.wikipedia.org/wiki/Tukey_lambda_distribution).  The\n    Pade approximation is used because the standard formula has a removable\n    discontinuity at lambda = 0, and does not produce accurate numerical\n    results near lambda = 0.\n    ' #NEWLINE# lam = np . asarray ( lam ) #NEWLINE# shp = lam . shape #NEWLINE# lam = np . atleast_1d ( lam ) . astype ( np . float64 ) #NEWLINE# threshold = 0.075 #NEWLINE# low_mask = ( lam < ( - 0.5 ) ) #NEWLINE# neghalf_mask = ( lam == ( - 0.5 ) ) #NEWLINE# small_mask = ( np . abs ( lam ) < threshold ) #NEWLINE# reg_mask = ( ~ ( ( low_mask | neghalf_mask ) | small_mask ) ) #NEWLINE# small = lam [ small_mask ] #NEWLINE# reg = lam [ reg_mask ] #NEWLINE# v = np . empty_like ( lam ) #NEWLINE# v [ low_mask ] = np . nan #NEWLINE# v [ neghalf_mask ] = np . inf #NEWLINE# if ( small . size > 0 ) : #NEWLINE# #INDENT# v [ small_mask ] = ( _tukeylambda_var_p ( small ) / _tukeylambda_var_q ( small ) ) #NEWLINE# #UNINDENT# if ( reg . size > 0 ) : #NEWLINE# #INDENT# v [ reg_mask ] = ( ( 2.0 / ( reg ** 2 ) ) * ( ( 1.0 / ( 1.0 + ( 2 * reg ) ) ) - beta ( ( reg + 1 ) , ( reg + 1 ) ) ) ) #NEWLINE# #UNINDENT# v . shape = shp #NEWLINE# return v