def expected_epsilon(q, err, bounds=None, pmf=em_pmf):
    foo = (lambda eps: (expected_error(q, eps, pmf) - err))
    if (bounds is None):
        eps = 1.0
        while (foo(eps) > 0):
            eps *= 2
        while (foo(eps) < 0):
            eps /= 2.0
        bounds = [eps, (2 * eps)]
    return root_scalar(foo, bracket=bounds, method='bisect').root
def expected_epsilon(q, err, bounds=None, pmf=em_pmf):
    foo = (lambda eps: (expected_error(q, eps, pmf) - err))
    if (bounds is None):
        eps = 1.0
        while (foo(eps) > 0):
            eps *= 2
        while (foo(eps) < 0):
            eps /= 2.0
        bounds = [eps, (2 * eps)]
    return root_scalar(foo, bracket=bounds, method='bisect').root