gpt4 book ai didi

python - 如何禁用 scipy.optimize.basinhopping 中的局部最小化过程?

转载 作者:太空宇宙 更新时间:2023-11-03 12:59:28 25 4
gpt4 key购买 nike

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

enter image description here

最佳答案

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

请参阅关于“自定义最小化器”的讨论 in the documentation of minimize() :

 **Custom minimizers**It may be useful to pass a custom minimization method, for examplewhen 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 hasits 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 functionreturning 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` mayexpand in future versions and then these parameters will be passed tothe 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))

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

关于python - 如何禁用 scipy.optimize.basinhopping 中的局部最小化过程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27862152/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com