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

📄 svdd.m

📁 数据挖掘的工具箱,最新版的,希望对做这方面研究的人有用
💻 M
字号:
%SVDD Support Vector Data Description
% 
%       W = SVDD(A,FRACREJ,SIGMA)
% 
% Optimizes a support vector data description for the dataset A by 
% quadratic programming. The data description uses the Gaussian kernel
% by default. FRACREJ gives the fraction of the target set which will
% be rejected, when supplied FRACERR gives (an upper bound) for the
% fraction of data which is completely outside the description.
%
% Note: this version of the SVDD is not compatible with older dd_tools
% versions. This is to make the use of consistent_occ.m possible.
%
% Further note: this classifier is one of the few which can actually
% deal with example outlier objects!
% 
% Default:  FRACREJ=0.05; SIGMA=5  (dangerous!)
%
% See also: datasets, mapppings, dd_roc.
%
%@article{Tax1999c,
%	author = {Tax, D.M.J. and Duin, R.P.W},
%	title = {Support vector domain description},
%	journal = {Pattern Recognition Letters},
%	year = {1999},volume = {20},
%	number = {11-13},pages = {1191-1199}
%}

% Copyright: D. Tax, R.P.W. Duin, davidt@ph.tn.tudelft.nl
% Faculty of Applied Physics, Delft University of Technology
% P.O. Box 5046, 2600 GA Delft, The Netherlands
  
function W = svdd(a,fracrej,sigma)

% First set up the parameters
if nargin < 3 
	sigma = [];
end
if nargin < 2 | isempty(fracrej), fracrej = 0.05; end
if nargin < 1 | isempty(a) % empty svdd
	W = mapping(mfilename,{fracrej,sigma});
	W = setname(W,'Support vector data description');
	return
end

if isempty(sigma),
	sigma = 5;
end

if ~ismapping(fracrej) % training

	if isempty(sigma)
		error('This versions needs a sigma.');
	end
	% introduce outlier label for outlier class if it is available.
	if isocset(a)
		signlab = getoclab(a);
		if all(signlab<0), error('SVDD needs target objects!'); end
	else
		%error('SVDD needs a one-class dataset.');
      % Noo, be nice, everything is target:
      signlab = ones(size(a,1),1);
		%a = target_class(+a);
	end
	% check the rejection rates
	if (length(fracrej)<2) % if no bound on the outlier error is given, we
								 % do not care
		fracrej(2) = 1;
	end
	if (fracrej(1)>1)
		warning('Fracrej > 1? I cannot reject more than all my target data!');
	end
	% Setup the appropriate C's
	nrtar = length(find(signlab==1));
	nrout = length(find(signlab==-1));
	warning off; % we could get divide by zero, but that is ok.
	C(1) = 1/(nrtar*fracrej(1));
	C(2) = 1/(nrout*fracrej(2));
	warning on;

	% Find the alpha's
	matver = version;
%	if (exist('m_svm') == 3) & (str2num(matver(1:3))>=6.0)
%		%disp('Using m_svm'); % My own version
%		[SVx,alf,R2] = m_svm(+a,signlab,2,2,sigma,fracrej(1),1e-4,fracrej(2));
%		R2 = -R2;
%	else
		% Standard optimization procedure:
		[alf,R2,Dx,J] = svdd_optrbf(sigma,+a,signlab,C);
		SVx = +a(J,:);
		alf = alf(J);
        %	end
	% Compute the offset (not important, but now gives the possibility to
	% interpret the output as the distance to the center of the sphere)
	offs = 1 + sum(sum((alf*alf').*exp(-sqeucldistm(SVx,SVx)/(sigma*sigma)),2));

	% store the results
	W.s = sigma;
	W.a = alf;
	W.threshold = offs+R2;
	W.sv = SVx;
	W.offs = offs;
	W = mapping(mfilename,'trained',W,str2mat('target','outlier'),size(a,2),2);
	W = setname(W,'Support vector data description');
else                               %testing

	W = getdata(fracrej);
	m = size(a,1);

	% check if alpha's are OK
	if isempty(W.a)
		warning('The SVDD is empty or not well defined');
		out = zeros(m,1);
	end

	% and here we go:
	K = exp(-sqeucldistm(+a,W.sv)/(W.s*W.s));
	out = W.offs - 2*sum( repmat(W.a',m,1).* K, 2);
	out = [out repmat(W.threshold,m,1)];

	% use just distances, but make sure that the correct class has the
	% highest output:
	newout = -out;

	W = setdat(a,newout,fracrej);
end
return


⌨️ 快捷键说明

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