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

📄 mclassc.m

📁 The pattern recognition matlab toolbox
💻 M
字号:
%MCLASSC Computation of multi-class classifier from 2-class discriminants%%  W = MCLASSC(A,CLASSF,MODE)%% INPUT%   A       Dataset%   CLASSF  Untrained classifier%   MODE    Type of handling multi-class problems (optional; default: 'single')%% OUTPUT%   W       Combined classifier%% DESCRIPTION% For default MODE = 'single', the untrained classifier CLASSF is called to% compute C classifiers between each of the C classes in the dataset A and% the remaining C-1 classes. The result is stored into the combined% classifier W. There is no combining rule added. The default rule, MAXC% might be replaced by adding one, e.g. W = W*MEANC.%% For MODE = 'multi' the untrained classifier CLASSF is trained between all% pairs of classes as well as between each class and all other classes.% This total set of C classes is combined by MINC.  The use of soft labels% is supported.%% EXAMPLES% W = MCLASSC(GENDATM(100),QDC,'MULTI');%% SEE ALSO% DATASETS, MAPPINGS, MAXC, MINC.% Copyright: R.P.W. Duin, r.p.w.duin@prtools.org% Faculty EWI, Delft University of Technology% P.O. Box 5031, 2600 GA Delft, The Netherlands% $Id: mclassc.m,v 1.7 2007/11/20 10:27:24 duin Exp $function [w,varargout] = mclassc(a,classf,mode);	prtrace(mfilename);    varargout = repmat({[]},[1, max((nargout-1),0)]);	  if nargin < 3, mode = 'single'; end	if nargin < 2, classf = []; end	if nargin < 1 | isempty(a)    %fixed w=mclassc(dataset,ldc)    w = mapping(mfilename,{classf,mode});		return	end		if ~isa(classf,'mapping') | ~isuntrained(classf)		error('Second parameter should be untrained mapping')	end	islabtype(a,'crisp','soft');	isvaldfile(a,1,2); % at least 1 object per class, 2 classes	fid = []; % Progress messages default destination	[m,k,c] = getsize(a);		if c == 2		[w,varargout] = map(a,classf);		return	end	varout = {};  lablist = getlablist(a);	switch mode	 case 'single'	  w = [];	  %	lablist = getlablist(a);				len1 = prprogress(fid,'Multi-class: %4i classifiers: ',c); 		len2 = prprogress(fid,'%5i',0); 	  for i=1:c			closemess(fid,len2);			len2 = prprogress(fid,'%5i',i);		  if islabtype(a,'crisp')			  mlab = 2 - (getnlab(a) == i);			  aa = setlabels(a,mlab);				aa = remclass(aa);  % remove empty classes				%aa = setnlab(a,mlab);				%aa = setlablist(aa,[1 2]');				if ~isempty(a.prior)					aa = setprior(aa,[a.prior(i),1-a.prior(i)]');				end		  elseif islabtype(a,'soft')			  atargets = gettargets(a);			  targets = [atargets(:,i) 1-atargets(:,i)]; %assumes soft labels sum to one???			  aa = dataset(+a,mlab,targets,'lablist',[1 2]');		  end			varo = varargout;      [v,varo{:}] = map(aa,classf);			varout = [varout; varo];			w = [w,setlabels(v(:,1),lablist(i,:))];	  end	 case 'multi'	  w = [];		len1 = prprogress(fid,'Multi-class: %4i classifiers: ',c*(c-1)); 		len2 = prprogress(fid,'%5i',0); 		nclassf = 0;	  nlab = getnlab(a);	  for i1=1:c		  lab = lablist(i1,:);		  		  J1 = find(nlab==i1);		  if islabtype(a,'crisp')			  mlab = ones(m,1);			  mlab(J1) = zeros(length(J1),1);			  aa = setlabels(a,mlab);				aa = remclass(aa); % remove empty classes		  else			  problab = gettargets(a);			  mlab = [problab(:,i1) sum(problab,2)-problab(:,i1)];			  aa = settargets(a,mlab,[1 2]');		  end				  I1 = [1:c]; I1(i1) = [];			varo = varargout;      [v,varo{:}] = map(aa,classf);			varout = [varout; varo];      w = [w,setlabels(v(:,1),lab)];		  for i2 = I1 			  if islabtype(a,'crisp')				  J2 = find(nlab==i2);				  v = aa([J1;J2],:)*classf;			  else				  mlab2 = problab(:,[i1 i2]);				  v = setlabels(aa,mlab2)*classf;			  end			  w = [w,setlabels(v(:,1),lab)];				nclassf = nclassf+1;				closemess(fid,len2);				len2 = prprogress(fid,'%5i',i1);		  end	  end	  w = minc(w);	 otherwise	  error('Unknown mode')	end	closemess(fid,len1+len2);		w = setname(w,getname(classf));	w = setsize(w,[k,c]);	w = setcost(w,a);	if ~isempty(varout)    varargout = num2cell(varout',2)';  end  	return

⌨️ 快捷键说明

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