curve-fitting

Python curve_fit choice of bounds and initial condition affect the result

拥有回忆 提交于 2019-12-03 20:33:35
问题 I have a data set that is described by two free parameters which I want to determine using optimalization.curve_fit . The model is defined as follows def func(x, a, b,): return a*x*np.sqrt(1-b*x) And the fitting part as popt, pcov = opt.curve_fit(f = func, xdata = x_data, ydata= y_data, p0 = init_guess, bounds = ([a_min, b_min], [a_max, b_max])) The outcome of the solutions for a and b depends quite strong on my choice of init_guess , i.e. the initial guess and also on the choice of the

Gaussian fit in C#

亡梦爱人 提交于 2019-12-03 17:37:55
In a project I'm working on I need to obtain a Gaussian fit from a set of points - needing mean and variance for some processing, and possibly an error degree (or accuracy level) to let me figure out if the set of points really have a normal distribution. I've found this question but it is limited to 3 points only - whereas I need a fit that can work with any number of points. What I need is similar to the labview Gaussian Peak Fit I have looked at mathdotnet and aforge.net (using both in the same project), but I haven't found anything. Does anybody know any C# or (easily convertible) C/C++ or

How to determine the uncertainty of fit parameters with Python?

懵懂的女人 提交于 2019-12-03 17:11:14
问题 I have the following data for x and y: x y 1.71 0.0 1.76 5.0 1.81 10.0 1.86 15.0 1.93 20.0 2.01 25.0 2.09 30.0 2.20 35.0 2.32 40.0 2.47 45.0 2.65 50.0 2.87 55.0 3.16 60.0 3.53 65.0 4.02 70.0 4.69 75.0 5.64 80.0 7.07 85.0 9.35 90.0 13.34 95.0 21.43 100.0 For the above data, I am trying to fit the data in the form: However, there are certain uncertainties associated with x and y, where x has uncertainty of 50% of x and y has a fixed uncertainty. I am trying to determine the uncertainty in the

scipy.optimize.curvefit() - array must not contain infs or NaNs

╄→尐↘猪︶ㄣ 提交于 2019-12-03 16:29:46
问题 I am trying to fit some data to a curve in Python using scipy.optimize.curve_fit. I am running into the error ValueError: array must not contain infs or NaNs . I don't believe either my x or y data contain infs or NaNs: >>> x_array = np.asarray_chkfinite(x_array) >>> y_array = np.asarray_chkfinite(y_array) >>> To give some idea of what my x_array and y_array look like at either end ( x_array is counts and y_array is quantiles): >>> type(x_array) <type 'numpy.ndarray'> >>> type(y_array) <type

Fit sine wave with a distorted time-base

百般思念 提交于 2019-12-03 15:50:34
I want to know the best way to fit a sine-wave with a distorted time base, in Matlab. The distortion in time is given by a n-th order polynomial (n~10), of the form t_distort = P(t) . For example, consider the distortion t_distort = 8 + 12t + 6t^2 + t^3 (which is just the power series expansion of (t-2)^3 ). This will distort a sine-wave as follows: I want to be able to find the distortion given this distorted sine-wave. (i.e. I want to find the function t = G(t_distort) , but t_distort = P(t) is unknown.) Here's an analytical driven route that takes asin of the signal with proper unwrapping

Restricting values for curve_fit (scipy.optimize)

柔情痞子 提交于 2019-12-03 15:18:26
I'm trying to fit a logistic growth curve to my data using curve_fit using the following function as the input. def logistic(x, y0, k, d, a, b): if b > 0 and a > 0: y = (k * pow(1 + np.exp(d - (a * b * x) ), (-1/b) )) + y0 elif b >= -1 or b < 0 or a < 0: y = (k * pow(1 - np.exp(d - (a * b * x) ), (-1/b) )) + y0 return y As you can see the function i am using has some restrictions on the values it can accept for parameter a and b. Any guess on how to handle the incorrect values? Should the input function raise an exception or return a dummy value? Thanks in advance. When the parameters fall out

Curve fitting unsorted points on a plane

邮差的信 提交于 2019-12-03 14:38:50
问题 Question: How do you fit a curve to points on a plane if they aren't single valued? For the example shown, how would one fit a curve (like the black one) to the noisy blue data? It's similar to spline smoothing, but I don't know the order of the data. Matlab would be preferred, but pseudocode is fine. Or a pointer to what the correct terminology for this problem is would be great. Thanks 回答1: Your data look like a two-dimensional parametric plot of (x,y) as a function of some underlying

Linear fitting in python with uncertainty in both x and y coordinates [closed]

好久不见. 提交于 2019-12-03 13:58:42
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 months ago . Hi I would like to ask my fellow python users how they perform their linear fitting. I have been searching for the last two weeks on methods/libraries to perform this task and I would like to share my experience: If you want to perform a linear fitting based on the least-squares method you have many options.

Automatic curve fitting in R

半城伤御伤魂 提交于 2019-12-03 13:56:30
问题 Is there any package that automatically fits a curve using many simple models? By simple models I mean: ax+b ax^2+bx+c a*log(x) + b a*x^n+b ax/(1+bx) ax^n/(1+bx^n) ... The best would be to have a function that takes two vector parameters X and Y and returns a list of fitted simple models with their SSE. 回答1: Try this. rhs is a character vector of right sides and x and y are the data. It constructs the formula fo for each and then extracts the parameters and sets each to 1 for the starting

How to fit more than one line to data points

跟風遠走 提交于 2019-12-03 13:19:20
问题 I am trying to fit more than one line to a list of points in 2D. My points are quite low in number (16 or 32). These points are coming from a simulated environment of a robot with laser range finders attached to its side. If the points lie on a line it means that they detected a wall , if not, it means they detected an obstacle . I am trying to detect the walls and calculate their intersection, and for this I thought the best idea is to fit lines on the dataset. Fitting one line to a set of