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
16
votes
2 answers

scipy curve_fit raises "OptimizeWarning: Covariance of the parameters could not be estimated"

I am trying to fit this function to some data: But when I use my code import numpy as np from scipy.optimize import curve_fit import matplotlib.pyplot as plt def f(x, start, end): res = np.empty_like(x) res[x < start] =-1 res[x > end]…
Jonas
  • 1,838
  • 4
  • 19
  • 35
15
votes
2 answers

Python and lmfit: How to fit multiple datasets with shared parameters?

I would like to use the lmfit module to fit a function to a variable number of data-sets, with some shared and some individual parameters. Here is an example generating Gaussian data, and fitting to each data-set individually: import numpy as…
Merlin
  • 297
  • 1
  • 3
  • 10
8
votes
1 answer

ValueError: The input contains nan values - from lmfit model despite the input not containing NaNs

I'm trying to build a model using lmfit (link to docs) and I can't seems to find out why I keep getting a ValueError: The input contains nan values when I try to fit the model. from lmfit import minimize, Minimizer, Parameters, Parameter,…
Jason
  • 4,346
  • 10
  • 49
  • 75
6
votes
2 answers

Curve fit with parameter bounds

I have experimental data : xdata =…
KhanSuleyman
  • 109
  • 8
6
votes
1 answer

Fitting complex model using Python and lmfit?

I would like to fit ellipsometric data to complex model using LMFit. Two measured parameters, psi and delta, are variables in a complex function rho. I could try with separating problem to real and imaginary part with shared parameters or piecewise…
Jur Kravla
  • 61
  • 1
  • 3
5
votes
2 answers

Use Python lmfit with a variable number of parameters in function

I am trying to deconvolve complex gas chromatogram signals into individual gaussian signals. Here is an example, where the dotted line represents the signal I am trying to deconvolve. I was able to write the code to do this using…
user14241
  • 727
  • 1
  • 8
  • 27
4
votes
1 answer

How do I fit an exponential decay curve which accounts for uncertainties?

I have some radioactive decay data, which has uncertainties in both x and y. The graph itself is all good to go, but I need to plot the exponential decay curve and return the report from the fitting, to find the half-life, and reduced chi^2. The…
Epideme
  • 209
  • 3
  • 11
4
votes
1 answer

Python lmfit reduced chi-square too small after weighted fit

I am running a fit in Python 2.7 with lmfit using some test data with the following code. I require a weighted fit with weights of 1/y (with the Leven-Marq. routine). I have defined weights and am using them here: from __future__ import…
edesz
  • 11,756
  • 22
  • 75
  • 123
4
votes
1 answer

python lmfit: voigt fitting - difference between out.best_fit and out.best_values

I am struggling to write a code for fitting a Voigt profile to experimental data. For now I get sometimes a reasonable fit function but I need to do automatic about 1000 fits. That means it is not an opportunity if every second fit is off. I tried…
oigen
  • 43
  • 5
4
votes
1 answer

Creating a python lmfit Model with arbitrary number of parameters

Is there a way to construct a an lmfit Model based on a function with an arbitrary number of dependent variables? For example: from lmfit import Model def my_poly(x, *params): func = 0 for i in range(len(params)): func+= params[i]*z**i …
Brian Pollack
  • 198
  • 3
  • 12
4
votes
2 answers

Uncertainties on fitted parameters in lmfit

I'm looking for the easiest way of outputting the uncertainty in the fitted parameters. With spo.curve_fit, we just get the covariance matrix when we fit and we can take the diagonal and square root to find the uncertainties. With lmfit it doesn't…
danm
  • 117
  • 2
  • 10
3
votes
1 answer

curve fitting to an ordinary differential equation

I want to fit a curve to the ODE shown below- dA/dt = k1*profit + k2 I have the observed time series of the variables A and profit and I would like to get the optimal values of k1 and k2 using a curve fitting technique in python. I am able to write…
lsr729
  • 752
  • 2
  • 11
  • 25
3
votes
1 answer

Scipy minimize / Scipy Curve fit / lmfit

log(VA) = gamma - (1/eta)log[alphaL^(-eta) + betaK^(-eta)] I'm trying to estimate the above function with nonlinear least squares. I am using 3 different packages (Scipy-minimize, Scipy-curve_fit and lmfit - Model) for this but I find different…
3
votes
1 answer

Julia - Equivalent of Python lmfit

I would like to minimize x and y in function f using least square (Levenberg-Marquardt). In Python I can use lmfit like follows params = lmfit.Parameters() params.add('x', value=0, min=-np.pi, max=np.pi) params.add('y', value=0.0, min=-0.25,…
Darren Christopher
  • 3,893
  • 4
  • 20
  • 37
3
votes
2 answers

How to fix 'The array returned by a function changed size between calls' while using lmfit for minimization?

How can I fix code with error 'The array returned by a function changed size between calls' while using lmfit for minimization? Please find my code below: import numpy as np import pandas as pd import lmfit as lf #model needs to be fitted x0 =…
Ankita Bera
  • 35
  • 2
  • 6
1
2 3
25 26