f(x, y) function approximation
I ha开发者_如何学运维ve a f(x, y) = z function (table-defined on uniform grid) and need to approximate it; this function is smooth. Approximation results must be as close to original as possible, derivatives are less important. Function domain is rectangular. Suggest approaches to solve this task plz.
UPD I need approximation, not interpolation.
UPD2 Shape of this function is quite similar to earth surface UPD3 My main task is to describe surface with smaller count of points, while retaining it's shape as close to original as possible.I'd be inclined to suggest NURBS approximations for this. You can make an approximate fit in a "least squares" sense. See for example The NURBS book (Piegl and Tyler, 1997), §9.4.3. In terms of freely available implementations I believe NURBS++ has an implementation of this algorithm (be sure to check the patch tracker before trying to make it compile with any modern compiler). Octave has a NURBS package, which I've not used before and I think R has a fairly comprehensive one too.
If you're arriving at this point from a probabilistic approach then something like "mixture of Gaussian" using an EM 'like' algorithm or 'Kriging' might make more sense.
So you have the function values at set intervals like (0,0),(0,1),(1,0),(1,1),etc..? I don't think there's any 'best' way to approximate the values in between. You say the functions is 'smooth', so averaging the surrounding values might be nice.
Given a grid with point intervals (xInterval,yInterval); x going right and y going up; I'd say something like this:
public void setAverage(float y, float x) {
float dy = (y - yBottom)/yInterval;
float leftAvgr = leftTopValue * dy + leftBottomValue * (1-dy);
float rightAvrg = rightTopValue * dy + rightBottomValue * (1-dy);
float dx = (x - xLeft)/xInterval;
float avrg = rightAvrg * dx + leftAvgr * (1 - dx);
}
精彩评论