lmfit

Constraints on curve fitting parameters

三世轮回 提交于 2019-12-25 08:25:23
问题 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 lmfit import Model, Parameters #create x and y data to be used for curve fitting xip=[ 0.02237461, 0.0983837 , 0.25707382, 0.56959641, 1.33419197, 4.95835927] yip=[0.20085822, 0.23583258, 0.28996988, 0.36350284, 0.47981232, 0.67602165] #function to

importing lmfit succesfull but importing Model from lmfit not

本小妞迷上赌 提交于 2019-12-25 01:21:58
问题 I have installed lmfit trough PIP pip install lmfit==0.7.2 importing lmfit in ipython notebook seems to work. That is, the import does not give any error messages and I can call a bunch of functions from lmfit. However when i try to import Model from lmfit it gives me an import error: from lmfit import Model The import error. --------------------------------------------------------------------------- ImportError Traceback (most recent call last) <ipython-input-151-3ba1b6658da4> in <module>()

Fitting a multi-peak function to a DataSet using LMFIT

帅比萌擦擦* 提交于 2019-12-23 03:33:08
问题 I'm trying to make a multi-lorentzian fitting using the LMFIT library, but it's not working and I even understand that the syntax of what I made is completelly wrong, but I don't have any new ideas. My problem is this: I have a very long spectra with multiple sets of peaks, but the number of peaks is not constant in these sets, so sometimes I will have just 1 peak, but sometimes I might have 8 or even 20. #function definition: def Lorentzian(x, amp, cen, wid, n): f = 0 for i in range( int(n)

Python lmfit: Fitting a 2D Model

冷暖自知 提交于 2019-12-22 12:29:13
问题 I'm trying to fit a 2D-Gaussian to some greyscale image data, which is given by one 2D array. The lmfit library implements a easy-to-use Model class, that should be capable of doing this. Unfortunately the documentation (http://lmfit.github.io/lmfit-py/model.html) does only provide examples for 1D fitting. For my case I simply construct the lmfit Model with 2 independent variables. The following code seems valid for me, but causes scipy to throw a "minpack.error: Result from function call is

Python: importing lmfit.models fails

十年热恋 提交于 2019-12-13 04:44:41
问题 This post is related to my other one where I was told to use lmfit to fix my problem. I installed lmfit in anaconda Prompt with conda install --channel "conda-forge" lmfit which worked. But now when I try to use it in my Programm I get the following error: ModuleNotFoundError: No module named 'lmfit.model'; 'lmfit' is not a package Thats how the beginning of my Program looks like: import numpy as np import math import scipy #I dont need scipy, but I read, that lmfit needs scipy. It doesn't

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

妖精的绣舞 提交于 2019-12-12 04:18:07
问题 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 use scipy.integrate.quad for this purpose and the features of lmfit, but I do not get -at least- to simulate a reasonable curve (see the code below). Some real physical parameters that can be used to simulate this equation are: Dm = 3.2E-9 m, w = 0

Trouble with curve fitting - lmfit won't produce proper fit to peak data

删除回忆录丶 提交于 2019-12-12 01:39:37
问题 I'm quite new to python and the lmfit model and having some trouble. I want to fit a peak function (something like Gaussian or Voigtian profil) to my experimental data, but it never gives me any good results. Its best fit is a linear function, which kind of describes the base line of my peak profile. The x data for the fitting process are simply numbers running from 0 to 100. Here are my y data: array([ 0.99518284, 0.99449661, 0.99609029, 0.996 , 0.994307 , 0.999693 , 0.99826185, 0.99680361,

Creating a python lmfit Model with arbitrary number of parameters

邮差的信 提交于 2019-12-11 04:27:27
问题 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 return func #note: below does not work my_model = Model(my_poly, independent_vars = ['x'], param_names = ['A','B','C']) Something similar to the above would be wonderful if I am interested in a polynomial series and want to test the performance as the series

Fitting complex model using Python and lmfit?

我是研究僧i 提交于 2019-12-10 13:37:30
问题 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 picewise approach, but is there any way to do it directly with complex function? Fitting only real part of function works beautifully, but when I define complex residual function I get: TypeError: no ordering relation is defined for complex numbers. Below

Scipy curve_fit bounds and conditions

拟墨画扇 提交于 2019-12-08 12:24:59
问题 I am trying to use curve_fit to fit some data. it is working great, I would just like to improve the fit with additional parameters to match assumptions (such as mechanical efficiency cannot be greater than 100% etc) y_data = [0.90 0.90 0.90 0.90 0.90 0.90 0.90 1.30 1.30 1.30 1.30 1.20 1.65 1.65 1.65 1.65 1.65 1.65 1.80 1.80 1.80 1.80 1.80 1.80 1.80 1.80 1.80 3.50 6.60 6.60 6.70 6.70 6.70 6.70 6.70 8.50 12.70] # I am aware this does not have commas x_data = [0.38 0.38 0.38 0.38 0.38 0.38 0.38