?? make_outliers.m
字號:
function [b,blck] = make_outliers(a,n,scale)
% MAKE_OUTLIERS
%
% [b,blck] = make_outliers(a,n,scale)
%
% Add an uniform outlier distribution to the given OC dataset a and
% create a new dataset b. Dataset should contain a target class (with
% the label 'target '. All other data will be deleted. The
% n new outliers will be drawn from a block defined around dataset a.
% The size of the box can be adjusted by scale (default 2, which means
% the edge of the box is twice the maximum distance in the respective
% feature direction).
%
% When n=0 is given, no outliers are created, but the dataset with
% only the first class is created and the box is computed.
%
% [b,blck] = make_outliers(a,n,blck)
%
% The user now defines the block where the data should be created. The
% format of the block is blck=[minx max; miny maxy ]
%
% [b,blck] = make_outliers(a)
% Now the same number of target objects and outlier objects are
% created.
%
% In the case of 2D data is also possible to use a grid of objects. In
% that case n should be <0.
%
% Dxd, 20-04-2000
% 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
if (nargin<3)
scale = 2.0;
end
if (nargin<2) % if no required number is given, copy from a:
n = size(a,1);
end
% well, find the target class:
a = target_class(a);
lablist = str2mat('target','outlier');
[m,k] = size(a);
% create the outlier box:
if (max(size(scale))>1) % the block is known
blck = scale;
else
blck = [min(a)' max(a)']; % the block has to be defined
df = diff(blck,1,2);
meanval = mean(blck,2);
newscale = scale/2;
blck = [meanval-newscale*df, meanval+newscale*df];
end
% combine it to a dataset:
if (n>0) % we randomly draw uniform data:
b = [+a; (ones(n,1)*blck(:,1)') + ...
(ones(n,1)*diff(blck,1,2)').*rand(n,k)];
else
if k==2
grid = gendatgrid([],[30 30],blck(:,1),blck(:,2));
b = [+a; grid];
n = size(grid,1);
else
warning('Data should be 2D');
end
end
labb = [ones(m,1)*lablist(1,:); ones(n,1)*lablist(2,:)];
b = dataset(b,char(labb),getfeat(a),[],lablist);
return
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -