我正在尝试将一个非常复杂的(扁平高斯)模型拟合到我获得的数据中。 Image for flattened Gaussian formula (我这里代码中的变量fc代表vo,中心频率。)
我使用 from scipy.optimize import curve_fit 在 python 中编写了代码。 它无法优化我的方程式,并且总是对参数给出相同的答案。 数据文件链接:https://www.filehosting.org/file/details/795968/my-file.dat
import numpy as np
from scipy.optimize import curve_fit
x = np.loadtxt("my-file.dat")[:,0]
yres = np.loadtxt("my-file.dat")[:,1]
def flatgauss(x, A,fc,t,w):
B= ((4*(x-fc)**2)/ w**2 ) * np.log((-1/t)*np.log((1+ np.exp(-t))/2))
return -A*( (1-np.exp(-t*np.exp(B)))/ (1-np.exp(-t)) )
popt, pcov = curve_fit(flatgauss, x, yres)
print ("fitted parameters:", popt)
这是我得到的: OptimizeWarning:无法估计参数的协方差 类别=优化警告) 拟合参数:[1。 1.1.1.]
请帮助我使用 scipy 或您认为好的任何其他模块来安装它。 (像司仪一样)
请您参考如下方法:
scipy 的 curve_fit 例程的默认初始参数估计值都是 1.0,并且由于无法对这些估计值进行改进,因此返回它们给出“拟合参数:[1. 1. 1. 1.]”。如果您查看如下所示的数据散点图,发布的数据不会位于平坦的高斯峰上 - 或任何其他 preak 方程 - 因此 curve_fit 在您使用的方程上失败。
