Radial base functions (RBF) can be used for interpolation and and approximation of scattered data i.e. data is not required to be on any regular grid. The same function can handle data interpolation in any dimension. See file rbftest.m for more examples.
1. Create RBF interpolation using
rbf=rbfcreate(x, f); ?x? ? coordinates of the nodes and ?f? - values of the function at the nodes
2. Calculate interpolated values ?fi? at nodes ?xi? using
fi = rbfinterp(xi, rbf); rbf ? is structure returned by rbf=rbfcreate(x, f)
x = 0:1.25:10; f = sin(x);
xi = 0:.1:10;
fi = interp1(x,f,xi);
% RBF interpolation
fi = rbfinterp(xi, rbf);
x = rand(50,1)*4-2; y = rand(50,1)*4-2; z = x.*exp(-x.^2-y.^2);
ti = -2:.05:2;
[XI,YI] = meshgrid(ti,ti);
ZI = griddata(x,y,z,XI,YI,'cubic');
rbf=rbfcreate([x'; y'], z');
ZI = rbfinterp([XI(:)'; YI(:)'], op);
ZI = reshape(ZI, size(XI));
1. Radial Base Function:
rbfcreate(x, f ,'RBFFunction', 'multiquadric');
available RBF functions are: multiquadric, gaussian, linear, cubic, thinplate
2. Smoothing level: (must be a positive scalar)
rbfcreate(x, f ,'RBFSmooth', 0.1);
3. Multiquadric and gaussian functions have definable constants
rbfcreate(x, f ,?RBFConstant', 0.1);
RBF interpolation usually produces much better results that standard Matlab functions but computation complexity of RBF interpolation is n^3 thus it is not recommended to use it for more then 2000 nodes.
Alex Chirokov (2020). Scattered Data Interpolation and Approximation using Radial Base Functions (https://www.mathworks.com/matlabcentral/fileexchange/10056-scattered-data-interpolation-and-approximation-using-radial-base-functions), MATLAB Central File Exchange. Retrieved .
Hello, I love your code, I was looking for a 2d approximation of a surface using scattered points and it does the trick perfectly BUT, the code lack isn't fast enough for real time processing of a large number of point. For example it already strugle to handle 1400 points in less than a second, and I am looking to compute a radiabasis approximation of my surface with a hundred thousand points. Do you have any ideas how I Could speed up the process so that the creation of the rbf and the following interpolation uses less computation time ?
@paul beauvilliers The general situation is even more difficult. Quality of RBF approximation strongly (!!!) depends on the signum of diagonal smoothing term and this signum depends on the type of RBF.
Update: The smoothing parameter DOES have an effect even with a value < 1 (but greater than zero of course). My previous comment/inquiry was derived from a comparison with another 1D smoothing function (Matlab's "csaps" function), where the effect of the smoothing parameter is much more dramatic/obvious. Can anyone can share insight regarding (pertinent) differences between the algorithm implemented here and that implemented in "csaps" (sticking to 1D for now)?
Is anyone else having difficulty with smoothing, using the "thin plate" basis function? [Even in 1D I'm not seeing any effect until the smoothing parameter gets very much above 1 ... and that just seems to add a lot of oscillations.]
How one can obtain the first and second derivatives (with a speed and accelerations at the beginning and at the end supposed null conditions "Vinit = Vfinal = 0 and Aint = Afinal = 0")
of the function f (x) modeled by RBF interpolation in 1D
help me, thank you
Why must be dim==dimPoints? Could I evaluate at just one (or a few) point(s) with coordinates of the evaluation point(s) different than those of the nodes?
% same acceleration ( 6 X ) possible in function [f] = rbfinterp(x, options).
f = zeros(1, nPoints);
r = zeros(1, n);
rbfcoeff_np1=rbfcoeff(n+1); % scalar
% r=repmat(x(:,i),1,n)-nodes; %safer ( old mlb ver <2016b)
% new mlb feature : implicit expansion
r=x(:,i)-nodes; % recent mlb versions 2016b>
r_sq = r(1,:).*r(1,:)+r(2,:).*r(2,:);
% r_sq = sum(r.*r,1); % ok
r_v = sqrt(r_sq);
s = rbfcoeff_np1 + rbfcoeff_1ton*(r_sq.*log(r_v+1))';
f(i) = s+rbfcoeff1_dim*x(1:dim,i);
% sensible speed-up (5 X on my HW) by avoiding the use of 'fval' to invoke functions and transforming the original nested loop into a simple parfor loop. see following example
function [A]=rbfAssemble(x, phi, const, smooth)
s = functions(phi) ,
if strcmp(s.function, 'rbfphi_thinplate')
% new section
% more readable but less performing :
% for j=1:i
% r=xvi(:,j); %
% less readable but more performing :
% end new section
Works nicely. Help should be implemented properly when using "help rbfinterp/rpfcreate".
One mis-spelling in the help comments: to use multiquadric the string has to be "multiquadric" not "multiquadrics"
good work ...
Perfect code, thanks!!!
please give me the programme of identification's systems no-linear with RBF network
Nice function. Only, for large data sets it easily runs into memory problems. This could be improved by using the fact that only half of the matrix A in rbfAssemble is actually needed, since it is symmetric.
While this is not a perfectly implemented code for the file exchange (see J. D'Errico's comments) - it is exactly what I was looking for and has proven extremely helpful for my engineering problem. The big ticket item for me was the ability to extrapolate scattered data (as well as interpolate). Thank you for providing this tool.
good stuff, thanks
very quickly, thanks!
Windows-only documentation, a complete waste of time
It seems the time is due to review this code again, at least Scott Andrews seems to think it is. Note that my first review was made before any improvements were made. It was an entirely accurate review at that time.
The Powerpoint doc is indeed quite helpful. But remember that when you choose to use this code in the future, it might be nice to have Matlab help available for these codes. I'll paste in the complete help provided for the rbfinterp function here:
Yes. That is right. There is no help. No indication of what the arguments mean. So next month when you want to use these tools, you should drop out of matlab and fire up this file into powerpoint just to remember what order the arguments follow and what they mean? Sorry, but this is ridiculous.
Back to the Powerpoint doc. The author chooses to make an apples to oranges comparison to show how good these tools are. Surely the author understands that use of Matlab's Pchip interpolant is a poor choice for interpolating an ocsillatory function? Had the author actually compared a true spline fit to the RBF model, the difference would have been far smaller. Conversely, It is trivial to show an example of a monotone function where pchip (the interp1 'cubic' interpolant) will shine, yet RBF interpolation will be miserable.
My earlier comments about the slowness of RBF interpolation are still valid. These techniques create dense matrices, so interpolation over thousands of points may be slow.
Overall, the powerpoint help improves these tools considerably. The lack of any help for a main function would have normally pulled my rating down farther, but the author deserves commendation for the effort expended on the ppt doc. The error checking is good, plus its a good implementation of the property/value pair interface in rbfcreate. Plus, these tools do provide an alternative to linear interpolation in multiple dimensions.
This is amazingly simple and well documented code. With regards to the prior reviewers comments, I'm not sure what aspect he believes difficult to use. I read the ppt included and was up and running in 5 minutes. Also, the package does interpolate and approximate. If the smoothing is off, then it interpolates exactly as advertised. The only slight downside is that the algo is a bit slow, but there is no way to fit high-dimensional data in any Mathworks package other than linear interpolations. As such, it is a wonderful addition.
A very good introduction to RBF method.
The code is concise and clear, no extra comments required to figure out how it works. The package is good to conduct a quick test of how RBF methods work in particular application. Good work!
This has potential. It also has virtually no help. No hints about how to use it, except by trying to read the uncommented test examples and guess what the options do. You will need to edit the code just to learn what the options are. Its a major flaw in a package that some might find as useful. I will also note that this package is touted as doing interpolation, but the examples show that smoothing was done. Interpolation REPRODUCES the original data. It should not smooth the data, so the description is inaccurate.
Finally, I'll repeat the athor's statement that this code will be slow for large sets of data. It will easily exceed your system memory since it generates large dense matrices.
I would have given this code a lower rating, except I also recognize that this code, when cleaned up, might actually be useful. That is, if anybody but the author could figure out how to use it.
Several users complained about lack of explanations. So I added presentation that explains how to use provided set of functions.
Inspired: Sound Power Directivity Analysis