简体   繁体   中英

How to disable the local minimization process in scipy.optimize.basinhopping?

I am using scipy.optimize.basinhopping for finding the minima of a scalar function. I wonder whether it is possible to disable the local minimization part of scipy.optimize.basinhopping? As we can see from the output message below, minimization_failures and nit are nearly the same, indicating that the local minimization part may be useless for the global optimization process of basinhopping --- reason why I would like to disable the local minimization part, for the sake of efficiency.

在此输入图像描述

You can avoid running the minimizer by using a custom minimizer that does nothing.

See the discussion on "Custom minimizers" in the documentation of minimize() :

**Custom minimizers**
It may be useful to pass a custom minimization method, for example
when using a frontend to this method such as `scipy.optimize.basinhopping`
or a different library. You can simply pass a callable as the ``method``
parameter.
The callable is called as ``method(fun, x0, args, **kwargs, **options)``
where ``kwargs`` corresponds to any other parameters passed to `minimize`
(such as `callback`, `hess`, etc.), except the `options` dict, which has
its contents also passed as `method` parameters pair by pair. Also, if
`jac` has been passed as a bool type, `jac` and `fun` are mangled so that
`fun` returns just the function values and `jac` is converted to a function
returning the Jacobian. The method shall return an ``OptimizeResult``
object.
The provided `method` callable must be able to accept (and possibly ignore)
arbitrary parameters; the set of parameters accepted by `minimize` may
expand in future versions and then these parameters will be passed to
the method. You can find an example in the scipy.optimize tutorial.

Basically, you need to write a custom function that returns an OptimizeResult and pass it to basinhopping via the method part of minimizer_kwargs , for example

from scipy.optimize import OptimizeResult
def noop_min(fun, x0, args, **options):
    return OptimizeResult(x=x0, fun=fun(x0), success=True, nfev=1)

...

sol = basinhopping(..., minimizer_kwargs=dict(method=noop_min))

Note: I don't know how skipping local minimization affects the convergence properties of the basinhopping algorithm.

You can use minimizer_kwargs to specify to minimize() what options your prefer to the local minimization step. See the dedicated part of the docs .

It is then up to what type of solver you ask minimize for. You can try setting a larger tol to make the local minimization step terminate earlier.

EDIT, in reply to the comment "What if I want to disable the local minimization part completely?"

The basinhopping algorithm from the docs works like:

The algorithm is iterative with each cycle composed of the following features

  • random perturbation of the coordinates
  • local minimization accept or
  • reject the new coordinates based on the minimized function value

If the above is accurate there is no way to skip the local minimization step entirely, because its output is required by the algorithm to proceed further, ie keep or discard the new coordinate. However, I am not an expert of this algorithm.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM