6.3.9.5.3. statsmodels.sandbox.distributions.mv_normal.expect_mc_bounds

statsmodels.sandbox.distributions.mv_normal.expect_mc_bounds(dist, func=<function <lambda>>, size=50000, lower=None, upper=None, conditional=False, overfact=1.2)[source]

calculate expected value of function by Monte Carlo integration

Parameters:

dist : distribution instance

needs to have rvs defined as a method for drawing random numbers

func : callable

function for which expectation is calculated, this function needs to be vectorized, integration is over axis=0

size : int

minimum number of random samples to use in the Monte Carlo integration, the actual number used can be larger because of oversampling.

lower : None or array_like

lower integration bounds, if None, then it is set to -inf

upper : None or array_like

upper integration bounds, if None, then it is set to +inf

conditional : bool

If true, then the expectation is conditional on being in within [lower, upper] bounds, otherwise it is unconditional

overfact : float

oversampling factor, the actual number of random variables drawn in each attempt are overfact * remaining draws. Extra draws are also used in the integration.

Returns:

expected value : ndarray

return of function func integrated over axis=0 by MonteCarlo, this will have the same shape as the return of func without axis=0

Notes

this doesn’t batch

Examples

>>> mvn = mve.MVNormal([0,0],2.)
>>> mve.expect_mc_bounds(mvn, lambda x: np.ones(x.shape[0]),
                            lower=[-10,-10],upper=[0,0])
0.24990416666666668

get 3 marginal moments with one integration

>>> mvn = mve.MVNormal([0,0],1.)
>>> mve.expect_mc_bounds(mvn, lambda x: np.dstack([x, x**2, x**3, x**4]),
    lower=[-np.inf,-np.inf], upper=[np.inf,np.inf])
array([[  2.88629497e-03,   9.96706297e-01,  -2.51005344e-03,
          2.95240921e+00],
       [ -5.48020088e-03,   9.96004409e-01,  -2.23803072e-02,
          2.96289203e+00]])
>>> from scipy import stats
>>> [stats.norm.moment(i) for i in [1,2,3,4]]
[0.0, 1.0, 0.0, 3.0]