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

📄 target_class.m

📁 模式识别工具箱,希望对大家有用!
💻 M
字号:
function [a,b] = target_class(a,clnr)
% TARGET_CLASS  extracts the target class from an one-class dataset
%
% A = target_class(A,clnr)
%
% Extract the target class from an one-class dataset. When the label
% clnr is given, the class indicated by this label is taken.

% 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<2)
  clnr = 'target ';
end

[nlab,lablist,m,k,c] = dataset(a);

% use all data when it is unlabeled:
if (length(lablist)==1) & lablist==255
  laba = ones(m,1)*'target ';
  a = dataset(+a,char(laba),[],[],'target ');
  return;
end

% OK, this is a hack !!
% if the lablist contains characters, but all character values are
% smaller than 32 (smaller ASCI value), than something went probabily
% wrong, and then we assume it were just doubles)
if isa(lablist,'char')
  if length(find(lablist<32))==size(lablist,1)
    lablist = double(lablist);
  end
end

% 'double' target label should match with 'double' lablist, then we
% have to map everything to strings:
if isa(clnr,'double') & isa(lablist,'double')
  lablist = num2str(lablist);
  clnr = num2str(clnr);
end

% easy when the labels are strings:
if isa(clnr,'char')
  if isa(lablist,'double')
    clnr = strmatch(str2num(clnr),lablist);
  else % lablist is character
    clnr = strmatch(clnr,lablist);
  end
  %warning(['Class ',lablist(clnr,:),' is used as target class.']);
  if isempty(clnr)
    error('Cannot find target class objects.');
  end

  % give a sign what we are doing:
  if isa(lablist(clnr,:),'double')
    disp(['Class ',num2str(lablist(clnr,:)),' is used as target class.']);
  else
    if ~strcmp(deblank(lablist(clnr,:)),'target')
      disp(['Class ',lablist(clnr,:),' is used as target class.']);
    end
  end
end

% now everything is numeric:
I = find(nlab==clnr);
if isempty(I)
  error('Cannot find target class objects...');
end

% store the remaining data in b, if required:
if nargout>1
  J = setdiff(1:m,I);
  labb = ones(length(J),1)*'outlier';
  b = dataset(+a(J,:),char(labb),[],[],'outlier');
end

% and finish up:
laba = ones(length(I),1)*'target ';
a = dataset(+a(I,:),char(laba),[],[],'target ');


return

⌨️ 快捷键说明

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