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

📄 kmeans_dd.m

📁 模式识别工具箱,希望对大家有用!
💻 M
字号:
%KMEANS_DD k-means data description.% %       W = kmeans_dd(A,fracrej,K)% % Train a k-means method with K prototypes on dataset A. Parameter% fracrej gives the fraction of the target set which will be rejected.% % This method requires the k-means from the NetLab toolbox. Here the% means are optimized using a EM algorithm. To avoid confusion with% the PRTools kmeans, the NetLab kmeans is copied to mykmeans and this% version is used.% % See also datasets, mappings, dd_roc% Copyright: D. Tax, R.P.W. Duin, duin@ph.tn.tudelft.nl% Faculty of Applied Physics, Delft University of Technology% P.O. Box 5046, 2600 GA Delft, The Netherlands  function [W,out] = kmeans_dd(a,fracrej,K,epochs)if nargin < 4,  epochs = 1000; endif nargin < 3 | isempty(K), K = 5; endif nargin < 2 | isempty(fracrej), fracrej = 0.05; endif nargin < 1 | isempty(a) % empty dd  W = mapping('kmeans_dd',{fracrej,N});  returnendif isa(fracrej,'double')           %training  if ~isa(a,'dataset')              %train on training set    error('KMEANS_DD: I need a dataset to train');  end  a = oc_set(a);     % make sure a is an OC dataset  [nlab,lablist,m,k,c] = dataset(a);  % train it:  options = 0; options(14) = epochs;  w0 = rand(K,k);  w = mykmeans(w0, +a, options);  w = setdiff(w,w0,'rows');  w = unique(w,'rows');%  if max(size(w))<2%    error('Did not find a solution');%  end  % obtain the threshold:  d = min(dist(+a,w'),[],2);  if (size(d,2)~=1)    d = d';  end  thr = -threshold(-d,fracrej);  %and save all useful data:  W.w = w;  W.threshold = thr;  W.scale = mean(d);  W = mapping('kmeans_dd',W,str2mat('target','outlier'),k,c);else                               %testing  [W,classlist,type,k,c] = mapping(fracrej);  % unpack  [nlab,lablist,m,k,c,p] = dataset(a);  %compute:  out = min(dist(W.w,a'))';  if max(size(out))==1    out  end  newout = dist2dens([out ones(m,1)*W.threshold],W.scale);  W = dataset(newout,getlab(a),classlist,p,lablist);endreturn

⌨️ 快捷键说明

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