finding Bias in dual form SVM using mean of support vector

조회 수: 5 (최근 30일)
Kien Tang
Kien Tang 2020년 9월 3일
답변: Shubham Rawat 2020년 9월 14일
Hi , here i am trying to implement Soft margin SVM using CVX
After getting the set of alpha using CVX i try to set the constrain of alpha to a set of support vector as S , then calculate the weight (w)
Now my problem is i want to calculate the bias b by using the mean of support vector but dont actually know how to implement that formula into matlab code
function dual = svm_train_dual(X_train, y_train, C)
%r = 800 , l = 200
[r,l] = size(X_train);
H = zeros(r,r);
q = ones(r,1);
for a = 1:r
for b = 1:r
H(a,b) = X_train(a,:)*X_train(b,:)';
end
end
cvx_begin
variable alp(r);
% minimize((1/2)*alp'*H*alp - q'*alp);
minimize(0.5*quad_form(y_train'.*alp,H) - q'*alp);
subject to
alp >= 0;
alp <= C/r;
y_train * alp == 0;
cvx_end
w = zeros(1,l);
b = 0;
%constraint alp to 1*10^-2 < alp < (C/r) - 1*10^-5 as a support vector
%S is set of support vector
S = alp(alp > 1*10^-5 | alp< (C/r) - 1*10^-5);
w = (S'.*y_train)*(X_train);
% S = alp(alp > 1*10^-5 | alp < (C/r) - 1*10^-5)
b = ?????????????;
dual.w = w;
dual.b = b;
dual.alp = alp;
dual.S = S;
end

답변 (1개)

Shubham Rawat
Shubham Rawat 2020년 9월 14일
Hi Kien,
Here Bias will be :
b = mean(y_train - w'*X_train);
% here you have already calculated weight vector

카테고리

Help CenterFile Exchange에서 Automotive에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by