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
0
votes
1 answer

How to set variable to not fit it

I want to fit Gauss, but variables cen and cen2 must be constantly. from pylab import * import matplotlib.mlab from lmfit import Model def gaussian(x, amp, cen, wid,amp2,cen2,wid2): return (amp/(sqrt(2*pi)*wid)) * exp(-(x-cen)**2…
Kinga Jn
  • 11
  • 2
0
votes
0 answers

Convergence check in LMFIT

I am using the lmfit library as implemented for python to do least square fits. Unfortunately, I don't know how to properly estimate the convergence of my results. What I currently do is to start with some tight convergence parameter set and check…
Alexander Cska
  • 738
  • 1
  • 7
  • 29
0
votes
2 answers

guess function when using built-in defined models in lmfit

I am having a problem with the guess function of lmfit. I am trying to fit some experimental data and I want to use different built in models of lmfit, but I cannot run the built in modules, only if I define the function directly. The following code…
0
votes
1 answer

lmfit and minimize function for multiple datasets

I have a problem with the script used to simultaneously describe a set of data with some common parameters. The program is quite long and complex, and I am reporting the essential parts here for the sake of simplicity. Full script and a set of data…
0
votes
1 answer

Python - Clipping out data to fit profiles

I have several sets of data to which I'm trying to fit different profiles. In the centre of one of the minima there is contamination that prevents me from doing a good fit as you can see in this image: How can I clip out those spikes in the bottom…
EternalGenin
  • 495
  • 2
  • 6
  • 14
0
votes
2 answers

lmfit- tying fitting parameters one to the other

I'm using python lmfit module to fit multiple Gaussian. What I want is to tide one parameter to the other trough mathematical expression, for example: def gaussian(x,a1,c1,w1,a2,w2,c2): g1=a1*np.exp(-(x-c1)**2/(2*w1**2)) …
0
votes
1 answer

Adding weights when using lmfit to fit a 3D line on a cloud of points

I am using the following code to fit a 3D line on a cloud of 3D points. I am using a least squares method of lmfit to minimize. I need to add weights to different points, but do not know how to do it when using an array (and not a scalar) distance…
Iroxk
  • 43
  • 5
0
votes
0 answers

Python minimizer

I am trying to fit a 3D line on a cloud of points. I am using a minimzer from lmfit. I define the line-point distance as np.linalg.norm(np.cross(p-v0,v1-v0))/np.linalg.norm(v1-v0) (method 2 from…
Iroxk
  • 43
  • 5
0
votes
2 answers

How to draw samples from lmfit model?

I have a skewed Gaussian model in lmfit that fits my data. Now I would like to draw a sample from it, but I could nowhere in the documentation find how? Is the correct approach to simply implement the model function yourself in my case the skewed…
Hakaishin
  • 2,550
  • 3
  • 27
  • 45
0
votes
0 answers

Nonlinear magnetic model fit -with a definite integral- using scipy.integrate.quad and lmfit

I would like to fit an hysteresis curve, with a superparamagnetic behavior, using a magnetic model which includes a Langevin function and a pair distribution function [1]. To fit with this equation I must solve a definite integral. I was trying to…
Ernesto
  • 21
  • 4
0
votes
1 answer

ValueError when using lmfit LognormalModel

I have been using lmfit for about a day now and needless to say I know very little about the library. I have been using several built-in models for curve fitting and all of them work flawlessly with the data except the Lognormal Model. Here is my…
0
votes
2 answers

lmfit - best and init fit do not correspond to report

I am trying to fit data with Python library lmfit. In the data, there are two gaussian functions, the second (LO) higher than the first (TO). The code follows: TOmod = GaussianModel(prefix="TO_") LOmod =…
Jakub Wagner
  • 428
  • 1
  • 5
  • 15
0
votes
1 answer

lmfit matplot - fitting many curves from many different files at the same time/graph

I have the following code, with which I intend to read and plot many curves from many different files. The "reading and plotting" is already working pretty good. The problem is that now I want to make a fitting for all those curves in the same…
Jonas Kublitski
  • 119
  • 1
  • 11
0
votes
1 answer

Set an optimization using LMFIT and Parameters class with condition to be checked

How to use ExpressionModel in LMFIT to fit a conditional model that can be represented as: from lmfit.models import ExpressionModel # read(xdata and ydata) here if xdata < some_parameter_value: model = ExpressionModel('expression1') else: …
Hzine
  • 105
  • 1
  • 9
0
votes
1 answer

Set parameter expression that contains the independent variable in python lmfit

I have dictionary of parameters with unknown number of those parameters (comes from other function), I looped through the dictionary to add its components to an lmfit models as follows: from lmfit import Parameters fit_params = Parameters() for…
Hzine
  • 105
  • 1
  • 9