function [Y]=MLPval(x,W1,W2,F1,F2)
%MLPval compute output values from a trained MLP
%
%      [Y]=MLPval(X,W1,W2,F1,F2)
%
% X  is the input data
% W1 the weight matrix input -> hidden layer
% W2 weight matrix hidden layer -> ouput
% F1 (default 'tah') activation function of the hidden layer units
% F2 (default 'lin') activation function of the output layer units
%
% Y the output ouf the network at point X
%	
%	21/04/97 S. Canu
if nargin < 3;
   help MLPval
   error(sprintf('\n *** MLPval error: invalid call***\n\n\t[Y]=MLPval(X,W1,W2,F1,F2);\n\n'));
end;
% Check that matrix (X) and matrix (W1) have compatible dimensions
[n,d] = size(x);
[dp1,m] = size(W1);
[mp1,q] = size(W2);
if (d+1)~=dp1,
    error('The number of colum in x plus one must equal the number of rows in W1');
end
if (m+1)~=mp1,
    error('The number of colum in W1 plus one must equal the number of rows in W2');
end
% Complete unspecified name of activation function
if nargin < 5;
   F2='lin';
   if nargin < 4;
      F1 ='tah';
   end;
end;
if F1=='tah' & F2=='lin'
  a1 = [x ones(n,1)]*W1;
  x1 = tanh(a1);
  a2 = [x1 ones(n,1)]*W2;
  Y =  a2;
elseif F1=='sig' & F2=='lin'
  a1 = [x ones(n,1)]*W1;
  x1 = tanh(a1);
  a2 = [x1 ones(n,1)]*W2;
  Y =  a2;
elseif F1=='tah' & F2=='tah'
  a1 = [x ones(n,1)]*W1;
  x1 = phi(a1);
  a2 = [x1 ones(n,1)]*W2;
  Y =  tanh(a2);
elseif F1=='sig' & F2=='tah'
  a1 = [x ones(n,1)]*W1;
  x1 = phi(a1);
  a2 = [x1 ones(n,1)]*W2;
  Y =  tanh(a2);
elseif F1=='tah' & F2=='sig'
  a1 = [x ones(n,1)]*W1;
  x1 = tanh(a1);
  a2 = [x1 ones(n,1)]*W2;
  Y =  phi(a2);
elseif F1=='sig' & F2=='sig'
  a1 = [x ones(n,1)]*W1;
  x1 = phi(a1);
  a2 = [x1 ones(n,1)]*W2;
  Y =  phi(a2);
  
  
elseif F1=='tah' & F2=='exp'
  a1 = [x ones(n,1)]*W1;
  x1 = tanh(a1);
  a2 = [x1 ones(n,1)]*W2;
  Y =  exp(a2);
elseif F1=='sig' & F2=='exp'
  a1 = [x ones(n,1)]*W1;
  x1 = phi(a1);
  a2 = [x1 ones(n,1)]*W2;
  Y =  exp(a2);
else
 error('The name of the activation function is incorect')
end
