scipy0.18.1中有错误吗`scipy.optimize.minimize.最小化`?

2024-09-27 09:36:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图用^{}中的dogleg方法来求解函数。为了更好地理解它,我采用了帮助页底部的一个示例,并使用dogleg方法:

from scipy.optimize import minimize

def fun(x):
    return (x[0] - 1)**2 + (x[1] - 2.5)**2

# solver
res = minimize(fun, (2, 0), method='dogleg', jac=False) # or jac=None, it doesn't matter

print(res)

我得到一个错误ValueError: Jacobian is required for dogleg minimization.

这类似于一个老问题:"Jacobian is required for Newton-CG method" when doing a approximation to a Jacobian not being used when jac=False?,它似乎没有得到解决。在

所以我的问题是:这个^{}中真的有一个bug,还是我没有正确地使用它?在


Tags: 方法函数falseforisrequiredresmethod
1条回答
网友
1楼 · 发布于 2024-09-27 09:36:16

必须传递一个雅可比函数才能使用dogleg方法,因为它是基于梯度的优化方法。如果你看一下^{}jac参数,它表示

jac : bool or callable, optional
Jacobian (gradient) of objective function. Only for CG, BFGS, Newton-CG, L-BFGS-B, TNC, SLSQP, dogleg, trust-ncg. If jac is a Boolean and is True, fun is assumed to return the gradient along with the objective function. If False, the gradient will be estimated numerically. jac can also be a callable returning the gradient of the objective. In this case, it must accept the same arguments as fun.

如果你往下看页面底部的注释:

Method dogleg uses the dog-leg trust-region algorithm for unconstrained minimization. This algorithm requires the gradient and Hessian; furthermore the Hessian is required to be positive definite.

一些基于梯度的方法不需要显式的雅可比(和/或Hessian),因为它们将使用差分方法来近似它们。但是dogleg确实需要您显式地传递这样一个函数。在

相关问题 更多 >

    热门问题