def logEI_gaussian(mean, var, thresh):
    """Return log(EI(mean, var, thresh))

    This formula avoids underflow in cdf for
        thresh >= mean + 37 * sqrt(var)

    """
    assert np.asarray(var).min() >= 0
    sigma = np.sqrt(var)
    score = (mean - thresh) / sigma
    n = scipy.stats.norm
    try:
        float(mean)
        is_scalar = True
    except __HOLE__:
        is_scalar = False

    if is_scalar:
        if score < 0:
            pdf = n.logpdf(score)
            r = np.exp(np.log(-score) + n.logcdf(score) - pdf)
            rval = np.log(sigma) + pdf + np.log1p(-r)
            if not np.isfinite(rval):
                return -np.inf
            else:
                return rval
        else:
            return np.log(sigma) + np.log(score * n.cdf(score) + n.pdf(score))
    else:
        score = np.asarray(score)
        rval = np.zeros_like(score)

        olderr = np.seterr(all='ignore')
        try:
            negs = score < 0
            nonnegs = np.logical_not(negs)
            negs_score = score[negs]
            negs_pdf = n.logpdf(negs_score)
            r = np.exp(np.log(-negs_score)
                       + n.logcdf(negs_score)
                       - negs_pdf)
            rval[negs] = np.log(sigma[negs]) + negs_pdf + np.log1p(-r)
            nonnegs_score = score[nonnegs]
            rval[nonnegs] = np.log(sigma[nonnegs]) + np.log(
                nonnegs_score * n.cdf(nonnegs_score) + n.pdf(nonnegs_score))
            rval[np.logical_not(np.isfinite(rval))] = -np.inf
        finally:
            np.seterr(**olderr)
        return rval
dataset/ETHPy150Open hyperopt/hyperopt/hyperopt/criteria.py/logEI_gaussian