📄 svmlspex01fun.m
字号:
%Object function and constrained function for SVMLSPex01.m:
%
% Objective: min "f(A)=||W||" , p8/line26
% Subject to: yi*(xi*W+b)-1>=0, function (12);
%
%a.dat file contained two classes samples and both are equal in number.
%Positive samples corresponding to Yi = 1, are arranged first in the a.dat with nigative ones followed
function [F,G]= SVMLSPex01FUN(Q);
[m,n]=size(Q);
if n>m,
Q=Q';
end
W=Q(1:2);
b=Q(3);
clear Q;
%Read the samples
fid=fopen('a.dat','r');
m1=fread(fid,1,'float'); %Number of class A
m2=fread(fid,1,'float'); %Number of class B
n=fread(fid,1,'float'); %Dimension of problem
m=m1+m2; %Total number of the samples
for k=1:n
X(1:m,k)=fread(fid,m,'float');
end
fclose(fid);
%Samples with m*n matrix and each row represent a sample vector.
F=W'*W;
Y=[ones(m1,1);-ones(m2,1)]; %Classifing value for two classes
G=1-diag(Y)*(X*W+b); %Constraint is function (12), keep to MATLAB should be C(x)<=0
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -