curve-fitting

Linear curve fitting with errors

假如想象 提交于 2019-12-04 04:57:57
I was looking for a way to perform a linear curve fit in Javascript. I found several libraries, but they don't propagate errors. What I mean is, I have data and associated measurement errors, like: x = [ 1.0 +/- 0.1, 2.0 +/- 0.1, 3.1 +/- 0.2, 4.0 +/- 0.2 ] y = [ 2.1 +/- 0.2, 4.0 +/- 0.1, 5.8 +/- 0.4, 8.0 +/- 0.1 ] Where my notation a +/- b means { value : a, error : b } . I want to fit this into y = mx + b , and find m and b with their propagated errors. I know the Least Square Method algorithm, that I could implement, but it only take errors on the y variable, and I have distinct errors in

ValueError: operands could not be broadcast together with shapes (0) (26) when using optimize.curve

北战南征 提交于 2019-12-04 04:28:33
问题 I'm trying to get a best fit line to some data my script generates. This is what I have: import numpy as np import scipy as sp . . . def func(x, a, b, c): return a*np.exp(-b*x) + c popt, pcov = sp.optimize.curve_fit(func, numgelt, turnsG) I keep getting this error: ValueError: operands could not be broadcast together with shapes (0) (26) I have checked and the two arrays (numgelt and turnsG) are definitely the same size. I've also ensured that the entries are float. Thank you! 回答1: I had the

How to fit polynomial to data with error bars

若如初见. 提交于 2019-12-04 03:54:42
I am currently using numpy.polyfit(x,y,deg) to fit a polynomial to experimental data. I would however like to fit a polynomial that uses weighting based on the errors of the points. I have found scipy.curve_fit which makes use of weights and I suppose I could just set the function, 'f', to the form a polynomial of my desired order, and put my weights in 'sigma', which should achieve my goal. I was wondering is there another, better way of doing this? Many Thanks. Bernhard Take a look at http://scipy-cookbook.readthedocs.io/items/FittingData.html in particular the section 'Fitting a power-law

Modifying a curve to prevent singular gradient matrix at initial parameter estimates

杀马特。学长 韩版系。学妹 提交于 2019-12-04 03:20:51
问题 I want to use y=a^(b^x) to fit the data below, y <- c(1.0385, 1.0195, 1.0176, 1.0100, 1.0090, 1.0079, 1.0068, 1.0099, 1.0038) x <- c(3,4,5,6,7,8,9,10,11) data <- data.frame(x,y) When I use the non-linear least squares procedure, f <- function(x,a,b) {a^(b^x)} (m <- nls(y ~ f(x,a,b), data = data, start = c(a=1, b=0.5))) it produces an error: singular gradient matrix at initial parameter estimates. The result is roughly a = 1.1466, b = 0.6415, so there shouldn't be a problem with intial

Exponential curve fit matlab

我与影子孤独终老i 提交于 2019-12-04 02:13:45
问题 I have the following equation: I want to do a exponential curve fitting using MATLAB for the above equation, where y = f(u,a) . y is my output while (u,a) are my inputs. I want to find the coefficients A,B for a set of provided data. I know how to do this for simple polynomials by defining states. As an example, if states= (ones(size(u)), u u.^2) , this will give me L+Mu+Nu^2 , with L , M and N being regression coefficients. However, this is not the case for the above equation. How could I do

how to find out the scaling factors to match two curves in matlab?

拈花ヽ惹草 提交于 2019-12-04 02:11:28
问题 I have two data sets obtained at different days. The results I got from two different data sets have similar shape but different values (see fig1). I am trying to match the second data set (x2,y2) to the first one (x1,y1) by multiply a constant A in x and B in y of the second data (see fig2). for example: data1: x1=[-0.3:0.06:2.1]'; y1=[ 0.001 0.001 0.004 0.014 0.052 0.166 0.330 0.416 0.340 0.247 0.194 0.197 0.237 0.330 0.428 0.542 0.669 0.767 0.855 0.900 0.913 0.904 0.873 0.811 0.765 0.694 0

Why isn't `curve_fit` able to estimate the covariance of the parameter if the parameter fits exactly?

旧城冷巷雨未停 提交于 2019-12-04 01:52:58
I don't understand curve_fit isn't able to estimate the covariance of the parameter, thus raising the OptimizeWarning below. The following MCVE explains my problem: MCVE python snippet from scipy.optimize import curve_fit func = lambda x, a: a * x popt, pcov = curve_fit(f = func, xdata = [1], ydata = [1]) print(popt, pcov) Output \python-3.4.4\lib\site-packages\scipy\optimize\minpack.py:715: OptimizeWarning: Covariance of the parameters could not be estimated category=OptimizeWarning) [ 1.] [[ inf]] For a = 1 the function fits xdata and ydata exactly. Why isn't the error/variance 0 , or

Difference between Levenberg-Marquardt-Algorithm and ODR

偶尔善良 提交于 2019-12-03 22:13:56
I was able to fit curves to a x/y dataset using peak-o-mat , as shown below. Thats a linear background and 10 lorentzian curves. Since I need to fit many similar curves I wrote a scripted fitting routine, using mpfit.py , which is a Levenberg-Marquardt-Algorithm. However the fit takes longer and, in my opinion, is less accurate than the peak-o-mat result: Starting values Fit result with fixed linear background (values for linear background taken from the peak-o-mat result) Fit result with all variables free I believe the starting values are already very close, but even with the fixed linear

How to fit a curve to a damped sine wave in matlab

隐身守侯 提交于 2019-12-03 21:51:14
I have some measurements done and It should be a damped sine wave but I can't find any information on how to make (if possible) a good damped sine wave with Matlab's curve fitting tool. Here's what I get using a "Smoothing spline": Image http://s21.postimg.org/yznumla1h/damped.png . Edit 1 : Here's what I got using the "custom equation" option: Edit 2 : I've uploaded the data to pastebin in csv format where the first column is the amplitude and the second is the time. The damped sin function can be created using the following code: f=f*2*pi; t=0:.001:1; y=A*sin(f*t + phi).*exp(-a*t); plot(t,y)

Fitting an exponential modified gaussian curve to data with Python

随声附和 提交于 2019-12-03 20:43:16
I have a data set and a kernel density estimate for those data. I believe the KDE should be reasonably well described by an exponentinally modified Gaussian , so I'm trying to sample from the KDE and fit those samples with a function of that type. However, when I try to fit using scipy.optimize.curve_fit, my fit doesn't match the data well at all. My code is import scipy.special as sse from scipy.optimize import curve_fit def fit_func(x, l, s, m): return 0.5*l*n.exp(0.5*l*(2*m+l*s*s-2*x))*sse.erfc((m+l*s*s-x)/(n.sqrt(2)*s)) # exponential gaussian popt, pcov = curve_fit(fit_func, n.linspace(0,1