lmfit

How to properly get the errors in lmfit

本秂侑毒 提交于 2021-02-11 17:42:21
问题 Hello I am trying to learn how to properly use lmfit and I think I am calculating the fit errors wrong. I have some data with errors on y and when I do the fit I call this (I tried for a simple linear fit): weight = 1/err out = line_fit.fit(y, pars, x=x, weights = weight) I assumed that this would calculate the chi square and use the errors in the denominator. However it seems to not work properly. The fit looks good and I am getting a reasonable value for the errors, but if I increase the

How to properly get the errors in lmfit

房东的猫 提交于 2021-02-11 17:41:02
问题 Hello I am trying to learn how to properly use lmfit and I think I am calculating the fit errors wrong. I have some data with errors on y and when I do the fit I call this (I tried for a simple linear fit): weight = 1/err out = line_fit.fit(y, pars, x=x, weights = weight) I assumed that this would calculate the chi square and use the errors in the denominator. However it seems to not work properly. The fit looks good and I am getting a reasonable value for the errors, but if I increase the

lmfit model fitting and then prediction

孤街浪徒 提交于 2021-02-10 21:54:19
问题 I was adopting lmfit to do a curve fitting and use that fitted model to do prediction. However, the following code did not achieve what I want. Could you please help? Thanks. import numpy as np from lmfit import Model def linearModel(x, a0, a1): return a0+a1*x #main code begin here X=[1,2,4] # data for fitting y=[2,4,6] # data for fitting gmodel = Model(linearModel) #select model params = gmodel.make_params(a0=1, a1=1) # initial params result = gmodel.fit(y, params, x=X) # curve fitting x1=[1

lmfit model fitting and then prediction

你。 提交于 2021-02-10 21:52:12
问题 I was adopting lmfit to do a curve fitting and use that fitted model to do prediction. However, the following code did not achieve what I want. Could you please help? Thanks. import numpy as np from lmfit import Model def linearModel(x, a0, a1): return a0+a1*x #main code begin here X=[1,2,4] # data for fitting y=[2,4,6] # data for fitting gmodel = Model(linearModel) #select model params = gmodel.make_params(a0=1, a1=1) # initial params result = gmodel.fit(y, params, x=X) # curve fitting x1=[1

How to find the area of a function (Pseudo Voigt) using optimized parameters from lmfit?

旧街凉风 提交于 2021-01-29 11:55:07
问题 I am trying to determine the area of a curve (peak). I was able to successfully fit the peak (data) using a Pseudo Voigt profile and a exponential background and get the fitting parameters out which agree with parameters obtained using commercial software. The issue is now trying to relate those fitted peak parameters to the area of the peak. I could not find an simple method of using the fitted parameters to calculate the area of the peak unlike in the case with a Gaussian line shape. So I

Python LMFIT restriction fit parameters

旧城冷巷雨未停 提交于 2021-01-29 10:24:51
问题 I'm trying to fit a function to some data in Python using the LMFIT library for nonlinear functions. It's easy enough, but I want to know if there's a way to restrict some properties of the fitted values. For example, in the following code I fit my data to optimize values A, B and C. But I also want the ratio of A to B to be pi/4 times some integer. Is there a way to impose this restriction? from lmfit import Model import numpy from numpy import cos, sin, pi, linspace Upload data: data =

Constraint on parameters in lmfit

一个人想着一个人 提交于 2021-01-29 06:28:47
问题 I am trying to fit 3 peaks using lmfit with a skewed-Voigt profile (this is not that important for my question). I want to set a constraint on the peaks centers of the form: peak1 = SkewedVoigtModel(prefix='sv1_') pars.update(peak1.make_params()) pars['sv1_center'].set(x) peak2 = SkewedVoigtModel(prefix='sv2_') pars.update(peak2.make_params()) pars['sv2_center'].set(1000+x) peak3 = SkewedVoigtModel(prefix='sv3_') pars.update(peak3.make_params()) pars['sv3_center'].set(2000+x) Basically I want

Fitting “multimodal” lognormal distributions to data using python

谁都会走 提交于 2021-01-28 18:42:46
问题 I have the following data measured using an instrument in the lab. Since the instrument collects particles of different sizes in bins based upon their diameter the measurements are essentially "binned": import numpy as np import matplotlib.pylab as plt from lmfit import models y = np.array([196, 486, 968, 2262, 3321, 4203, 15072, 46789, 95201, 303494, 421484, 327507, 138931, 27973]) bins = np.array([0.0150, 0.0306, 0.0548, 0.0944, 0.1540, 0.2560, 0.3830, 0.6050, 0.9510, 1.6400, 2.4800, 3.6700

Fitting “multimodal” lognormal distributions to data using python

十年热恋 提交于 2021-01-28 18:41:35
问题 I have the following data measured using an instrument in the lab. Since the instrument collects particles of different sizes in bins based upon their diameter the measurements are essentially "binned": import numpy as np import matplotlib.pylab as plt from lmfit import models y = np.array([196, 486, 968, 2262, 3321, 4203, 15072, 46789, 95201, 303494, 421484, 327507, 138931, 27973]) bins = np.array([0.0150, 0.0306, 0.0548, 0.0944, 0.1540, 0.2560, 0.3830, 0.6050, 0.9510, 1.6400, 2.4800, 3.6700

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

孤街浪徒 提交于 2021-01-04 02:38:46
问题 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] = 1 linear = np.all([[start <= x], [x <= end]], axis=0)[0] res[linear] = np.linspace(-1., 1., num=np.sum(linear)) return res if __name__ == '__main__': xdata = np.linspace(0., 1000., 1000) ydata = -np.ones(1000) ydata[500:1000] = 1. ydata = ydata + np.random