
function [cv] = crossvalid(X,y,c); 

n = size(X,1);

cv = 0;
for i=1:n, 
  I = find((1:n) ~= i); 
  w = logisticreg(X(I,:),y(I),c);
  p = g(w(1) + X(i,:)*w(2:length(w)));
  cv = cv + ( y(i)*log(p) + (1-y(i))*log(1-p) )/n;
end;

    
    
% ----------------------------------------
% logistic function

function [p] = g(z)

p = 1 ./(1+exp(-z));

