function [w,b] = solve_log(x,t,lambda);

% SOLVE_LOG  Logistic regression solver.
%
% Input:
%
% x:      ninp x ndat input matrix
% t:      1 x ndat output vector
% lambda: regularization parameter [0]
%
% Output:
%
% w: 1 x ninp weight vector
% t: threshold
%
% Notes:
%
% (1) If nargout = 1, threshold is set to zero.
% (2) Uses Matlab's fminunc instead of IRLS.

if nargin < 3,
  lambda = 0;
end

[ninp,npat] = size(x);
[nout,npat] = size(t);

w = zeros(nout,ninp);
b = zeros(nout,1);
if nargout < 2,
  ntot = ninp;
else
  ntot = ninp+1;
end
options = optimset('GradObj','on','Display','off');
for i=1:nout,
  q0 = randn(1,ntot)/100;
  q = fminunc('error_log',q0,options,x,t,lambda);
  w(i,:) = q(1:ninp);
  if nargout == 2,
    b(i) = q(ninp+1);
  end
end
