def _opt_1d(funcs, start, L1_wt, tol):
    """
    Optimize a L1-penalized smooth one-dimensional function of a
    single variable.

    Parameters
    ----------
    funcs : tuple of functions
        funcs[0] is the objective function to be minimized.  funcs[1]
        and funcs[2] are, respectively, the first and second
        derivatives of the smooth part of funcs[0] (i.e. excluding the
        L1 penalty).
    start : real
        A starting value for the function argument
    L1_wt : non-negative real
        The weight for the L1 penalty function.
    tol : non-negative real
        A convergence threshold.

    Returns
    -------
    The argmin of the objective function.
    """

    # TODO: can we detect failures without calling funcs[0] twice?

    x = start
    f = funcs[0](x)

    b = funcs[1](x)
    c = funcs[2](x)
    d = b - c*x

    if L1_wt > np.abs(d):
        return 0.
    elif d >= 0:
        x += (L1_wt - b) / c
    elif d < 0:
        x -= (L1_wt + b) / c

    f1 = funcs[0](x)

    # This is an expensive fall-back if the quadratic
    # approximation is poor and sends us far off-course.
    if f1 > f + 1e-10:
        return brent(funcs[0], brack=(x-0.2, x+0.2), tol=tol)

    return x
dataset/ETHPy150Open statsmodels/statsmodels/statsmodels/duration/hazard_regression.py/_opt_1d/original