bundles / scipy latest / scipy / stats / _continuous_distns / vonmises_gen / expect
function
scipy.stats._continuous_distns:vonmises_gen.expect
Signature
def expect ( self , func = None , args = () , loc = 0 , scale = 1 , lb = None , ub = None , conditional = False , ** kwds ) Summary
Calculate expected value of a function with respect to the distribution by numerical integration.
Extended Summary
The expected value of a function f(x) with respect to a distribution dist is defined as
ub E[f(x)] = Integral(f(x) * dist.pdf(x)), lb
where ub and lb are arguments and x has the dist.pdf(x) distribution. If the bounds lb and ub correspond to the support of the distribution, e.g. [-inf, inf] in the default case, then the integral is the unrestricted expectation of f(x). Also, the function f(x) may be defined such that f(x) is 0 outside a finite interval in which case the expectation is calculated within the finite range [lb, ub].
Parameters
func: callable, optionalFunction for which integral is calculated. Takes only one argument. The default is the identity mapping f(x) = x.
args: tuple, optionalShape parameters of the distribution.
loc: float, optionalLocation parameter (default=0).
scale: float, optionalScale parameter (default=1).
lb, ub: scalar, optionalLower and upper bound for integration. Default is set to the support of the distribution.
conditional: bool, optionalIf 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: floatThe calculated expected value.
Notes
The integration behavior of this function is inherited from scipy.integrate.quad. Neither this function nor scipy.integrate.quad can verify whether the integral exists or is finite. For example cauchy(0).mean() returns np.nan and cauchy(0).expect() returns 0.0.
Likewise, the accuracy of results is not verified by the function. scipy.integrate.quad is typically reliable for integrals that are numerically favorable, but it is not guaranteed to converge to a correct value for all possible intervals and integrands. This function is provided for convenience; for critical applications, check results against other integration methods.
The function is not vectorized.
Examples
To understand the effect of the bounds of integration considerfrom scipy.stats import expon
✓expon(1).expect(lambda x: 1, lb=0.0, ub=2.0)
✗expon(1).cdf(2.0) - expon(1).cdf(0.0)
✗expon(1).expect(lambda x: 1, lb=0.0, ub=2.0, conditional=True)
✗import numpy as np from scipy.stats import vonmises res = vonmises(loc=2, kappa=1).expect(lambda x: np.exp(1j*x), complex_func=True)✓
res
✗np.angle(res) # location of the (circular) distribution
✗Aliases
-
scipy.stats._continuous_distns.vonmises_gen.expect