正在尝试从lmfit
匹配ExponentialGaussianModel()
,但得到以下错误消息:The input contains nan values
我在windows上使用Jupyternotebook,对python和lmfit还不熟悉。我发现lmfit文档对于初学者来说有点晦涩难懂,希望能在这里找到帮助。下面是我的代码:我想生成指数高斯直方图,提取数据点并练习使用lmfit
库进行拟合。(我想练习拟合并找到最少数量的点来重现生成直方图所用的参数)
from scipy.stats import exponnorm
from lmfit.models import ExponentialGaussianModel
K2 = 1.5
r2 = exponnorm.rvs(K2, size=500, loc = 205, scale = 40)
Q = np.histogram(r2,500)
exp_gaus_x = Q[1]
exp_gaus_y = Q[0]
tof_x = exp_gaus_x[1:]
tof_y = exp_gaus_y
mod = ExponentialGaussianModel()
pars = mod.guess(tof_y, x=tof_x)
out = mod.fit(tof_y, pars, x=tof_x)
(out.fit_report(min_correl=0.25))
我得到一个错误,即有一个输入值。我在等手册上显示的报告。在
在
lmfit
中使用的指数高斯的定义来自https://en.wikipedia.org/wiki/Exponentially_modified_Gaussian_distribution。 指数项为exp[center*gamma + (gamma*sigma)**2/2 - gamma*x]
对于}和/或{}的大ish值,这有可能给出{}。我相信您得到了这样的}(实际上是“根本”)。这是那个特定模式的一个真正的局限性。在这个页面上,{cd4}的顺序比cd5}的顺序更接近。在
sigma
和{Inf
值,这就是您看到的NaN
消息的原因。fitting例程(在Fortran中)并不优雅地处理NaN
或{我认为对于指数修正高斯函数,一个更简单的定义会更好。与
虽然参数的含义已经发生了一些变化,但是您将得到一个合适的匹配,并且需要显式地给出起始值,而不是依赖于
guess()
过程。它们不必离得很近,只是离得不远。在完整的脚本可以是:
^{pr2}$会打印出来的
展示一个情节
希望有帮助。在
相关问题 更多 >
编程相关推荐