简体   繁体   English

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

[英]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. 我正在使用scipy.optimize.basinhopping来查找标量函数的最小值。 I wonder whether it is possible to disable the local minimization part of scipy.optimize.basinhopping? 我想知道是否有可能禁用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. 正如我们从下面的输出消息中可以看到的, minimization_failuresnit几乎相同,表明局部最小化部分对于流域购物的全局优化过程可能是无用的 - 这就是为什么我想禁用局部最小化部分,因为效率的缘故。

在此输入图像描述

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() : 请参阅minim()文档中有关“自定义最小化器”的讨论:

**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 基本上,你需要编写返回一个自定义函数OptimizeResult并将它传递给通过basinhopping method的一部分minimizer_kwargs ,例如

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. 您可以使用minimizer_kwargs指定minimize()您喜欢的局部最小化步骤的选项。 See the dedicated part of the docs . 请参阅文档的专用部分。

It is then up to what type of solver you ask minimize for. 然后由您要求minimize的求解器类型决定。 You can try setting a larger tol to make the local minimization step terminate earlier. 您可以尝试设置更大的tol以使本地最小化步骤更早终止。

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: 来自docs的流域购物算法的工作方式如下:

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. 但是,我不是这个算法的专家。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用scipy.optimize.basinhopping时'minimization_failures'的含义? - Meaning of 'minimization_failures' when using scipy.optimize.basinhopping? 了解scipy.optimize.basinhopping的输出 - Understanding the output of scipy.optimize.basinhopping 如何访问从 scipy.optimize.basinhopping(不最小化)返回的 OptimizeResult 实例的 `success` 属性? - How to access `success` attribute of OptimizeResult instance returned from scipy.optimize.basinhopping (NOT minimize)? scipy.optimize.basinhopping interval并接受测试合成器 - scipy.optimize.basinhopping interval and accept test syntaces 为什么 scipy.optimize.basinhopping 给出不同的结果 - why scipy.optimize.basinhopping give different results 使用python scipy.optimize.basinhopping在exp中溢出 - overflow in exp using python scipy.optimize.basinhopping 基于 scipy.optimize.basinhopping 中的 Levenberg-Marquardt 的自定义最小化器 - Custom minimizer based on Levenberg-Marquardt in scipy.optimize.basinhopping scipy.optimize.basinhopping 不调用 accept_test。 为什么? - scipy.optimize.basinhopping doesn't call accept_test. Why? 区分盆地跳跃中的本地/全局调用(scipy) - Distinguish the local/global invocation in basinhopping (scipy) scipy.optimize.basinhopping。 带参数的对象函数 - scipy.optimize.basinhopping. Object function with argument(s)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM