

def minimize_scalar(fun, bracket=None, bounds=None, args=(), method='brent', tol=None, options=None):
    "Minimization of scalar function of one variable.\n\n    Parameters\n    ----------\n    fun : callable\n        Objective function.\n        Scalar function, must return a scalar.\n    bracket : sequence, optional\n        For methods 'brent' and 'golden', `bracket` defines the bracketing\n        interval and can either have three items `(a, b, c)` so that `a < b\n        < c` and `fun(b) < fun(a), fun(c)` or two items `a` and `c` which\n        are assumed to be a starting interval for a downhill bracket search\n        (see `bracket`); it doesn't always mean that the obtained solution\n        will satisfy `a <= x <= c`.\n    bounds : sequence, optional\n        For method 'bounded', `bounds` is mandatory and must have two items\n        corresponding to the optimization bounds.\n    args : tuple, optional\n        Extra arguments passed to the objective function.\n    method : str or callable, optional\n        Type of solver.  Should be one of\n\n            - 'Brent'     :ref:`(see here) <optimize.minimize_scalar-brent>`\n            - 'Bounded'   :ref:`(see here) <optimize.minimize_scalar-bounded>`\n            - 'Golden'    :ref:`(see here) <optimize.minimize_scalar-golden>`\n            - custom - a callable object (added in version 0.14.0),\n              see below\n    tol : float, optional\n        Tolerance for termination. For detailed control, use solver-specific\n        options.\n    options : dict, optional\n        A dictionary of solver options.\n            maxiter : int\n                Maximum number of iterations to perform.\n            disp : bool\n                Set to True to print convergence messages.\n\n        See :func:`show_options()` for solver-specific options.\n\n    Returns\n    -------\n    res : OptimizeResult\n        The optimization result represented as a ``OptimizeResult`` object.\n        Important attributes are: ``x`` the solution array, ``success`` a\n        Boolean flag indicating if the optimizer exited successfully and\n        ``message`` which describes the cause of the termination. See\n        `OptimizeResult` for a description of other attributes.\n\n    See also\n    --------\n    minimize : Interface to minimization algorithms for scalar multivariate\n        functions\n    show_options : Additional options accepted by the solvers\n\n    Notes\n    -----\n    This section describes the available solvers that can be selected by the\n    'method' parameter. The default method is *Brent*.\n\n    Method :ref:`Brent <optimize.minimize_scalar-brent>` uses Brent's\n    algorithm to find a local minimum.  The algorithm uses inverse\n    parabolic interpolation when possible to speed up convergence of\n    the golden section method.\n\n    Method :ref:`Golden <optimize.minimize_scalar-golden>` uses the\n    golden section search technique. It uses analog of the bisection\n    method to decrease the bracketed interval. It is usually\n    preferable to use the *Brent* method.\n\n    Method :ref:`Bounded <optimize.minimize_scalar-bounded>` can\n    perform bounded minimization. It uses the Brent method to find a\n    local minimum in the interval x1 < xopt < x2.\n\n    **Custom minimizers**\n\n    It may be useful to pass a custom minimization method, for example\n    when using some library frontend to minimize_scalar.  You can simply\n    pass a callable as the ``method`` parameter.\n\n    The callable is called as ``method(fun, args, **kwargs, **options)``\n    where ``kwargs`` corresponds to any other parameters passed to `minimize`\n    (such as `bracket`, `tol`, etc.), except the `options` dict, which has\n    its contents also passed as `method` parameters pair by pair.  The method\n    shall return an ``OptimizeResult`` object.\n\n    The provided `method` callable must be able to accept (and possibly ignore)\n    arbitrary parameters; the set of parameters accepted by `minimize` may\n    expand in future versions and then these parameters will be passed to\n    the method.  You can find an example in the scipy.optimize tutorial.\n\n    .. versionadded:: 0.11.0\n\n    Examples\n    --------\n    Consider the problem of minimizing the following function.\n\n    >>> def f(x):\n    ...     return (x - 2) * x * (x + 2)**2\n\n    Using the *Brent* method, we find the local minimum as:\n\n    >>> from scipy.optimize import minimize_scalar\n    >>> res = minimize_scalar(f)\n    >>> res.x\n    1.28077640403\n\n    Using the *Bounded* method, we find a local minimum with specified\n    bounds as:\n\n    >>> res = minimize_scalar(f, bounds=(-3, -1), method='bounded')\n    >>> res.x\n    -2.0000002026\n\n    "
    if (not isinstance(args, tuple)):
        args = (args,)
    if callable(method):
        meth = '_custom'
    else:
        meth = method.lower()
    if (options is None):
        options = {
            
        }
    if (tol is not None):
        options = dict(options)
        if ((meth == 'bounded') and ('xatol' not in options)):
            warn("Method 'bounded' does not support relative tolerance in x; defaulting to absolute tolerance.", RuntimeWarning)
            options['xatol'] = tol
        elif (meth == '_custom'):
            options.setdefault('tol', tol)
        else:
            options.setdefault('xtol', tol)
    if (meth == '_custom'):
        return method(fun, args=args, bracket=bracket, bounds=bounds, **options)
    elif (meth == 'brent'):
        return _minimize_scalar_brent(fun, bracket, args, **options)
    elif (meth == 'bounded'):
        if (bounds is None):
            raise ValueError('The `bounds` parameter is mandatory for method `bounded`.')
        return _minimize_scalar_bounded(fun, bounds, args, **options)
    elif (meth == 'golden'):
        return _minimize_scalar_golden(fun, bracket, args, **options)
    else:
        raise ValueError(('Unknown solver %s' % method))

dataset/ETHPy150Open scipy/scipy/scipy/optimize/_minimize.py minimize_scalar/original