Do the following, integrate the results in a Word document. The document should be well formatted mixing the graphs and explanations as requested in the assignment, with ABSOLUTELY NO handwritten or hand drawn items.
Matlab Issues
You can use the pinv function to calculate the pseudo inverse.
To select N centers from Q input vectors you can use the randperm function. The command randperm(n) returns a random permutation of the integers between 1 and n.
You can use the C language \ character or the MATLAB sequence ... to continue a line. If a directive is too long to fit conveniently on one line, this allows you to split up the directive on to multiple lines. Example:
C(:,k) = C(:,k) + muc*en*W(k)/sigma(k)^2*exp(-norm(X(:,i)-C(:,k))^2/sigma(k)^2)...
* (X(:,i)-C(:,k));
Matlab Assignment
1) Do problem 3.12 from the textbook. Run the output of your neural network through the sign function to get the desired bipolar outputs. Plot the output of the sign function as a 3-D plot to show the performance of your network. All four networks should perform the approximation very well.
To solve this problem implement the functions described below. The function rbfval is already implemented for you. When using the rbfols function note that you have to pick the number of centers Nc to be retained. Use Nc = 50.
function Y = rbfval(W,C,sigma,X);
%
% RBFVAL - calculates the output of the RBF function
%
% Y = rbfval(W,C,sigma,X);
%
% W - weights of the RBF network
% C - centers of the RBF network
% sigma - spread parameters
% X - input vectors
%
% Y - output vectors
% determine the dimension and number of the input vectors
% and the number of the network centers
[N,Nc] = size(C);
[N,Q] = size(X);
if length(sigma) == 1
s = sigma*ones(1,Nc);
else
s = sigma;
end
% form the mapping matrix
Fi = zeros(Q,Nc);
for i = 1:Q
for j = 1:Nc
Fi(i,j) = exp(-norm(C(:,j)-X(:,i))^2/s(j)^2);
end
end
% calculate the outputs
Y = Fi*W;
function [W,C,sigma] = rbfexact(X,Y);
%
% RBFEXACT - Determines the weights for the RBF NN
%
% [W,C,sigma] = rbfexact(X,Y)
%
% X - N by Q matrix of the input patterns
% Y - 1 by Q matrix of the output values
%
% The RBF function is chosen as Gaussian and the spread parameter is set as
% sigma = dmax/sqrt(Q), where dmax is the max. distance between centers and
% K is the number of centers. Since this is exact RBF NN all input patterns
% are used as centers.
%
% W - weights for the RBF centers
% C - centers of the RBF network
% sigma - spread parameter
function [W,C,sigma] = rbfrand(X,Y,Nc);
%
% RBFRAND - Determines the weights for the RNF NN with random centers
%
% [W,C,sigma] = rbfrand(X,Y,Nc)
%
% X - N by Q matrix of the input patterns
% Y - 1 by Q matrix of the output values
% Nc - Number of random centers to be selected from the data
%
% The RBF function is chosen as Gaussian and the spread parameter is set as
% sigma = dmax/sqrt(Q), where dmax is the maximum distance between centers
% and K is the number of centers. Since this is exact RBF NN all input
% patterns are used as centers.
%
% W - weights for the RBF network
% C - centers of the RBF network
% sigma - spread parameter
function [W,C,sigma,E] = rbfsgrad(X,Y,Nc,Tp);
%
% RBFSGRAD - Determines the weights for the RBF NN using the grdient learning
%
% [W,C,sigma,E] = rbfsgrad(X,Y,Nc,Tp)
%
% X - N by Q matrix of the input patterns
% Y - 1 by Q matrix of the output values
% Nc - number of random centers to be selected from the data
% Tp - training parameter vector
% Tp(1) - learning rate for the weights
% Tp(2) - learning rate for the centers
% Tp(3) - learning rate for the spread parameter
% Tp(4) - maximum number of iterations
% Tp(5) - required accuracy
%
% W - weights for the RBF network
% C - centers of the RBF network
% sigma - spread parameters
% E - error trajectory
function [W,C,sigma,Ind,M] = rbfols(X,Y,Nc);
%
% RBFOLS - Determines the weights for the RBF NN using OLS regression
%
% [W,C,sigma,Ind,M] = rbfols(X,Y,Nc)
%
% X - N by Q matrix of the input patterns
% Y - 1 by Q matrix of the output values
% Nc - number of centers to be retained
%
% W - weights of the RBF network
% C - centers of the RBF network
% sigma - spread parameter
% Ind - index values of the retained centers
% M - error reduction ratio