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
0 answers

Lmfit Global Fit, Is this code even doing a global fit?

I am using 5 models, for 5 datasets that share some parameters between them for a global fit. I am not sure if I am actually doing a global fit here. I am trying to implement Schild / Global fit for a dose-response type of data. def…
user2332994
  • 27
  • 1
  • 6
0
votes
2 answers

python lmfit [nan] values

I am trying to use lmfit for a global fit problem (schild analysis). I have some shared parameters and some that are calculated based on these shared. At one point the function encounters log for a negative number and throws a [nan] list causing it…
user2332994
  • 27
  • 1
  • 6
0
votes
1 answer

Python, Lmfit, globalfit

I am trying to do a global fit using 1 shared parameter and 6 other parameters. dataComplete is my data parsed from a text file and dose = x values. Here, the bValue changes per the concentration and others stay the same. There are some calculations…
user2332994
  • 27
  • 1
  • 6
0
votes
1 answer

Constraints on curve fitting parameters

I am trying to impose bounds and constraints in my quadratic curve fitting process. Objective is to find coefficients a,b and c. Imposing constraint on b: delta-2*a*x is my doubt. How can I add a variable, x in my constraints. Workable code: from…
learnerADV
  • 13
  • 4
0
votes
1 answer

Trilateration with LMFIT Python

I'm trying to perform Non-Linear Least-Squares Fitting LMFIT for Trilateration purposes: LMFIT beacons includes beacon position x,y,z Parameters() include Xinit location to estimate. tag_distances[i] include measurements (distance from tag…
Guido
  • 634
  • 1
  • 8
  • 19
0
votes
1 answer

Annotate fitted peaks with model's prefix

So right now I have a fit routine that fits a composite model to a data set. It would return a graph like this on matplotlib. Is there any way to annotate each peak with the prefix of its individual model from the composite model? Thank you!
Linh Phan
  • 83
  • 1
  • 9
0
votes
1 answer

How to distinguish known local parameters from global parameters in lmfit?

I am working with the lmfit python package https://lmfit.github.io/lmfit-py/ for fitting data to a specified non-linear function within certain permitted ranges of variation for some parameters (which is mainly why I found lmfit…
0
votes
1 answer

Error-weighted fit using uncertainties in LMFIT

I am trying to fit a model using LMFIT, I can easily do the following: def loss_function(params): residuals = [] for x, measured in ...: y = predict(x, params) residuals.append(y - measured) return residuals params =…
luke14free
  • 2,529
  • 1
  • 17
  • 25
0
votes
1 answer

Lmfit separate peak fitting

I'm very new to curve/peak fitting, but I am trying to fit a data set with multiple separate independent peaks. I've tried something similar to the example provided by lmfit, and here's my code: import matplotlib.pyplot as plt from lmfit.models…
Linh Phan
  • 83
  • 1
  • 9
0
votes
1 answer

python 2 peak lorentzian fitting issues using lmfit

import numpy as np import os import matplotlib.pyplot as plt from lmfit.models import GaussianModel, ExponentialModel, LorentzianModel, VoigtModel import scipy from scipy.optimize import…
Karthick
  • 58
  • 4
0
votes
1 answer

Apply power fit to data by using levenberg-marquardt algorithm in python

Hy everybody! I am a beginer in python and data analysis, and meet with a problem, during fitting a power function to my data. Here I plotted my dataset as a scatterplot I want to plot a power function with expontent arround -1 , but after I apply…
0
votes
1 answer

how to call iter_cb every iteration rather than every function evaluation?

The minimize function in lmfit allows the specification of a function that is called every iteration with the keyword iter_cb. This function is called every function evaluation (so not every iteration in the least squares process). What I want to do…
Mark Bakker
  • 799
  • 1
  • 6
  • 15
0
votes
1 answer

lmfit, result.plot_fit(ax) not plotting all 3 plots in pyqt

I have a pyqt5 widget class MPLibWidget(QtWidgets.QWidget): """ base MatPlotLib widget """ def __init__(self, parent=None): super(MPLibWidget, self).__init__(parent) self.figure = Figure() self.canvas = FigureCanvasQTAgg(self.figure) …
Faller
  • 1,588
  • 3
  • 16
  • 27
0
votes
1 answer

how do I suppress the print of "Adding parameter" in lmfit

How do I suppress the printing of "Adding parameter" in the following code In [7]: from numpy import sqrt, pi, exp, linspace In [8]: import numpy as np In [9]: def gaussian(x, amp, cen, wid): ...: return amp * exp(-(x-cen)**2 /wid) …
Oren
  • 4,711
  • 4
  • 37
  • 63
0
votes
2 answers

Still having trouble with curve fitting

I already opened a question on this topic, but I wasn't sure, if I should post it there, so I opened a new question here. I have trouble again when fitting two or more peaks. First problem occurs with a calculated example function. xg =…
kire
  • 95
  • 2
  • 12