%  fap2Di.m               
%           13 March 2005
%
% Example of approximation of two 2-dimensional functions
% using backpropagation in a batch mode. Initialization
%
% ---------------,
% Andrew P. Paplinski, 
% http://www.csse.monash.edu.au/~app/

clear

p = 3 ; % Number of inputs (2) plus the bias input
L = 12; % Number of hidden signals (with bias)
m = 2 ; % Number of outputs

na = 16 ;  N = na^2; nn = 0:na-1;  % Number of training cases

% Generation of the training cases as coordinates of points
% from two 2-D surfaces

% Specification of the sampling grid

X1 = nn*4/na - 2; % na  points from  -2 step (4/na)=.25
                  %            to (2 - 4/na)=1.75
[X1 X2] = meshgrid(X1);  % coordinates of the grid vertices
                         % X1 and X2  are  na by na

R  = (X1.^2 + X2.^2 +1e-5);  % R is a  na by na  matrix of
   % squares of distances of the grid vertices from the origin

D1 = X1 .* exp(-R);  D = (D1(:))';
                  % D1 is na by na, D  is   1 by N

D2 = 0.25*sin(2*R)./R ;  D = [D ; (D2(:))'];
           % D2 is na by na
           % D  is  2 by N  matrix of target output 2D vectors

Y = zeros(size(D)) ;  % memory allocation for the output matrix
X = [ X1(:)'; X2(:)'; ones(1,N) ];  % Appending the bias inputs
                                    % X  is  p by N
figure(1), clf reset, hold off
myfigA(1,11,10)

surfc([X1-2 X1+2], [X2 X2], [D1 D2]), % Two 2-D target functions
                                      % are ploted side by side
title('Two 2-D target functions'), grid on, drawnow
text(-1,2,0.25, 'y_1')
text(4,0,0.25, 'y_2')
% print -depsc2 -f1 dFap2Dd

% Initialization of the weight matrices

% Hidden layer weight matrix
 Wh = randn(L-1, p)/p;          % Wh  is L-1 by p

% Output layer weight matrix
 Wy = randn(m, L)/L ;         % Wy  is m by L

C = 1000;           % maximum number of training epochs
J = zeros(m, C);    % memory allocation for the error function
eta = [0.004 0.04]; % Training gains
