How can I change the 'radbas' transferFcn ?
7 views (last 30 days)
Show older comments
Nikos Vasileiadis
on 22 Dec 2016
Commented: Nikos Vasileiadis
on 23 Dec 2016
I want to do a 2D interpolation with a feedforward neural net in Matlab and I choose to use a radial bade transfer function on the neurons of the hidden layer. The problem is that the radbas function gives a hyperplane like figure 1 and I want a hyperplane more like figure 2. out=exp(-(x-x0)^2/2 + (y-y0)^2/2);
What should I do?


In other words I want each neuron creates and shift a bell shaped (hyper)plane along my 2D input space.
1 Comment
Accepted Answer
John BG
on 23 Dec 2016
Edited: John BG
on 23 Dec 2016
ok
the reason why radbas.m is called radial function is not because when plotting the outcome on a plane it should look like a 'hat', but because the function output is input phase independent:

.
you are right that inside radbas.m there is no mesh capability by this meaning that it's a 1D function and we have to either modify readbas.m, build another function, or further process before and after using radbas.m
Inside radbas.m
function a = radbas(n,b)
%RADBAS Radial basis transfer function.
%
% RADBAS(N)
% N - SxQ matrix of distance vectors.
% Returns values of N passed through radial basis function.
%
% EXAMPLE: n = -4:0.1:4;
% a = radbas(n);
% plot(n,a)
%
% RADBAS(Z,B) ...used when batching.
% Z - SxQ matrix of unbiased distance vectors.
% B - Sx1 bias vector.
% Obtains N by multiplying elements in each column of Z by
% the elements in B, then returns RADBAS(N).
% Mark Beale, 12-15-93
% Copyright (c) 1992-94 by The MathWorks, Inc.
% $Revision: 1.1 $ $Date: 1994/01/11 16:28:18 $
if nargin < 1, error('Not enough arguments.'); end
if nargin==2
[nr,nc] = size(n);
n = n .* (b*ones(1,nc));
end
a = exp(-(n.*n));
although Srouceforge has a download for radbas.m that is slightly different:
function retval = radbas (n)
if (nargin != 1)
print_usage ();
else
retval = exp (-n^2);
endif
endfunction
I suggest you start with something like the following:
b=0 % keep it 0 for now
dn=0.1 % step
nr=5 % range limit
range= -nr:dn:nr;
x0=1;y0=1 % center
xc=1;yc=1;
nx=range+xc;ny=range+yc
[X,Y]=meshgrid(nx,ny) % required to hve surf generating 3D points
Z=exp(-(X.^2+Y.^2))
surf(X,Y,Z)

and to colour according to 'altitude' proportional to heat, the higher the hotter, I am afraid you may have to define your own colormap. Some time ago I looked for the common heat color maps that have white yellow red blue black going from hottest to coldest, but MATLAB only has the following standard colormaps

the closest to white hottest black coldest seems to be 'jet'
colormap(jet)
colorbar

you can also delete the fine 'net' so it looks closer to the image you are after.
at this point, would you please accept my answer?
Thanks for time and attention, awaiting answer
John BG
More Answers (1)
John BG
on 22 Dec 2016
you probably missed using the coordinates out of meshgrid rather than the ranges x and y.
Try adding
[X,Y]=meshgrid(-3:.01:3)
then have your function working on X and Y rather than x and y:
Z=exp(-(X-x0)^2/2 + (Y-y0)^2/2);
and check
C=gradient(Z)
figure;
mesh(X,Y,Z,C)
if you find my answer useful would you please mark it as Accepted Answer by clicking on the ACCEPT ANSWER button?
thanks in advance for time and attention
John BG
See Also
Categories
Find more on Define Shallow Neural Network Architectures in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!