Search code examples
functionpython-2.7least-squaresdata-fitting

How to apply the least squares method to built-in models of Levenberg-Marquardt algorithm


I am trying to apply the least squares to my data using the built-in Voigt model from lmfit.

But I have to call the Minimizer class to apply the least squares method, which requires a function.

And I don't have a function since I used the built-in model given by lmfit. There's no simple function I use for Voigt model.

What is your recommendation?

Minimizer class: (http://lmfit.github.io/lmfit-py/fitting.html#module-Minimizer)


Solution

  • I was initially trying to change xtol, ftol and gtol values of the least-square which are 10^-7 by default, and for that I thought I need to call the Minimizer class. However, I could change tol values simply by adding them to model.fit:

    output = model.fit(input_y, parameters, x=input_x, \
          fit_kws={"ftol":1e-22, "xtol":1e-10, "gtol":1e-22})
    

    Here the output is the model(s) using lmfit.