在LMFIT中拟合负指数模型



lmfit的指数模型在近似(负)指数函数时如何工作?

以下试图遵循https://lmfit.github.io/lmfit-py/model.html,但未能提供正确的结果:

mod = lmfit.models.ExponentialModel()
pars = mod.guess([1, 0.5], x=[0, 1])
out = mod.fit([1, 0.5], pars, x=[0, 1])
out.eval(x=0) # result is 0.74999998273811308, should be 1
out.eval(x=1) # result is 0.75000001066995159, should be 0.5

您需要两个以上的数据点才能将两参数指数模型适合数据。LMFIT模型旨在进行数据拟合。这样的事情将起作用:

import numpy as np
import lmfit
xdat = np.linspace(0, 2.0, 11)
ydat = 2.1 * np.exp(-xdat /0.88) + np.random.normal(size=len(xdat), scale=0.06)
mod = lmfit.models.ExponentialModel()
pars = mod.guess(ydat, x=xdat)
out = mod.fit(ydat, pars, x=xdat)
print(out.fit_report())

相反,您正在获得amplitude = 0.75decay > 1e6

最新更新