python - scipy curve_fit unable to fit curve -
i trying use scipy.optimize function curve_fit fit set of data points using custom exponential function. code follows:
import numpy np import matplotlib.pyplot plt scipy.optimize import curve_fit def fit(x, tau, beta): return np.exp(-1 * np.power(x / tau, beta)) def plot_e2e(times, e2es): optimalparams, covariance = curve_fit(fit, times, e2es) tau = optimalparams[0] beta = optimalparams[1] print 'tau is:', tau print 'beta is:', beta if __name__ == '__main__': % read_e2e_data not included proprietary reasons. times, e2es = read_e2e_data(filename) plot_e2e(times, e2es)
doing raises following exception (line numbers may different due taking out unrelated stuff):
traceback (most recent call last): file ".\plot_e2e.py", line 54, in <module> plot_e2e(times, e2es) file ".\plot_e2e.py", line 34, in plot_e2e optimalparams, covariance = curve_fit(fit, times, e2es) file "c:\anaconda\lib\site-packages\scipy\optimize\minpack.py", line 586, in curve_fit raise runtimeerror(msg) runtimeerror: optimal parameters not found: number of calls function has reached maxfev = 600.
if increase maxfev parameter of curve_fit instead bogus values tau (4.035e-303).
my time , e2e vectors thus:
time = [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 9.0, 11.0, 14.0, 17.0, 21.0, 25.0, 30.0, 37.0, 45.0, 54.0, 65.0, 78.0, 94.0, 113.0, 136.0, 163.0, 196.0, 236.0, 283.0, 340.0, 409.0, 491.0] e2es = [1.0, 0.999804, 0.99964, 0.999497, 0.99937, 0.999276, 0.999139, 0.998974, 0.998566, 0.998005, 0.997225, 0.997073, 0.997793, 0.998586, 1.001542, 1.004414, 1.005311, 1.001431, 1.001016, 0.998936, 0.995649, 0.993765, 0.98663, 0.985266, 0.984635, 0.982588, 0.974413, 0.973811, 0.968772, 0.970131]
if have ideas might issue, please let me know. i've been trying debug issue , have hit dead end.
Comments
Post a Comment