#NEWLINE# def expect_v2( self , fn = None , args = ( ) , loc = 0 , scale = 1 , lb = None , ub = None , conditional = False ) : #NEWLINE# #INDENT# "calculate expected value of a function with respect to the distribution\n\n    location and scale only tested on a few examples\n\n    Parameters\n    ----------\n        all parameters are keyword parameters\n        fn : function (default: identity mapping)\n           Function for which integral is calculated. Takes only one argument.\n        args : tuple\n           argument (parameters) of the distribution\n        lb, ub : numbers\n           lower and upper bound for integration, default is set using\n           quantiles of the distribution, see Notes\n        conditional : boolean (False)\n           If true then the integral is corrected by the conditional probability\n           of the integration interval. The return value is the expectation\n           of the function, conditional on being in the given interval.\n\n    Returns\n    -------\n        expected value : float\n\n    Notes\n    -----\n    This function has not been checked for it's behavior when the integral is\n    not finite. The integration behavior is inherited from scipy.integrate.quad.\n\n    The default limits are lb = self.ppf(1e-9, *args), ub = self.ppf(1-1e-9, *args)\n\n    For some heavy tailed distributions, 'alpha', 'cauchy', 'halfcauchy',\n    'levy', 'levy_l', and for 'ncf', the default limits are not set correctly\n    even  when the expectation of the function is finite. In this case, the\n    integration limits, lb and ub, should be chosen by the user. For example,\n    for the ncf distribution, ub=1000 works in the examples.\n\n    There are also problems with numerical integration in some other cases,\n    for example if the distribution is very concentrated and the default limits\n    are too large.\n\n    " #NEWLINE# if ( fn is None ) : #NEWLINE# #INDENT# def fun( x , * args ) : #NEWLINE# #INDENT# return ( ( loc + ( x * scale ) ) * self . _pdf ( x , * args ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# def fun( x , * args ) : #NEWLINE# #INDENT# return ( fn ( ( loc + ( x * scale ) ) ) * self . _pdf ( x , * args ) ) #NEWLINE# #UNINDENT# #UNINDENT# if ( lb is None ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# lb = self . ppf ( 1e-09 , * loc ) #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# lb = self . a #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# lb = max ( self . a , ( ( lb - loc ) / ( 1.0 * scale ) ) ) #NEWLINE# #UNINDENT# if ( ub is None ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# ub = self . ppf ( ( 1 - 1e-09 ) , * args ) #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# ub = self . b #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# ub = min ( self . b , ( ( ub - loc ) / ( 1.0 * scale ) ) ) #NEWLINE# #UNINDENT# if conditional : #NEWLINE# #INDENT# invfac = ( self . _sf ( lb , * args ) - self . _sf ( ub , * args ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# invfac = 1.0 #NEWLINE# #UNINDENT# return ( integrate . quad ( fun , lb , ub , args = args , limit = 500 ) [ 0 ] / invfac )