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

📄 gradlfixed.m

📁 基于核分析的多类分类器
💻 M
字号:
function [grad] = gradlfixed(Sigma,indsup,Alpsup,C,Xapp,yapp,pow);%GRADLFIXED Computes the gradient of an upper bound on SVM loss wrt SIGMA^POW  %  GRAD = GRADLFIXED(SIGMA,INDSUP,ALPSUP,C,XAPP,YAPP,POW) %  is the gradient of the upper bound on the SVM loss obtained when the %  Lagrange multipliers are considered to be unaffected by SIGMA. %  %  SIGMA is the current SIGMA value%  INDSUP is the (nsup,1) index of current support vectors %  ALPSUP is the (nsup,1) vector of non-zero Lagrange multipliers%  C is the error penalty hyper-aparameter%  XAPP,YAPP are the learning examples%  27/01/03 Y. Grandvalet% initializationnsup  = length(indsup);[n,d] = size(Xapp);% I) compute distancesXappS = Xapp.*repmat(Sigma,n,1);XsupS = XappS(indsup,:);Dist  = XsupS*XappS';dist  = 0.5*sum(XappS.^2,2) ;Dist  = Dist - repmat(dist(indsup),1,n) - repmat(dist',nsup,1) ; % -1/2 (xi-xj)T Sigma^2 (xi-xj)Dist  = exp(Dist) ;% II) compute gradient of error part% II.1) slacksindpos = find(yapp== 1);indneg = find(yapp==-1);npos = length(indpos) ;nneg = length(indneg) ;nmin = min(npos,nneg);xipos = -sort(-(1 - Alpsup'*Dist(:,indpos))); xineg = -sort(-(1 + Alpsup'*Dist(:,indneg))); xi = sum([xineg(1:nmin) ; xipos(1:nmin)],1);% II.2) gradient of error partind = find(xi>=0) ;grad = zeros(1,d);if ~isempty(ind);   for k=1:d;      Distk   = repmat(XappS(ind,k)',nsup,1) - repmat(XsupS(:,k),1,length(ind)) ;      grad(k) =  Alpsup' * (Distk.*Dist(:,ind)) * (Xapp(ind,k).*yapp(ind)) ;   end;end;grad = C*grad ;% III) add gradient of norm partXsup  = Xapp(indsup,:);for k=1:d;   Distk = Xsup(:,k)*Xsup(:,k)';   distk = diag(Distk);   Distk = -2*Distk + repmat(distk,1,nsup) + repmat(distk',nsup,1) ; % (xik-xjk)^2   grad(k) = grad(k) + (Alpsup' * (Distk.*Dist(:,indsup)) * Alpsup) * Sigma(k) ;end;% III) modify according to powerind = find(Sigma~=0);grad(ind) = grad(ind).*(1/pow*abs(real(Sigma(ind).^(1-pow))));

⌨️ 快捷键说明

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