function [alphas, b] = kernel_perceptron(X,Y,d); N = size(X,1); err = 1; %error rate max_iter = 10000; %maximum number of iterations alphas = zeros(N,1); b = 0; t = 1; while t<=max_iter && err>0 for ii = 1 : N %cycle through training set %TO DO: update alpha and b xt = X(ii, :); yt = Y(ii, :); sum = 0; for i = 1 : N ai = alphas(i); yi = Y(i); xi = X(i, :); sum = sum + ai * yi * dot(xi, xt) ^ d; end sum = sum + b; if sum * yt <= 0 alphas(ii) = alphas(ii) + 1; b = b + yt; end %******************************* end t = t+1; %TO DO: calculate the error rate %******************************* end