curve-fitting

How can I fit a curve to a histogram distribution?

Someone asked me a question via e-mail about integer partitions the other day (as I had released a Perl module, Integer::Partition, to generate them), that I was unable to answer. Background: here are all the integer partitions of 7 (the sum of each row equals 7). 7 6 1 5 2 5 1 1 4 3 4 2 1 4 1 1 1 3 3 1 3 2 2 3 2 1 1 3 1 1 1 1 2 2 2 1 ...

Curve Fitting 3D data set

The curve-fitting problem for 2D data is well known (LOWESS, etc.) but given a set of 3D data points, how do I fit a 3D curve (eg. a smoothing/regression spline) to this data? MORE: I'm trying to find a curve, fitting the data provided by vectors X,Y,Z which have no known relation. Essentially, I have a 3D point cloud, and need to find...

How to calculate the vertex of a parabola given three points

I have three X/Y points that form a parabola. I simply need to calculate what the vertex of the parabola is that goes through these three points. Preferably a quick way as I have to do a LOT of these calculations! The "Ask A Scientist" website provides this answer: The general form of a parabola is given by the equation: A * x^2 + B...

Curve fitting implementation using least square method in C++

I am trying to write C++ function perform curve fitting implementation using least square method. Input parameters of this function are x and y 1D array and n. And this function finds the coefficients of a polynomial p(x) of degree n that fits the data, p(x(i)) to y(i), in a least squares sense. Therefore, function will return coeffic...

Java curve fitting library

I'm hoping to find a simple library that can take a series of 2 dimensional points and give me back a larger series of points that model the curve. Basically, I want to get the effect of curve fitting like this sample from JFreeChart: The problem with JFreeChart is that the code does not provide this type of api. I even looked at the ...

How do I calculate r-squared using Python and Numpy?

I'm using Python and Numpy to calculate a best fit polynomial of arbitrary degree. I pass a list of x values, y values, and the degree of the polynomial I want to fit (linear, quadratic, etc.). This much works, but I also want to calculate r (coefficient of correlation) and r-squared(coefficient of determination). I am comparing my re...

Curve fitting unsorted points on a plane

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 correc...

How does the Levenberg–Marquardt algorithm work in detail but in an understandable way?

Im a programmer that wants to learn how the Levenberg–Marquardt curvefitting algorithm works so that i can implement it myself. Is there a good tutorial anywhere that can explain how it works in detail with the reader beeing a programmer and not a mathemagician. My goal is to implement this algorithm in opencl so that i can have it run ...

Goodness of fit functions in R

What functions do you use in R to fit a curve to your data and test how well that curve fits? What results are considered good? ...

How to make topographic map from sparse sampling data?

I need to make a topographic map of a terrain for which I have only fairly sparse samples of (x, y, altitude) data. Obviously I can't make a completely accurate map, but I would like one that is in some sense "smooth". I need to quantify "smoothness" (probably the reciprocal the average of the square of the surface curvature) and I wan...

Finding a curve to match data

I'm looking for a non-linear curve fitting routine (probably most likely to be found in R or Python, but I'm open to other languages) which would take x,y data and fit a curve to it. I should be able to specify as a string the type of expression I want to fit. Examples: "A+B*x+C*x*x" "(A+B*x+C*x*x)/(D*x+E*x*x)" "sin(A+B*x)*exp(C+D*x)+...

On the issue of automatic time series fitting using R

we have to fit about 2000 or odd time series every month, they have very idiosyncratic behavior in particular, some are arma/arima, some are ewma, some are arch/garch with or without seasonality and/or trend (only thing in common is the time series aspect). one can in theory build ensemble model with aic or bic criterion to choose the b...

Fitting a density curve to a histogram in R

Is there a function in R that fits a curve to a histogram? Let's say you had the following histogram hist(c(rep(65, times=5), rep(25, times=5), rep(35, times=10), rep(45, times=4))) It looks normal, but it's skewed. I want to fit a normal curve that is skewed to wrap around this histogram. This question is rather basic, but I can't ...

Fitting a step function

I am trying to fit a step function using scipy.optimize.leastsq. Consider the following example: import numpy as np from scipy.optimize import leastsq def fitfunc(p, x): y = np.zeros(x.shape) y[x < p[0]] = p[1] y[p[0] < x] = p[2] return y errfunc = lambda p, x, y: fitfunc(p, x) - y # Distance to the target function x ...

"OCR" for a graph - scraping sample values from a plot image

This isn't really OCR, since it's not recognizing characters, but it's the same idea. Anyone know of an image-processing library or established algorithm for retrieving the values from a (raster) plot image? For instance, in this graph, it's hard for me to read exact values with my eyes because there's such gaps between gridlines: I...

Is it possible to do an algebraic curve fit with just a single pass of the sample data?

I would like to do an algebraic curve fit of 2D data points, but for various reasons - it isn't really possible to have much of the sample data in memory at once, and iterating through all of it is an expensive process. (The reason for this is that actually I need to fit thousands of curves simultaneously based on gigabytes of data whic...

Loess Fit and Resulting Equation

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 ...

Bezier Curve and French Curves

I am using Bezier curves to plot curves in a program I am making. I have five points. Here is a crude sketch of the curve I am trying to create. I'm trying to make a curve that goes through A,B,C,D. However, C is not a definite point, it is a suggestion of where the curve should pass through to make it look like a French Curve. C com...

Fitting a gauss curve to a certain histogram peak in c++

I have two questions concerning fitting a gauss curve to histogram peaks. My first question is a very basic one: How can I fit a gauss curve to a entire histogram? Does this only mean that I have to find out and calculate the mean value(µ) and the deviation(ϭ) of the histogram and put them into the formula for the Gauss curve? Would ...

Smooth local celing function

I have a gray-scale image and I want to make a function that closely follows the image is always grater than it the image smooth at some given scale. In other words I want a smooth function that approximates the maximum of another function in the local region while over estimating the that function at all points. Any ideas? My...