function [y,ix]=forward(net, x)
%FORWARD	Feed input, get output of the network.
%
%	[y,ix] = FORWARD (net, x);
%
%	Example:
%		net = initnet(newnet([2,4,1], 'demo'), [-1,1]);
%		net = trainnet(net, x, y, [0.1, 1000]);
%		y = FORWARD (net, [-0.3, 0.4; -0.4, 0.5]);
%	Inputs:
%	  x: each row of x is an input.
%	Outputs:
%	  y: each row of y is an output.
%	  ix: internal x. used by backpropagation in training.
%		each row of ix{l} is the inner status of layer l-1 
%		for one sample (not include -1)
%
%	See also: NEWNET, INITNET, BACKWARD.

%	Ling Li, Caltech
%	10/21/96, 10/08/00

% Check inputs
if size(x, 2) ~= net.neurons(1)
	error('Input matrix dimension not agree');
end

minusone = -ones(size(x, 1), 1);

ix = cell(1, net.layers);
ix{1} = x;

% forward loop
for l = 1:net.layers-2
	ix{l+1} = tanh([minusone,ix{l}] * net.weight{l});
end
l = net.layers-1;
ix{l+1} = [minusone,ix{l}] * net.weight{l};

y = ix{net.layers};
