function [l X Y w b J0 rho] = svmQP(yx,toler) ########################################################### # # USAGE: # [l x y w b J0 rho] = svmQP(yx,toler) # # INPUT: # yx = matrix with N examples. Each line: y x # toler = tolerance for QPsolver. e.g. 1.0e-5 ########################################################### # OUTPUT: # # l The vector of lambdas # x matrix [x1,x2,...,xn]' # y vector of labels # w normal vector of optimal hyperplane # b location scalar optimal hypp +b = 0 # J0 list of indices of support vectors # rho margin 1/|w| # ########################################################### [d,dimyx] = size(yx); [Q,A,b,c] = setQP(yx,d); YesQPsolver; ## sets x,y,obhis l = x; b = y; l(find(x <= 10*toler)) = 0; J0 = find(l > 10*toler); X = yx(:,2:dimyx); Y = yx(:,1); w = (l.*Y)'*X; rho = 1/norm(w); endfunction function [Q,A,b,c] = setQP(yx,d) [n,cc] = size(yx); d = d+1; Q = zeros(n,n); A = yx(:,1)'; b = 0; c = (-1)*ones(n,1); for i = 1:n Q(i,i) = A(i)*A(i)*dot(yx(i,2:d),yx(i,2:d)); for j = i:n Q(i,j) = A(i)*A(j)*dot(yx(i,2:d),yx(j,2:d)); Q(j,i) = Q(i,j); endfor endfor endfunction