?? lpdd.m
字號:
function W = lpdd(x,nu,dtype,par1,par2)% W = lpdd(x,nu,dtype,p1,p2)% % One-class classifier put into a linear programming framework. From% the data x the distance matrix is computed, and on this the linear% machine is trained. The parameter nu gives the possible error on the% target class.%% Several distances dtype can be used: see ddistm to see the% possibilities and the definition of the parameters par1 and par2. %% Copyright: D. Tax, E. Pekalska, davidt@ph.tn.tudelft.nl% Faculty of Applied Physics, Delft University of Technology% P.O. Box 5046, 2600 GA Delft, The Netherlands% first set up the parametersif nargin < 5 | isempty(par2), par2 = 1; endif nargin < 4 | isempty(par1), par1 = 2; endif nargin < 3 | isempty(dtype), dtype = 'lp'; endif nargin < 2 | isempty(nu), nu = 0.05; endif nargin < 1 | isempty(x) % empty W = mapping('lpdd',{nu,dtype,par1,par2}); returnend% trainingif isa(nu,'double') % do some trick to compute the distances later: W.x = x; [N,d_org] = size(x); % maybe we have example outliers... if is_ocset(x) labx = -ones(N,1); labx(find_target(x)) = 1; else labx = ones(N,1); end% x = +x; % no dataset please. x = ddistm(+x,+x,dtype,par1,par2); [N,d] = size(x); % set up the LP problem: f = [ones(N,1)/(nu*N); 1; zeros(d,1)]; A = [-eye(N) -labx repmat(labx,1,d).*x]; b = zeros(N,1); Aeq = [zeros(1,N+1) ones(1,d)]; beq = 1; lb = [zeros(N,1); -inf; zeros(d,1)]; ub = inf*ones(N+d+1,1); % optimize, use the mex-interface if available, else the Matlab % optimizer: if exist('lp_solve')>0% if ~exist('lpenv') lpenv=cplex_init; end% [alf,y_upd_,how_upd_,p_lp]=...% lp_solve(lpenv, f, sparse([Aeq;A]), [beq;b], lb, ub, 1, 0); newf = [f;-1]; newA = [A +labx]; newb = [b; 0]; newAeq = [Aeq 0]; e = [0; -ones(N,1)]; [v,alf] = lp_solve(-newf,sparse([newAeq;newA]),[beq;b],e); alf(N+1) = -(alf(N+1) + alf(end)); alf(end) = []; alf1 = linprog(f,A,b,Aeq,beq,lb,ub); else alf = linprog(f,A,b,Aeq,beq,lb,ub); end % store the results W.dtype = dtype; W.par1 = par1; W.par2 = par2; W.rho = alf(N+1); W.w = alf((N+2):end); W = mapping('lpdd',W,str2mat('target','outlier'),d_org,2);else %testing [W,classlist,type,k,c] = mapping(nu); % unpack [nlab,lablist,m,k,c,p] = dataset(x); % and here we go: D = ddistm(+x,W.x,W.dtype,W.par1,W.par2); % the official output:% out = W.rho - D*W.w;% newout = [out -out]; % but I choose for: newout = [-D*W.w -repmat(W.rho,m,1)]; W = dataset(newout,getlab(x),classlist,p,lablist);endreturn
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -