Questions tagged [lmfit]

lmfit is a Python library for Least-Squares Minimization with Bounds and Constraints.

A library for least-squares minimization and data fitting in Python. Built on top of scipy.optimize, lmfit provides a Parameter object which can be set as fixed or free, can have upper and/or lower bounds, or can be written in terms of algebraic constraints of other Parameters. The user writes a function to be minimized as a function of these Parameters, and the scipy.optimize methods are used to find the optimal values for the Parameters. The Levenberg-Marquardt (leastsq) is the default minimization algorithm, and provides estimated standard errors and correlations between varied Parameters. Other minimization methods, including Nelder-Mead’s downhill simplex, Powell’s method, BFGS, Sequential Least Squares, and others are also supported. Bounds and contraints can be placed on Parameters for all of these methods.

https://pypi.python.org/pypi/lmfit

382 questions
3
votes
2 answers

How do I specify error of Y-variable when fitting with lmfit?

I'm almost new to Python and I'm trying to fit data from college using lmfit. The Y variable has a variable error of 3%. How do I add that error to the fitting process? I am changing from scipy's curve fit and in scipy it was really easy to do so,…
3
votes
1 answer

the use of lmfit ExponentialGaussianModel( )

Trying to fit ExponentialGaussianModel() from lmfit but getting the following error message: The input contains nan values I am using Jupyternotebook on windows and I am new to python and lmfit. I find the lmfit documentation to be a bit obscure…
ttuff
  • 45
  • 5
3
votes
1 answer

LMFIT on Python: TypeError: only size-1 arrays can be converted to Python scalars

I am trying to create an curve fitting program using LMFIT on python (Anaconda) but I keep receiving the same error message: TypeError: only size-1 arrays can be converted to Python scalars. I was able to perform an optimization using just one…
3
votes
1 answer

choosing step sizes when fitting under python

As you may know, the lmfit module in python is convenient to extend capabilities of scipy.optimize functionnalities. However I don't find something that seems to me necessary: the possibility to choose the step sizes (used for partial derivations,…
Stéphane
  • 1,389
  • 3
  • 13
  • 34
3
votes
1 answer

Python lmfit constraints: a < b < c

I am using lmfit in Python to fit some data, which includes fitting the variables a, b, and c. I need to ensure that a < b < c. I found http://cars9.uchicago.edu/software/python/lmfit_MinimizerResult/constraints.html which talks about constraints…
ChemPaul
  • 45
  • 5
3
votes
2 answers

lmfit extract fit statistics parameters after fitting

This is a question about extracting fit statistics from the lmfit fit_report()(1) object In this lmfit example, the following partial output is returned: [[Model]] Model(gaussian) [[Fit Statistics]] # function evals = 31 # data points …
edesz
  • 11,756
  • 22
  • 75
  • 123
3
votes
1 answer

How can we get lmfit parameters after fitting?

I wrote a program to fit some Raman spectra peaks. I need to return the fitted parameters (position, amplitude, HWHM). I used the modul lmfit to create a lorentzian peak with constraints. I have a good agreement between the fitted peak and the raw…
Deniz Cakir
  • 33
  • 1
  • 4
3
votes
1 answer

LMFIT confidence interval uncertainty estimates error on python

the output error is : MinimizerException: Cannot determine Confidence Intervals without sensible uncertainty estimates Why I got this error? How can I calculate uncertainty estimates and solve this problem?? for dosya1 in glob.glob("mean*"): …
sirius123
  • 125
  • 1
  • 2
  • 4
3
votes
2 answers

Using multiple independent variables in Python lmfit

I am trying to fit a model to some data. The independent variables are called A and B, and they are columns in a Pandas DataFrame. I am trying to fit with two parameters against y in the data frame. Previously, with curve_fit from Scipy, I could…
slhck
  • 36,575
  • 28
  • 148
  • 201
3
votes
1 answer

fitting two lorentz by lmfit Model minimize in python

maybe someone can help me. I spent days on it, but I couldn't get through the problem. Thanks in advance. I want to fit 2 lorentzians to my experimental data. I broke my equations down to simple form of two lorentzians lorentz1 and lorentz2…
Amin
  • 437
  • 2
  • 4
  • 17
2
votes
1 answer

Putting conditions on parameters in lmfit.minimize

How to put conditions on parameters while using lmfit.minimize? from lmfit import Parameters,minimize, fit_report import numpy as np x = np.linspace(0,10,100) y = 2.39645 * x**2 + np.random.normal(0, 2, 100) def fun1(params,x,y): k1 =…
lsr729
  • 752
  • 2
  • 11
  • 25
2
votes
0 answers

Python: lmfit : shgo does not accept minimizer_kwargs

We are trying to find the global optimum of a minimisation problem. We have tried the basin hopping and shgo (simplicial homology global optimization) algorithm from scipy via the lmfit 'interface'. Using basin hopping, we can succesfully converge…
2
votes
0 answers

Solving simultaneous linear and non-linear equations and inequalities

I have a number of linear and non-linear equations and inequalities (about twenty), and am looking for solutions to these. The equations either relate or constrain a number of variables. These variables are either constant, allowed to be within some…
2
votes
1 answer

KeyError using lmfit.Model.fit()

I am sorry for a fairly basic question, but I am having trouble understanding the syntax with lmfit and can't come up with why this error comes up. The error is specifically: "KeyError: 'flux'" I understand that it wants some type of dictionary…
astroguy
  • 45
  • 4
2
votes
3 answers

lmfit and scipy curve_fit return initial guesses as best-fitted parameters

I want to fit a function to some data and I’ m facing a problem. I’ ve tried to use lmfit or curve_fit from scipy. Below I describe the problem. Here is my data: dataOT = pd.read_csv("KIC3239945e.csv", sep=';')…
1
2
3
25 26