function W = nninit(Ni, Nh)
% NNINIT Neural network initialisation
%
%       W = NNINIT(NI, NH) returns an initialised parameter vector
%       corresponding to a NIxNHx1 multi-layer perceptron with input and
%       hidden biases.
%       Use with function NNREG.
%
% See also: NNREG, NNCOST, NNCOSTR.
if (nargin ~= 2)
  error('NNINIT: wrong number of arguments.')
end

[P N] = size(Ni) ;
if (N*P ~= 1)        % If input was the input data instead of the dimension.
  Ni = P ;
end

W = zeros((Ni+2)*Nh + 1, 1) ;
W1 = (rand(Nh, Ni+1) - .5) / sqrt(Ni+1) ;
W2 = (rand(1, Nh+1) - .5) / sqrt(Nh+1) ;
W(1:((Ni+1)*Nh)) = reshape(W1, (Ni+1)*Nh, 1) ;
W(((Ni+1)*Nh+1):((Ni+2)*Nh + 1)) = reshape(W2, Nh+1, 1) ;
