python - How to fit data by exponential curve -
i little problem project because have set of data, plot in order 2 curves , fit plots exponential curve.
i watched post : fitting exponential decay no initial guessing. example kind different.
this i'm getting data :
my script following :
mask_g = np.bitwise_and( tbdata['g'] < 99.99, tbdata['gerr'] < 0.2) mask_r = np.bitwise_and( tbdata['r'] < 99.99, tbdata['rerr'] < 0.2) g_corrected = tbdata[mask_g] r_corrected = tbdata[mask_r] fig13 = plt.gcf() fig13.set_size_inches(16, 9) fig13, (ax1,ax2) = plt.subplots(1,2) fig_error_g = ax1.plot(g_corrected['g'], g_corrected['gerr'], '.') ax1.set_xlabel('g') ax1.set_ylabel('gerr') ax1.set_title('evolution de gerr en fonction de g') fig_error_r = ax2.plot(r_corrected['r'], r_corrected['rerr'], '.') ax2.set_xlabel('r') ax2.set_ylabel('rerr') ax2.set_title('evolution de rerr en fonction de r') fig13.tight_layout() plt.savefig('graphique.png') plt.show()
i tried write that, based on scipy doc :
def exponential(x,a,b,c) : return * np.exp(-b * x) + c xdata = g_corrected['g'] y = g_corrected['gerr'] ydata = y + 0.2 * np.random.normal(size=len(xdata)) popt, pcov = curve_fit(exponential, xdata, ydata)
but :
/home/user/enthought/canopy_64bit/user/lib/python2.7/site-packages/scipy/optimize/minpack.py:601: optimizewarning: covariance of parameters not estimated
category=optimizewarning)
do have idea on how can process ?
thank ;)
edit :
i tried fit plot :
mask_g = np.bitwise_and( tbdata['g'] < 99.99, tbdata['gerr'] < 0.2) mask_r = np.bitwise_and( tbdata['r'] < 99.99, tbdata['rerr'] < 0.2) g_corrected = tbdata[mask_g] r_corrected = tbdata[mask_r] params = np.polyfit(g_corrected['g'], np.log(g_corrected['gerr']),1) = params[0] = np.exp(params[1]) fig13 = plt.gcf() fig13.set_size_inches(16, 9) fig13, (ax1,ax2) = plt.subplots(1,2) fig_error_g = ax1.plot(g_corrected['g'], (g_corrected['gerr']), '.') fig_error_g = ax1.plot(g_corrected['g'], (a*np.exp(a*g_corrected['g'])),'.') ax1.set_xlabel('g') ax1.set_ylabel('gerr') ax1.set_title('evolution de gerr en fonction de g') fig_error_r = ax2.plot(r_corrected['r'], np.log(r_corrected['rerr']), '.') ax2.set_xlabel('r') ax2.set_ylabel('rerr') ax2.set_title('evolution de rerr en fonction de r') fig13.tight_layout() plt.savefig('graphique.png') plt.show()
and :
what think result ?
easiest way apply logarithmic scaling plot. know log(exp(x)) = x, i.e. if apply log() y-values , plot should linear plot. once have that, can fit linear toolbox (gaussian least square method). resulting slope prefactor in exp(ax), try obtain.
if have dependency on x-axis, might beneficial make log-log plot of data figure out dependencies.
Comments
Post a Comment