function net=newnet(neurons, name)
%NEWNET	Create a feed-forward neural network.
%
%	net = NEWNET (neurons, name);
%
%	Example: net = NEWNET ([2, 4, 1], 'demo net');
%
%	Input: 
%	  neurons: number of neurons in each layer.
%		[input, 1st hidden layer, 2nd, ..., output]
%	Output: a net (structure)
%
%	See also: INITNET, FORWARD, BACKWARD.

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

% Check inputs
if nargin < 1
	error('Insufficient inputs. Type ''help newnet'' to get more info.');
elseif size(neurons, 1) > 1
	neurons = neurons';
end

layers = size(neurons, 2);

if nargin < 2
	name = ['neural network with ' int2str(layers), ' layers'];
end

% Allocate memory for weights
% weight{l}(i+1, j): weight of layer l (l=1: 1st hidden layer, ...)
%	from neuron i (layer l-1) to neuron j (layer l)
%	neuron 0 of any layer is the constant -1
%	That is: w_{ij}^l ==> weight{l}(i+1, j)

w = cell(1, layers-1);
for l = 1:layers-1,
	w{l} = zeros(neurons(l)+1, neurons(l+1));
end

net = struct('name', name, 'layers', layers, 'neurons', neurons, 'weight', []);
net.weight = w;

