gpt4 book ai didi

python - Scipy 优化边界的 Curve_fit 错误

转载 作者:行者123 更新时间:2023-11-28 22:27:06 24 4
gpt4 key购买 nike

当我尝试运行时:

bet = (nu[minimum],10**4,3000,0,0,5000)   # Array of initial bet parameters
bound = ( (nu[0],nu[len(nu)-1]),(10**3,10**6),(-np.inf,np.inf),(-np.inf,np.inf),(-np.inf,np.inf),(-np.inf,np.inf) )
popt,pcov = curve_fit(S_21,x,y, p0=bet, bounds = bound)

TypeError: leastsq() got an unexpected keyword argument 'bounds'

问题是什么?我在 Windows 上使用 Python 3.4.4。

最佳答案

scipy.optimize.leastsq 不支持边界,在 scipy 版本 0.17 之前被 curve_fit 使用。 OTOH,scipy.optimize.least_squares(在较新版本的 scipy 中由 curve_fit 使用)可以支持边界,但在使用 lm (Levenberg-Marquardt) 方法,因为它是 scipy.optimize.leastsq 的简单包装器。这有点令人困惑。

请允许我推荐尝试 lmfit ( http://lmfit.github.io/lmfit-py/ ),它支持所有参数的边界,并且可以轻松修复/更改参数而无需更改模型函数。 Lmfit 的模型类提供了一种方便的曲线拟合方法,以及大量用于探索参数置信区间的工具。

关于python - Scipy 优化边界的 Curve_fit 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44245026/

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