How to compute mean squared error of interpolated data?

Hi, I was asked to compute the MSE of data that is interpolated using griddata() with respect to the original true data given by a computation formula. However when I tried it like this:
x = rand(200, 1);
y = rand(200, 1);
z = exp(x.^2).*y.*x;
[X,Y] = meshgrid(x,y);
Z = exp(X.^2).*Y.*X;
contour(X,Y,Z)
Zp = griddata(x,y,z,X,Y);
MSE = mean((Zp-Z).^2)
all element of MSE is NA, and the Zp is exactly the same as Z. Any hints why this didn't work out and how can I calculate the MSE correctly? Thanks!

2 Comments

You will get NaN's in Zp due to extrapolation....this is not the right way to check.
Thank you! So how should I interpolate the data and get the right MSE?

Sign in to comment.

Answers (1)

Your problem is that the interpolation will, by definition, match the values of your data at the points of your data, just try the same thing for a 1-D set of points with interp1. If you want to make some non-linear fit of points to a scattered set of points (which might be the better way to go about the re-interpolation task when there's noise in your data), you could try matlab's spline-fitting function spap2, or some of the FEX-contributions - I've used gridfit, and there are newer tools that also handles higher-dimensional cases: regularizeNd.
HTH

Categories

Find more on Interpolation in Help Center and File Exchange

Asked:

on 3 Nov 2020

Answered:

on 3 Nov 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!