2
votes

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)

1
Would you please post a link to the data file? - James Phillips
Yes, I have now edited the post to include a link to the data file. Here it is: <filehosting.org/file/details/795968/my-file.dat> - Shivaramakrishna Reddy
I do not want to accept their terms of service or give them my email address, both required for that download link. - James Phillips
Try emailing to me at [email protected] - James Phillips
Ok here is another link in which you need not accept any terms or need to provide an email id. <mediafire.com/file/7puj3hanac8aklr/my-file.dat/file> - Shivaramakrishna Reddy

1 Answers

1
votes

The default initial parameter estimates for scipy's curve_fit routine are all 1.0, and since no improvement on those estimates could be made they were returned giving "fitted parameters: [1. 1. 1. 1.]". If you look at a scatterplot of the data as shown below, the posted data does not lie on a flattened Gaussian peak - or any other preak equation - so curve_fit fails on the equation you used.

plot