curve-fitting

Fitting a vector function with curve_fit in Scipy

夙愿已清 提交于 2019-11-28 05:40:06
问题 I want to fit a function with vector output using Scipy's curve_fit (or something more appropriate if available). For example, consider the following function: import numpy as np def fmodel(x, a, b): return np.vstack([a*np.sin(b*x), a*x**2 - b*x, a*np.exp(b/x)]) Each component is a different function but they share the parameters I wish to fit. Ideally, I would do something like this: x = np.linspace(1, 20, 50) a = 0.1 b = 0.5 y = fmodel(x, a, b) y_noisy = y + 0.2 * np.random.normal(size=y

OpenCV line fitting algorithm

孤者浪人 提交于 2019-11-28 05:05:38
I'm trying to understand OpenCV fitLine() algorithm. This is fragment of code from OpenCV: icvFitLine2D function - icvFitLine2D I see that there is some random function that chooses points for approximation, then computes distances from points to fitted line (with choosen points), then choose other points and tries to minimize distance with choosen distType . Can someone clarify what happens from this moment without hard mathematics and assuming no great statistic knowledge?. OpenCV code comments and variable names does not help me in understanding this code. HugoRune (This is an old question,

Curve fitting with y points on repeated x positions (Galaxy Spiral arms)

余生颓废 提交于 2019-11-28 01:29:13
I currently have a MATLAB program which takes RGB images of traced spiral arms from galaxies and selects the biggest arm component and plots only that. I have tried using matlab's built in curve fitting tool with smoothing spline to fit it and I get the following result: I have tried using interp1 with parametric fitting to only get bad results. Is there a way to fit this type of curve at all? Spektre Your fail is due to that you handle your 2D curve as function which is not the case (you got more y values for the same x ) and that is why the fit fails on the right side (when you hit the non

Loess Fit and Resulting Equation

时光总嘲笑我的痴心妄想 提交于 2019-11-27 23:10:43
I'm a developer up in Portland, OR. I'm wondering if anyone can assist: I'm working on Loess fit models using R, once I have the fit accomplished, I'm looking to back-out the equation of the fitted non-linear curve, wondering if there is a way to determine this equation in R? I've been looking but can't find any literature. For me, the graph of the function is great, but without the equation of the graph, I'm kinda dead in the water. Loess doesn't give you an equation [1]. If you just want to get the values returned by the loess function you use predict(loess.object, new.data) [1] From

Curve Fitting to a time series in the format 'datetime'?

浪子不回头ぞ 提交于 2019-11-27 22:57:12
Here is my problem: polyfit does not take datetime values, so that I converted datetime with mktime producing the polynomial fit works z4 = polyfit(d, y, 3) p4 = poly1d(z4) For the plot however, I would like the datetime description on the axis and didn't # figure out how to do that. Can you help me? fig = plt.figure(1) cx= fig.add_subplot(111) xx = linspace(0, d[3], 100) pylab.plot(d, y, '+', xx, p4(xx),'-g') cx.plot(d, y,'+', color= 'b', label='blub') plt.errorbar(d, y, yerr, marker='.', color='k', ecolor='b', markerfacecolor='b', label="series 1", capsize=0, linestyle='') cx.grid() cx.set

Python curve fit library that allows me to assign bounds to parameters

家住魔仙堡 提交于 2019-11-27 20:50:32
I'd like to be able to perform fits that allows me to fit an arbitrary curve function to data, and allows me to set arbitrary bounds on parameters, for example I want to fit function: f(x) = a1(x-a2)^a3\cdot\exp(-\a4*x^a5) and say: a2 is in following range: (-1, 1) a3 and a5 are positive There is nice scipy curve_fit function, but it doesn't allow to specify parameter bounds. There also is nice http://code.google.com/p/pyminuit/ library that does generic minimalization, and it allows to set bounds on parameters, but in my case it did not coverge. Note: New in version 0.17 of SciPy Let's

Smooth spline representation of an arbitrary contour, f(length) --> x,y

泄露秘密 提交于 2019-11-27 19:10:19
Suppose I have a set of x,y coordinates that mark points along contour. Is there a way that I can build a spline representation of the contour that I can evaluate at a particular position along its length and recover interpolated x,y coordinates? It is often not the case that there is a 1:1 correspondence between X and Y values, so univariate splines are no good to me. Bivariate splines would be fine, but as far as I can tell all of the functions for evaluating bivariate splines in scipy.interpolate take x,y values and return z, whereas I need to give z and return x,y (since x,y are points on

Exponential curve fitting in SciPy

不想你离开。 提交于 2019-11-27 19:02:58
I have two NumPy arrays x and y . When I try to fit my data using exponential function and curve_fit (SciPy) with this simple code #!/usr/bin/env python from pylab import * from scipy.optimize import curve_fit x = np.array([399.75, 989.25, 1578.75, 2168.25, 2757.75, 3347.25, 3936.75, 4526.25, 5115.75, 5705.25]) y = np.array([109,62,39,13,10,4,2,0,1,2]) def func(x, a, b, c, d): return a*np.exp(b-c*x)+d popt, pcov = curve_fit(func, x, y) I get wrong coefficients popt [a,b,c,d] = [1., 1., 1., 24.19999988] What is the problem? First comment: since a*exp(b - c*x) = (a*exp(b))*exp(-c*x) = A*exp(-c*x

gaussian fit with scipy.optimize.curve_fit in python with wrong results

折月煮酒 提交于 2019-11-27 18:23:11
问题 I am having some trouble to fit a gaussian to data. I think the problem is that most of the elements are close to zero, and there not many points to actually be fitted. But in any case, I think they make a good dataset to fit, and I don't get what is confussing python. Here is the program, I have also added a line to plot the data so you can see what I am trying to fit #Gaussian function def gauss_function(x, a, x0, sigma): return a*np.exp(-(x-x0)**2/(2*sigma**2)) # program from scipy

Fit a curve for data made up of two distinct regimes

让人想犯罪 __ 提交于 2019-11-27 18:05:02
问题 I'm looking for a way to plot a curve through some experimental data. The data shows a small linear regime with a shallow gradient, followed by a steep linear regime after a threshold value. My data is here: http://pastebin.com/H4NSbxqr I could fit the data with two lines relatively easily, but I'd like to fit with a continuous line ideally - which should look like two lines with a smooth curve joining them around the threshold (~5000 in the data, shown above). I attempted this using scipy