基于matlab的svdd多分类程序,SVDD算法程序解释的问题?

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);                                             %从数据a中得到数字标签

if all(signlab<0), error('SVDD needs target objects!'); end        %如果所有的标签小于零,那么svdd出错!!需要目标样本

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

if length(fracrej)~=length(signlab)

error('The length of C is not fitting.');

end

C = fracrej;

else

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('dd_tools:AllReject',...

'Fracrej > 1? I cannot reject more than all my target data!');

end

fracrej

% Setup the appropriate C's                                        %设置c值

if (fracrej(1)<0) %DXD: tricky trick....

C(1) = -fracrej(1);

C(2) = -fracrej(2);

else

nrtar = length(find(signlab==1));

nrout = length(find(signlab==-1));

% we could get divide by zero, but that is ok.

%warning off MATLAB:divideByZero;

C(1) = 1/(nrtar*fracrej(1));

C(2) = 1/(nrout*fracrej(2));%nrout 异常样本数

%warning on MATLAB:divideByZero;

end

end

% Find the alpha's

% Standard optimization procedure:

[alf,R2,Dx,J] = svdd_optrbf(sigma,+a,signlab,C);                       %二次优化      J为支持向量和错误的点

SVx = +a(J,:);

alf = alf(J);

%         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))   %sqeucldistm专门计算欧式距离

% store the results                                                    %保存结果

W.c =C;

W.s = sigma;

W.a = alf;

W.R2= R2;

W.threshold = offs+R2;

W.sv = SVx;

W.offs = offs;

W = mapping(mfilename,'trained',W,char('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('dd_tools:OptimFailed','The SVDD is empty or not well defined');

out = zeros(m,1);

else

% 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);

end

newout = [out repmat(W.threshold,m,1)];

% Store the distance as output:

W = setdat(a,-newout,fracrej);                                       %重置数据和功能标签的数据集分类输出

W = setfeatdom(W,{[-inf 0; -inf 0] [-inf 0; -inf 0]});

end

return

搞不清楚training和testing是做什么的?newout求出的是什么?

你可能感兴趣的:(基于matlab的svdd多分类程序,SVDD算法程序解释的问题?)