回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>有没有人知道一个scipy/numpy模块,它允许对数据进行指数衰减?</p>
<p>Google search返回了一些博客文章,例如-<a href="http://exnumerus.blogspot.com/2010/04/how-to-fit-exponential-decay-example-in.html" rel="noreferrer">http://exnumerus.blogspot.com/2010/04/how-to-fit-exponential-decay-example-in.html</a>,但是这个解决方案需要预先指定y偏移量,这并不总是可能的</p>
<p>编辑:</p>
<p>曲线拟合是可行的,但如果没有对参数的初始猜测,它可能会失败得很惨,有时这是必需的。我使用的代码是</p>
<pre><code>#!/usr/bin/env python
import numpy as np
import scipy as sp
import pylab as pl
from scipy.optimize.minpack import curve_fit
x = np.array([ 50., 110., 170., 230., 290., 350., 410., 470.,
530., 590.])
y = np.array([ 3173., 2391., 1726., 1388., 1057., 786., 598.,
443., 339., 263.])
smoothx = np.linspace(x[0], x[-1], 20)
guess_a, guess_b, guess_c = 4000, -0.005, 100
guess = [guess_a, guess_b, guess_c]
exp_decay = lambda x, A, t, y0: A * np.exp(x * t) + y0
params, cov = curve_fit(exp_decay, x, y, p0=guess)
A, t, y0 = params
print "A = %s\nt = %s\ny0 = %s\n" % (A, t, y0)
pl.clf()
best_fit = lambda x: A * np.exp(t * x) + y0
pl.plot(x, y, 'b.')
pl.plot(smoothx, best_fit(smoothx), 'r-')
pl.show()
</code></pre>
<p>但如果我们去掉“p0=guess”,它就失败了。</p>