【问题标题】:How do I speed up lmfit as much as possible?如何尽可能加快 lmfit?
【发布时间】:2020-12-11 09:20:03
【问题描述】:

我正在使用 lmfit 将偏斜高斯函数拟合到大量单个数据集(10 000)。我得到了很好的结果,但是适应 10 000 像素所需的时间很长,所以我可以缩短适应时间的每一毫秒都会有所帮助。这是我正在使用的代码,其中 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 performance lmfit


    【解决方案1】:

    与 Python 本身一样,lmfit 旨在优化开发人员(或更常见的“科学家”)时间。考虑到这一观点,获得 10,000 次拟合的 10 倍加速实际上非常简单(而且成本低廉):获得一台具有 10 多个内核(或计算线程)的机器,并将问题分成 10 个脚本,每个脚本执行 1,000 次拟合。

    【讨论】:

      猜你喜欢
      • 2011-11-17
      • 1970-01-01
      • 2015-09-25
      • 1970-01-01
      • 1970-01-01
      • 2020-02-25
      • 2021-10-26
      • 1970-01-01
      • 2019-01-15
      相关资源
      最近更新 更多