[英]Meaning of 'minimization_failures' when using scipy.optimize.basinhopping?
[英]How to disable the local minimization process in scipy.optimize.basinhopping?
我正在使用scipy.optimize.basinhopping
來查找標量函數的最小值。 我想知道是否有可能禁用scipy.optimize.basinhopping的局部最小化部分? 正如我們從下面的輸出消息中可以看到的, minimization_failures
和nit
幾乎相同,表明局部最小化部分對於流域購物的全局優化過程可能是無用的 - 這就是為什么我想禁用局部最小化部分,因為效率的緣故。
您可以通過使用不執行任何操作的自定義最小化程序來避免運行最小化程序。
請參閱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.
基本上,你需要編寫返回一個自定義函數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))
注意:我不知道跳過局部最小化如何影響流水線算法的收斂性。
您可以使用minimizer_kwargs
指定minimize()
您喜歡的局部最小化步驟的選項。 請參閱文檔的專用部分。
然后由您要求minimize
的求解器類型決定。 您可以嘗試設置更大的tol
以使本地最小化步驟更早終止。
編輯,回復評論“如果我想完全禁用本地最小化部分怎么辦?”
來自docs的流域購物算法的工作方式如下:
該算法是迭代的,每個循環由以下特征組成
- 隨機擾動坐標
- 局部最小化接受或
- 根據最小化的函數值拒絕新坐標
如果以上是准確的,則無法完全跳過局部最小化步驟,因為算法需要其輸出繼續進行,即保持或丟棄新坐標。 但是,我不是這個算法的專家。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.