svmnlspex01fun.m
来自「数据挖掘的新方法-支持向量机书中算法例子」· M 代码 · 共 44 行
M
44 行
%SVMnLSPex01FUN.m
%
%Object function and Constrained function for Two Dimension SVM Problem, Two Class and Separable Situation;
%
%Method from Christopher J. C. Burges:
%Object function and Constrained function for Two Dimension SVM Problem, Two Class and Separable Situation;
%
%Method from Thorsten Joachims:
%"Making Large-Scale SVM Learning Practical", function (4)/(5)/(6)
%
% Objective: min "f(A)=-sum(A)+A'*Q*A/2" , function (4);
% Subject to: sum{A'*Y}=0 , function (5);
% 0 <= ai <= C , function (6);
%The optimizing variables is "Lagrange Multipliers": A=[a1,a2,...,am],m is the number of total samples.
%
function [F,G]= SVMnLSPex01FUN(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.
Q = diag(Y)*K(X,X')*diag(Y); %Component of matrix Q is Q(ij)=yi*yj*Xi*Xj';
F = -sum(A)+ 0.5*(A'*Q*A); %Object Function after Mapping;
G = sum(A'*Y); %Constraint Functions after Mapping;
function Kernel = K(U,E) %Kernel function
Kernel = (U*E+1).^4;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?