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

📄 nndd.m

📁 模式识别工具箱,希望对大家有用!
💻 M
字号:
%NNDD Nearest neighbour data description method.% %       W = nndd(A,fracrej)% % Calculates the Nearest neighbour data description. Training only% consists of the computation of the resemblance of all training% objects to the training data using Leave-one-out.% % 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] = nndd(a,fracrej)if nargin < 2 | isempty(fracrej), fracrej = 0.05; endif nargin < 1 | isempty(a) % empty nndd  W = mapping(mfilename,{fracrej});  returnendif isa(fracrej,'double')           %training  if isa(a,'dataset')              %train on training set    a = target_class(a);      % make sure we have a OneClass dataset    [nlab,lablist,m,k,c] = dataset(a);    % settings:    small_D = 1.0e-10;  % small distance,    large_D = 1.0e+10;  % large distance.    % leave-one-out on the training set:    fit = zeros(m,1);    distmat = distm(a);    distmat = distmat + large_D*(distmat<small_D); %surpress 0 dist.    for i=1:m      D = distmat;      [minD minI] = min(D(i,:));  % dist. from z to 1NN in A      D(i,minI) = large_D;      intdist = min(D(:,minI));   % dist. from 1NN to NN(1NN)      fit(i) = minD./intdist;    end  else    % check that a is now an  nndd?    [W,classlist,type,k,c] = mapping(a);    fit = W.fit;  end  %now obtain the threshold:  thresh = -threshold(-fit,fracrej);  %and save all useful data:  out = fit;  W.x = +a;  W.threshold = thresh;  W.fit = fit;  W.D = min(distmat,[],2);  W.scale = mean(fit);%  W = {+a,thresh,fit,min(distmat,[],2),mean(fit)};  W = mapping(mfilename,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:  distmat = distm(a,W.x);    %dist between train and test  [mindist I] = min(distmat,[],2);  out = log([mindist./(W.D(I)) ones(m,1)*W.threshold]);  % map to probability  newout = dist2dens(out,W.scale);             W = dataset(newout,getlab(a),classlist,p,lablist);endreturn

⌨️ 快捷键说明

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