如何在 scipy.optimize.basinhopping 中禁用局部最小化进程?

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

我正在使用 scipy.optimize.basinhopping 来寻找标量函数的最小值。我想知道是否可以禁用 scipy.optimize.basinhopping 的局部最小化部分?从下面的输出信息可以看出,minimization_failuresnit 几乎相同,说明局部最小化部分对于 basinhopping 的全局优化过程可能是无用的——我想的原因为了提高效率,禁用局部最小化部分。

您可以使用 minimizer_kwargs 指定 minimize() 您更喜欢局部最小化步骤的选项。请参阅 docs.

的专用部分

然后取决于您要求 minimize 求解器的类型。您可以尝试设置更大的 tol 以使局部最小化步骤提前终止。

编辑,回复评论"What if I want to disable the local minimization part completely?"

文档中的 basinhopping 算法的工作原理如下:

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

如果以上是准确的,则无法完全跳过局部最小化步骤,因为算法需要其输出才能继续进行,即保留或丢弃新坐标。但是,我不是这个算法的专家。

您可以通过使用不执行任何操作的自定义最小化器来避免 运行 最小化器。

参见 "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.

基本上,您需要编写一个 returns 和 OptimizeResult 的自定义函数,并通过 minimizer_kwargsmethod 部分将其传递给 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))

注意:我不知道跳过局部最小化如何影响 basinhopping 算法的收敛特性。