带加法的指数衰减



指数衰减的公式为:

np.exp(-(t/n))

其中t是时间步长,n为控制衰减速度的系数。我想要的是运行函数,在该函数中,我手动计算每一步的值,并能够在衰减过程中添加值。

我该怎么做?

我还发现了另一个公式:(1-percent)^t


def decay(val, rate): return val * np.exp(-rate)
In [84]: decay(1,1/10.)
Out[84]: 0.905
In [85]: decay(0.905,1/10.)
Out[85]: 0.819
In [86]: decay(0.819,1/10.)
Out[86]: 0.741
In [88]: np.exp(-1/10.)
Out[88]: 0.905
In [89]: np.exp(-2/10.)
Out[89]: 0.819
In [90]: np.exp(-3/10.)
Out[90]: 0.741

我可以建议使用数组在每个时间步长t进行求值吗?您需要编辑函数以包含衰变常数n

def decay(t, A, n):
return A*np.exp(-t/n)
t = np.linspace(0, 10, 256)
initial = 1
rate = 10
value = decay(t, initial, rate)

将是每个t的衰减函数值的数组。

最新更新