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.
% 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
View the winning live scripts from faculty and students who participated in the recent challenge.Learn more
Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.