⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 svmclassl2.m

📁 我用于脑机接口P300拼写范例中的程序
💻 M
字号:
function [xsup,w,d,pos,timeps,alpha,obj]=svmclass(x,y,c,lambda,kernel,kerneloption,verbose,span,alphainit)% USAGE [xsup,w,b,pos,timeps,alpha]=svmclass(x,y,c,lambda,kernel,kerneloption,verbose,span)%% Support vector machine for CLASSIFICATION% with quadratic penalty% This routine classify the training set with a support vector machine% using quadratic programming algorithm (active constraints method)%% INPUT%% Training set%      x  		: input data %      y  		: output data% parameters%		c		: Bound on the lagrangian multipliers     %		lambda		: Conditioning parameter for QP method%		kernel		: kernel  type. classical kernel are%%		Name			parameters%		'poly'		polynomial degree%		'gaussian'	gaussian standard deviation
%
%		for more details see svmkernel% %		kerneloption : parameters of kernel
%
%		for more details see svmkernel%% 		verbose : display outputs (default value is 0: no display)%%     Span    : span matrix for semiparametric learning %               This vector is sized Nbapp*Nbbasisfunction where%               phi(i,j)= f_j(x(i));
%
%%% OUTPUT%% xsup	coordinates of the Support Vector% w      weight% b		bias% pos    position of Support Vector% timeps time for processing the scalar product% alpha  Lagragian multiplier% obj    Value of Objective function%%% see also svmreg, svmkernel, svmval	%	21/09/97 S. Canu%	04/06/00 A. Rakotomamonjy   -inclusion of other kernel functions%	04/05/01 S. Canu            -inclusion of multi-constraint optimization for frame-SVM%%       scanu@insa-rouen.fr, alain.rakoto@insa-rouen.frif nargin< 9    alphainit=[];end;if nargin < 8	A = y;        b = 0;else        if span==1        span=ones(size(y));    end;	[na,m]=size(span);        [n un] = size(y);        if n ~= na	        error('span, x and y  must have the same number of row')        end        A = (y*ones(1,m)).*span;        b = zeros(m,1);endif nargin < 7	verbose = 0;endif nargin < 6	gamma = 1;endif nargin < 5	kernel = 'gaussian';endif nargin < 4	lambda = 0.000000001;endif nargin < 3	c = inf;end[nl nc] = size(x);[n un] = size(y);if n ~= nl	error('x and y must have the same number of row')endif min(y) ~= -1	error(' y must coded: 1 for class one and -1 for class two')endif verbose ~= 0 disp('building the distance matrix'); end;ttt = cputime;ps  =  zeros(n,n);		
ps=svmkernel(x,kernel,kerneloption);if size(c,1)==n    ps=ps+diag(1./c);else    ps=ps+1/c*eye(n);
end;
%----------------------------------------------------------------------%      monqp(H,b,c) solves the quadratic programming problem:% %    min 0.5*x'Hx - d'x   subject to:  A'x = b  and  0 <= x <= c %     x    %----------------------------------------------------------------------H =ps.*(y*y'); e = ones(size(y));timeps = cputime - ttt;                                                          [alpha , lambda , pos] =  monqpCinfty(H,e,A,b,lambda,verbose,x,ps,alphainit);  if verbose ~= 0 disp('out QP'); end;alphaall=zeros(size(e));alphaall(pos)=alpha;obj=-0.5*alphaall'*H*alphaall +e'*alphaall;xsup = x(pos,:);ysup = y(pos);w = (alpha.*ysup);d = lambda;if verbose ~= 0  	disp('max(alpha)') 	fprintf(1,'%6.2f\n',max(alpha)) end 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -