function [alphas offset] = my_seqminopt(data, targetLabels, boxConstraints, ...
while itCount
for i=1:m
num_alpha_change=0;
gI=(alphas.*targetLabels)‘ *(data*data(i,:)‘)+offset;
%violate the KKT condition
eI=gI-targetLabels(i);
if ((targetLabels(i)*eI<-tol)&& (alphas(i)tol) && (alphas(i)>0) )
j=randi([i,m]);%select randomly
gJ=(alphas.*targetLabels)‘ *(data*data(j,:)‘)+offset;
eJ=gJ-targetLabels(j);
%oldAlphaI,oldAlphaJ
oldAlphaI=alphas(i);
oldAlphaJ=alphas(j);
if targetLabels(i)~=targetLabels(j)
L=max(0,alphas(j)-alphas(i));
H=min(boxConstraints(i),boxConstraints(i)+alphas(j)-alphas(i));
else
L=max(0,alphas(j)+alphas(i)-boxConstraints(i));
H=min(boxConstraints(i),alphas(j)+alphas(i));
end
eta=2.0*data(i,:)*data(j,:)‘-data(i,:)*data(i,:)‘-data(j,:)*data(j,:)‘;
if eta>=0
continue;
end
alphas(j)=alphas(j)-targetLabels(j)*(eI-eJ)/eta;
if alphas(j)
alphas(j)=L;
elseif alphas(j)>H
alphas(j)=H;
end
alphaChange=alphas(j)-oldAlphaJ;
if abs(alphaChange)<1e-5
continue;
end
alphas(i)=alphas(i)+targetLabels(j)*targetLabels(i)*(oldAlphaJ-alphas(j));
b1=boxConstraints(i)-eI-targetLabels(i)*(alphas(i)-oldAlphaI)*data(i,:)*data(i,:)‘-targetLabels(j)*(alphas(j)-oldAlphaJ)*data(i,:)*data(j,:)‘;
b2=boxConstraints(i)-eJ-targetLabels(i)*(alphas(i)-oldAlphaI)*data(i,:)*data(j,:)‘-targetLabels(j)*(alphas(j)-oldAlphaJ)*data(j,:)*data(j,:)‘;
if ((alphas(i)>0) && (alphas(i)
offset=b1;
elseif ((alphas(j)>0) && (alphas(j)
offset=b2;
else
offset=(b1+b2)/2.0;
end
num_alpha_change=num_alpha_change+1;
end
end
if num_alpha_change == 0
itCount=itCount+1;
else
itCount=0;
end
end