{ } Raw JSON

bundles / scipy 1.17.1 / scipy / stats / _continuous_distns / vonmises_gen / expect

function

scipy.stats._continuous_distns:vonmises_gen.expect

source: /scipy/stats/_continuous_distns.py :11211

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, 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 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 consider
from scipy.stats import expon
expon(1).expect(lambda x: 1, lb=0.0, ub=2.0)
This is close to
expon(1).cdf(2.0) - expon(1).cdf(0.0)
If ``conditional=True``
expon(1).expect(lambda x: 1, lb=0.0, ub=2.0, conditional=True)
The slight deviation from 1 is due to numerical integration. The integrand can be treated as a complex-valued function by passing ``complex_func=True`` to `scipy.integrate.quad` .
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
The default limits of integration are endpoints of the interval of width ``2*pi`` centered at `loc` (e.g. ``[-pi, pi]`` when ``loc=0``).

Aliases

  • scipy.stats._continuous_distns.vonmises_gen.expect