如何在scipy.optimize.basinhopping中禁用本地最小化过程?

我正在使用scipy.optimize.basinhopping来查找标量函数的最小值.我想知道是否有可能禁用scipy.optimize.basinhopping的局部最小化部分?正如我们从下面的输出消息中可以看到的,minimization_failures和nit几乎相同,表明局部最小化部分对于流域购物的全局优化过程可能是无用的 – 这就是为什么我想禁用局部最小化部分,因为效率的缘故. 最佳答案 您可以通过使用不执行任何操作的自定义最小化程序来避免运行最小化程序.

请参阅“自定义最小化器”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.

基本上,您需要编写一个返回OptimizeResult的自定义函数,并通过minimizer_kwargs的方法部分将其传递给basinhopping,例如

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))

注意:我不知道跳过局部最小化如何影响流水线算法的收敛性.

点赞