www.pudn.com > kernelSVM.rar > determine_alpha2.m
function [ alpha2,alpha2_index,alpha2_new ] = determine_alpha2( mat_kernel,E,alpha,Y,littleValue,C,alpha1,alpha1_index)
%UNTITLED1 Summary of this function goes here
% Detailed explanation goes here
%determine alpha2 by minimizing E1-E2
E1 = E(alpha1_index);
E1_E2 = max(abs(E-E1));
alpha2_index_s = find(abs(E-E1)==E1_E2);
alpha2_s = alpha(alpha2_index_s);
for i=1:length(alpha2_s)
alpha2_index =alpha2_index_s(i);
alpha2 = alpha2_s(i);
if(Y(alpha1_index,1) ~= Y(alpha2_index,1))
U = max(0,alpha2-alpha1);
V = min(C,C-alpha1+alpha2);
else
U = max(0,alpha1+alpha2-C);
V = min(C,alpha1+alpha2);
end
k = mat_kernel(alpha1_index,alpha1_index)+mat_kernel(alpha2_index,alpha2_index)-2*mat_kernel(alpha1_index,alpha2_index);
if abs(k) V
alpha2_new = V;
elseif alpha2_new < U
alpha2_new = U;
end
if abs(alpha2_new-alpha2) < littleValue
continue
else
break
end
end
%determine alpha2 from support vector
if abs(alpha2_new-alpha2) < littleValue
sup_index = find(alpha>littleValue & alpha V
alpha2_new = V;
elseif alpha2_new < U
alpha2_new = U;
end
if abs(alpha2_new-alpha2) < littleValue
continue
else
break
end
end
end
end
%determine alpha2 from all training samples
if abs(alpha2_new-alpha2) < littleValue
clear i;
for i = 1:length(alpha)
alpha2_index = i;
alpha2 = alpha(alpha2_index);
if(Y(alpha1_index,1) ~= Y(alpha2_index,1))
U = max(0,alpha2-alpha1);
V = min(C,C-alpha1+alpha2);
else
U = max(0,alpha1+alpha2-C);
V = min(C,alpha1+alpha2);
end
k = mat_kernel(alpha1_index,alpha1_index)+mat_kernel(alpha2_index,alpha2_index)-2*mat_kernel(alpha1_index,alpha2_index);
if abs(k) V
alpha2_new = V;
elseif alpha2_new < U
alpha2_new = U;
end
if abs(alpha2_new-alpha2) < littleValue
continue
else
break
end
end
end