📄 linsvm.m
字号:
function [alpha,theta,solution]=linsvm(X,J)% LINSVM Support Vector Machines for the linear and separable case.% [alpha,theta,solution]=linsvm(X,J)%% LINSVM is an implementation of the Support Vector Machines % method for the linear and separable case. It finds a vector % alpha and a threshold which solve following task % % 1) alpha' * x >= theta for x=X(:,i), J(i)=1, (1st class)% alpha' * x < theta for x=X(:,i), J(i)=2, (2nd class)%% 2) and a margin between point sets (their convex hulls) % is maximal.%% The algorithm transforms the problem mentioned above to the% equivalent problem of quadratic programing and uses Matlab% Optimization Toolbox for resolving.%% Input:% X [DxM] contains M training points in the D-dimensional % feature space. X=[x1,x2,..XM] where xi is i-th column vectors.% J [1xM] contains class labels of the points in X. A class% label must be 1 for the first class and 2 for the second class.%% Output:% alpha [Dx1] normal vector of the found decision hyperplane.% theta [1x1] threshold of the found hyperplane.% solution [1x1], 1 ... solution is found,% 0 ... solution is not found.%% See also PERCEPTR, KOZINEC, EKOZINEC.%% Statistical Pattern Recognition Toolbox, Vojtech Franc, Vaclav Hlavac% (c) Czech Technical University Prague, http://cmp.felk.cvut.cz% Written Vojtech Franc (diploma thesis) 02.11.1999, 17.01.2000, 13.4.2000% Modifications% 24. 6.00 V. Hlavac, comments polished.% 16-dec-2000, comments repaired% Transform original feature space into the homogenous (theta=0)% coordinates.[alpha,X]=ctransf(0,0,X,J);N=size(X,1); % dimensionK=size(X,2); % number of training points.% Transform the problem to the quadratic programming problem% min x'*H*x+f'*x , A*x <= b% x%-------------------------------------------H=eye(N);f=zeros(N,1);b=-ones(K,1);A=-X';% Call quadratic programming method%-----------------------------------------------[alpha,lag,how]=qp(H,f,A,b,[],[],[],0,-1);% Transform the found solution from the homogenous coordinates% into original space.[alpha,theta]=ictransf(alpha);% Set solution according to the qp result%----------------------------------------if strcmpi(how,'ok')==1, solution=1;else solution=0;end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -