'Calculate expected value of a function with respect to the
distribution.
The expected value of a function ``f(x)`` with respect to a
distribution ``dist`` is defined as::
ubound
E[x] = Integral(f(x) * dist.pdf(x))
lbound
Parameters
func : callable, optional
Function for which integral is calculated. Takes only one argument.
The default is the identity mapping f(x) = x.
args : tuple, optional
Shape parameters of the distribution.
loc : float, optional
Location parameter (default=0).
scale : float, optional
Scale parameter (default=1).
lb, ub : scalar, optional
Lower and upper bound for integration. Default is set to the
support of the distribution.
conditional : bool, optional
If True, the integral is corrected by the conditional probability
of the integration interval.  The return value is the expectation
of the function, conditional on being in the given interval.
Default is False.
Additional keyword arguments are passed to the integration routine.
Returns
expect : float
The calculated expected value.
Notes
The integration behavior of this function is inherited from
`integrate.quad`.'

def expect(self, func=None, args=(), loc=0, scale=1, lb=None, ub=None, conditional=False, **kwds):

    lockwds = {'loc': loc, 'scale': scale}
    self._argcheck(*args)
    if (func is None):
        def fun(x, *args):
            return (x * self.pdf(x, *args, **lockwds))
    else:
        def fun(x, *args):
            return (func(x) * self.pdf(x, *args, **lockwds))
    if (lb is None):
        lb = (loc + (self.a * scale))
    if (ub is None):
        ub = (loc + (self.b * scale))
    if conditional:
        invfac = (self.sf(lb, *args, **lockwds) - self.sf(ub, *args, **lockwds))
    else:
        invfac = 1.0
    kwds['args'] = args
    olderr = np.seterr(all='ignore')
    vals = (integrate.quad(fun, lb, ub, **kwds)[0] / invfac)
    np.seterr(**olderr)
    return vals
