I am trying to fit a very complicated (Flattened Gaussian) model to a data I have obtained. Image for flattened Gaussian formula (variable fc in my code here represents vo, central frequency.)
I have written the code in python using from scipy.optimize import curve_fit. It is unable to optimize my equation and always gives the same answers for the parameters. Link to the data file: 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)
This is what I get: OptimizeWarning: Covariance of the parameters could not be estimated category=OptimizeWarning) fitted parameters: [1. 1. 1. 1.]
Please help me with fitting this using either scipy or any other module that you think is good. (like emcee)
