You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

curve_fit拟合参数误差疑似高估问题求助

曲线拟合参数绝对不确定度异常问题

我有一组实验室数据,拟拟合至函数:
f(s, params) = amp * (s/sp) / (1 + s/sp + 1.041) + bg

我在curve_fit中设置absolute_sigma=True以获取参数(sp、amp、bg)的绝对不确定度,但通过np.sqrt(np.diag(pcov))计算得到的误差看似不合理。下图中蓝色点为数据,红色线是f(s, *popt)最优拟合线,绿色线为sp减去计算误差的拟合线,橙色线为sp加上计算误差的拟合线,我预期±误差线应更贴近红色最优线。

最小示例代码

# Function for fitting
def scattering_rate(s, sp, amp, bg):
    return amp * (s/sp) / (1 + s/sp + (-20/19.6)**2) + bg

# data
s = np.array([0.6, 1.2, 2.3, 4.3, 8.1, 15.2, 28.5, 53.4])
y = np.array([8.6, 8.5, 8.9, 9.5, 10.6, 12.6, 15.5, 18.3])

# Fit data to saturated scattering rate
popt, pcov = curve_fit(scattering_rate, s, y, absolute_sigma=True)
print('Fit parameters', popt)
print('Fit uncertainties', np.sqrt(np.diag(pcov)))

# Construct fit from optimized parameters
fit_s = np.linspace(np.min(s), np.max(s), 100)
fit = scattering_rate(fit_s, *popt)

# Consider one error difference in sp value
fit_plus_err = saturation_power(fit_s, popt[0] + np.sqrt(np.diag(pcov))[0], popt[1], popt[2])
fit_minus_err = saturation_power(fit_s, popt[0] - np.sqrt(np.diag(pcov))[0], popt[1], popt[2])

# Plot
plt.plot(s, y, '-o', markeredgecolor='k', label='data')
plt.plot(fit_s, fit_plus_err, label='sp + err')
plt.plot(fit_s, fit_minus_err, label='sp - err')
plt.plot(fit_s, fit, '-r', label='opt sp')
plt.xlabel('s')
plt.ylabel('y')
plt.legend()
plt.grid()
plt.show()

补充说明

根据建议,我添加了原始数据的误差棒y_err = np.array([0.242, 0.231, 0.282, 0.31 , 0.373])至curve_fit的sigma参数中,结果有所改善,但误差线与最优线仍有一定距离。

拟合结果图

初始拟合图

初始拟合图

添加误差棒后拟合图

添加误差棒后拟合图


内容的提问来源于stack exchange,提问作者AJ Rasmusson

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 17:42:38