function alpha = simple_perceptron(X,Y,maxloop,ker); %X is an array of ROW vectors %TRAINx = X(trinds,:); %TRAINy = Y(trinds,:); %TESTx = X(teinds,:); %TESTy = Y(teinds,:); nx = length(Y); %maxloop = 20; % in case data not lin. sep. done = 0; cnt = 1; alpha = zeros(nx,1); ERRS = []; while ~done done = 1; for i=1:nx x_i = X(i,:); y_hat = compute_yhat(X,x_i,alpha,ker); if (y_hat ~= Y(i)) done = 0; alpha(i) = alpha(i) + Y(i); end end cnt = cnt+1; done = done + (cnt > maxloop); % show performance Yh = compute_yhat(X,X,alpha,ker); e = mean(Y~=Yh); ERRS(end+1)=e; plot(ERRS); drawnow; end return