gpt4 book ai didi

python - 在 LMFIT 中拟合负指数模型

转载 作者:行者123 更新时间:2023-12-01 02:22:55 31 4
gpt4 key购买 nike

在逼近(负)指数函数时,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

关于python - 在 LMFIT 中拟合负指数模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47771520/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com