如何尽可能加快lmfit



我使用lmfit将一个偏斜的高斯函数拟合到大量的单个数据集(10000(。我得到了很好的结果,但拟合10000像素所需的时间相当长,所以我可以节省每毫秒的拟合时间都会很有帮助。这是我正在使用的代码,其中x和y是我想要拟合的数据。参数的猜测对我来说非常有效,但主要是通过试错产生的。

import lmfit as lm
from lmfit import Model
from lmfit.models import GaussianModel, ConstantModel, ExponentialGaussianModel, SkewedGaussianModel
from lmfit import Parameters
def LM_skewedgauss(x,y):
supermodel = ConstantModel() + SkewedGaussianModel()
x = x

# Guesses

a_peak = np.max(y)
#16 is a needed constant from the way the data is produced
t_peak = np.where(y == a_peak)[0][0]*16 
avg = np.mean(y)
gamma = 1.5
sigma = 31
params = supermodel.make_params(amplitude = a_peak*sigma*np.sqrt(2*np.pi),
center = t_peak,
sigma = sigma,
gamma = gamma,
c = 3)
result = supermodel.fit(counts, params = params, x = x)
#result.plot()
bestparam = result.params

与Python本身一样,lmfit旨在优化开发人员(或者更常见的"科学家"(的时间。考虑到这一观点,获得10000次拟合的10倍加速实际上非常简单(而且便宜(:获得一台具有10个以上内核(或计算线程(的机器,并将问题分解为10个脚本,每个脚本进行1000次拟合。

最新更新