📄 svmlspex02fun.m
字号:
%SVMnLSPex02FUN.m
%Object function and Constrained function for Two Dimension SVM Problem, Two Class and Separable Situation;
%
%Method from Christopher J. C. Burges:
%"A Tutorial on Support Vector Machines for Pattern Recognition", page 9
%
% Objective: min "f(A)=-sum(ai)+sum[sum(ai*yi*xi*aj*yj*xj)]/2" ,function (16)
% Subject to: sum{ai*yi}=0 ,function (15);
% and ai>=0 for any i, the particular set of constraints C2 (page 9, line14).
%
%The a.dat file contained both +/- classes samples and, "m1" and "m2" are thire number respectively.
%Vector A = [a1,a2,...]
function [F,G]= SVMLSPex02FUN(A)
%Samples matrix X with (m*n), m samples with dimention n;
fid=fopen('a.dat','r'); %Get the samples
m1=fread(fid,1,'float'); %The number of Position Set
m2=fread(fid,1,'float'); %The number of Negative Set
n=fread(fid,1,'float'); %Dimension of the samples
m=m1+m2; %
for k=1:n
X(1:m,k)=fread(fid,m,'float');
end
fclose(fid);
Y=[ones(m1,1);-ones(m2,1)]; %Classfication value for both Positive/Negative samples
%Object Function value F and Constrained function value G, G(i) is the value of i'th constrained function.
ay=diag(A)*diag(Y);
F=-sum(A)+sum(sum(0.5*((X*X')*ay)'*ay)); %function (16)
G(1)=sum(sum(ay)); %Equality constrain function (15)
G(2:m+1)=-A; %condition ai>=0, for any i;
G=G';
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -