#NEWLINE# def expect_mc( dist , func = ( lambda x : 1 ) , size = 50000 ) : #NEWLINE# #INDENT# "calculate expected value of function by Monte Carlo integration\n\n    Parameters\n    ----------\n    dist : distribution instance\n        needs to have rvs defined as a method for drawing random numbers\n    func : callable\n        function for which expectation is calculated, this function needs to\n        be vectorized, integration is over axis=0\n    size : int\n        number of random samples to use in the Monte Carlo integration,\n\n\n    Notes\n    -----\n    this doesn't batch\n\n    Returns\n    -------\n    expected value : ndarray\n        return of function func integrated over axis=0 by MonteCarlo, this will\n        have the same shape as the return of func without axis=0\n\n    Examples\n    --------\n\n    integrate probability that both observations are negative\n\n    >>> mvn = mve.MVNormal([0,0],2.)\n    >>> mve.expect_mc(mvn, lambda x: (x<np.array([0,0])).all(-1), size=100000)\n    0.25306000000000001\n\n    get tail probabilities of marginal distribution (should be 0.1)\n\n    >>> c = stats.norm.isf(0.05, scale=np.sqrt(2.))\n    >>> expect_mc(mvn, lambda x: (np.abs(x)>np.array([c, c])), size=100000)\n    array([ 0.09969,  0.0986 ])\n\n    or calling the method\n\n    >>> mvn.expect_mc(lambda x: (np.abs(x)>np.array([c, c])), size=100000)\n    array([ 0.09937,  0.10075])\n\n\n    " #NEWLINE# def fun( x ) : #NEWLINE# #INDENT# return func ( x ) #NEWLINE# #UNINDENT# rvs = dist . rvs ( size = dist ) #NEWLINE# return fun ( rvs ) . mean ( 0 )