Determine in an interpolation the contribution of each node nearby
조회 수: 2 (최근 30일)
이전 댓글 표시
Hello,
I applied an interpolation using the cubic spline on a set of points. Is there any possible way I can find the contribution of the neighbouring nodes to the interpolation in the location I'm on? I know all nodes affects the interpolation but basically I want to find for each node, what are the most significant nodes that are mostly affecting the interpolation.
Thank you
댓글 수: 0
채택된 답변
John D'Errico
2022년 10월 14일
편집: John D'Errico
2022년 10월 15일
The most significant nodes? The nearest neighbors to a given point. Beyond that, the significance will die off, probably exponentially in some way, though it will oscillate.
But what you ask is actually moderately easy. A cubic spline is linear in the values of the functions at the nodes. That is, you can solve for the coefficients of the cubic spline using a linear system of equations. Therefore, those coefficients are a linear function of the values of y at each data point. And then the prediction itself? Again, a linear combination of the coefficients, where the linear combination is itself not linear, but you don't really care about that. This tells you that you can do exactly what you are asking for in a simple way.
For example, consider the set of points
x = 1:10;
y = sin(x); % y can be ANYTHING you want here.
We could build a cubic spline on that support using spline.
spl = spline(x,y);
But now, suppose we were to perturb one data point, say, at x == 4? At that point, suppose we were to perturb the spline so at that point, we now have y(4)+dy? Leave ALL of the other data points alone.
The new spline, passing through that point will be just additive, as a sum of two splines.
y4p = zeros(size(x));
y4p(4) = 1;
spl4 = spline(x,y4p);
fnplt(spl4)
hold on
plot(x,y4p,'ro')
grid on
That is the perturbation introduced into a spline, as a function of a unit perturbation, applied at the point x==4.
Can you see that the influence of that point, on any point near it dies off as you move away from x==4? But as well, EVERY point has SOME influence on the value of the spline at all locations.
I think (hope) you can visualize how it will work. In fact, you could even build up the complete spline as a sum of terms like that. Think in terms of Green's functions. You can see there how each data point contributes to the value of the interpolant at any intermediate point. For example, try this:
nx = numel(x);
G = cell(1,nx);
for i = 1:nx
y0 = zeros(1,nx);
y0(i) = 1;
G{i} = spline(x,y0);
end
Now we have a set of unit splines, that again, we should be able to build the complete spline from, IF we wanted to do so. But in terms of the contribution of any data point to some intermediate location x, we can now try this:
N = 100;
X = linspace(x(1),x(end),N);
nodalinfluence = zeros(nx,N);
for i = 1:nx
nodalinfluence(i,:) = fnval(G{i},X);
end
% normalize the influences
nodalinfluence = abs(nodalinfluence)./sqrt(sum(nodalinfluence.^2,1));
mesh(nodalinfluence')
xlabel 'Node'
ylabel 'x'
view(20,70)
I'm not sure if that is what you would be asking for. But it should show the relative contribution of the value at each node to the interpolated function value at any given point along the curve.
This is different from modeling tools like pchip or makima, since they are nonlinear in a sense. Those tools will have ONLY the immediate 2 neighbors on both sides of a given point as being of influence, but even there, the relative influence is highest for the immediate neighbors, and it will decrease for the next pair of points further away. Again though, those tools are nonlinear functions of the value of the curve at any node, so you will not find some nice additive process like a Green's function.
댓글 수: 5
Walter Roberson
2022년 10월 16일
Interpolation could potentially differ slightly due to round-off error, depending on the implementation.
추가 답변 (1개)
Walter Roberson
2022년 10월 14일
As an approximation, and restricted to the case where the x coordinates of the spline are strictly increasing:
If you were to interp1() the query x coordinate against the indices of the x coordinates asking for 'nearest'
num_x = length(spline)x);
query_y = interp1(spline_x, spline_y, 'spline')
idx = interp1(spline_x, 1:num_x, query_x, 'nearest');
Now for idx > 1 & idx < num_x then spline_x(idx-1), spline_x(idx), spline_x(idx+1) and corresponding y values are three nearest nodes. From there you could calculate the distance between spline_x, spline_y to those three points, and use some kind of inverse distance to get weighting factors to give you an idea of how much the nodes contributed.
This will not be exact: to be exact you should take into account the derivative conditions.
Perhaps there is a better way by using spline() and pulling apart the piecewise polynomial.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Splines에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!