fitting exponential decay with no initial guessing

前端 未结 8 912
刺人心
刺人心 2020-12-01 02:31

Does anyone know a scipy/numpy module which will allow to fit exponential decay to data?

Google search returned a few blog posts, for example - http://exnumerus.blo

相关标签:
8条回答
  • 2020-12-01 02:57

    I never got curve_fit to work properly, as you say I don't want to guess anything. I was trying to simplify Joe Kington's example and this is what I got working. The idea is to translate the 'noisy' data into log and then transalte it back and use polyfit and polyval to figure out the parameters:

    model = np.polyfit(xVals, np.log(yVals) , 1);   
    splineYs = np.exp(np.polyval(model,xVals[0]));
    pyplot.plot(xVals,yVals,','); #show scatter plot of original data
    pyplot.plot(xVals,splineYs('b-'); #show fitted line
    pyplot.show()
    

    where xVals and yVals are just lists.

    0 讨论(0)
  • 2020-12-01 02:58

    If your decay starts not from 0 use:

    popt, pcov = curve_fit(self.func, x-x0, y)
    

    where x0 the start of decay (where you want to start the fit). And then again use x0 for plotting:

    plt.plot(x, self.func(x-x0, *popt),'--r', label='Fit')
    

    where the function is:

        def func(self, x, a, tau, c):
            return a * np.exp(-x/tau) + c
    
    0 讨论(0)
提交回复
热议问题