【问题标题】:Fit negative exponential model in LMFIT在 LMFIT 中拟合负指数模型
【发布时间】:2017-12-13 22:54:43
【问题描述】:

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

【问题讨论】:

    标签: python lmfit


    【解决方案1】:

    您需要两个以上的数据点才能将两参数指数模型拟合到数据中。 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.75 和 decay > 1e6。

    【讨论】:

    • 谢谢。该数据旨在成为 MVCE,但太简单了。似乎 lmfit 不太适合我的真实数据。
    猜你喜欢
    • 2014-12-17
    • 2018-11-07
    • 2014-06-18
    • 2019-07-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-23
    • 1970-01-01
    相关资源
    最近更新 更多