Index: /prextra/prextra/annquerycheck.m
===================================================================
--- /prextra/prextra/annquerycheck.m	(revision 4)
+++ /prextra/prextra/annquerycheck.m	(revision 4)
@@ -0,0 +1,9 @@
+%ANNQUERYCHECK  Check whether the ANN Matlab Wrapper toolbox is in the path
+
+function annquerycheck
+	
+	if exist('annquery','file') ~= 2
+		error([newline 'The ANN Matlab Wrapper package is not found. Download and install it from' ...
+			newline 'http://webscripts.softpedia.com/scriptDownload/ANN-MATLAB-Wrapper-Download-33976.html'])
+	end
+		
Index: /prextra/prextra/kannc.m
===================================================================
--- /prextra/prextra/kannc.m	(revision 4)
+++ /prextra/prextra/kannc.m	(revision 4)
@@ -0,0 +1,71 @@
+%KANNC 1-Nearest Neighbor Classifier using ANNQUERY
+%
+%   W = KANNC(A,,K,OPTION)
+%
+% INPUT
+%   A      Dataset
+%   K      Number of desired neighbours
+%   OPTION Options for ANNQUERY
+%
+% OUTPUT
+%   W      NN classifier using the ANN Query package
+%
+% DESCRIPTION  
+% This is the nearest neighbor implementation for PRTools using the
+% ANNQUERY package 
+%
+% SEE ALSO
+% MAPPINGS, DATASETS, ANNQUERY, KNNC
+
+% 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
+
+
+function out = kannc(a,knn,opt)
+
+	prtrace(mfilename);
+	
+	name = 'KANNC';
+	% No input data, return an untrained classifier.
+	if nargin < 3, opt = []; end
+	if nargin < 2, knn = 1; end
+	if (nargin == 0) | (isempty(a))
+		out = mapping(mfilename,'untrained',{knn,opt});
+		out = setname(out,name);
+	elseif isdataset(a) & ~ismapping(knn) % training
+		islabtype(a,'crisp');
+		isvaldfile(a,1,2); % at least 1 object per class, 2 classes
+		a = testdatasize(a);
+		a = testdatasize(a,'objects');
+		a = seldat(a);    % get labeled objects only
+		[m,k,c] = getsize(a);
+		v.data = a;
+		v.knn  = knn;
+		v.opt  = opt;
+		out = mapping(mfilename,'trained',v,getlablist(a),k,c);
+		out = setname(out,name);
+	elseif nargin == 2 & ismapping(knn)  % execution
+		% to avoid confusion, rename trained mapping
+		w = knn;
+		v = +w;   % get datafield
+		[k,c] = size(w);
+		nlab = getnlab(v.data);
+		J = annquery(+v.data',(+a)',v.knn)';
+		n = size(J,1); % no of test objects
+		J = nlab(J);
+		if size(J,2) == 1
+			out = zeros(2,n);
+			out([1:2:n*2]+J'-1) = ones(1,n);
+			out = out';
+		else
+			out = hist(J,[1:c]);
+		end
+		% Use Bayes estimators for posteriors
+		out = (out+ones(size(out,1),2))/(v.knn+c);
+		out = setdat(a,out,w);
+	else
+		error('Illegal input')
+	end
+		
+	
Index: /prextra/prextra/kdnnc.m
===================================================================
--- /prextra/prextra/kdnnc.m	(revision 4)
+++ /prextra/prextra/kdnnc.m	(revision 4)
@@ -0,0 +1,75 @@
+%KDNNC 1-Nearest Neighbor Classifier using KDTree
+%
+%   W = KNNC(A,TYPE)
+%
+% INPUT
+%   A      Dataset
+%   TYPE  'fast' (default) or 'good'
+%
+% OUTPUT
+%   W      NN classifier using KDTree for finding nearest neighbors
+%
+% DESCRIPTION  
+% This is a KD-Tree nearest neighbor implementation for PRTools using the
+% KD-Tree package by Pramod Vemulapalli, see 
+% http://www.mathworks.com/matlabcentral/fileexchange/26649-kdtree-implementation-in-matlab
+% It should be in the Matlab search path.
+%
+% SEE ALSO
+% MAPPINGS, DATASETS, KNNC
+
+% 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
+
+
+function out = kdnnc(a,par)
+
+	prtrace(mfilename);
+	
+	kdtreecheck;
+	name = 'KDTree NN Classifier';
+	% No input data, return an untrained classifier.
+	if nargin < 2, par = 'good'; end
+	if (nargin == 0) | (isempty(a))
+		out = mapping(mfilename,'untrained',par);
+		out = setname(out,name);
+	elseif isdataset(a) & isstr(par) % training
+		if isempty(strmatch(par,char('fast','good')))
+			error('KDTree type should be either ''fast'' or ''good''')
+		end
+		islabtype(a,'crisp');
+		isvaldfile(a,1,2); % at least 1 object per class, 2 classes
+		a = testdatasize(a);
+		a = testdatasize(a,'objects');
+		a = seldat(a);    % get labeled objects only
+		[m,k,c] = getsize(a);
+		data.kdtree = kd_buildtree(+a,0);
+		data.nlab = getnlab(a);
+		data.type = par;
+		out = mapping(mfilename,'trained',data,getlablist(a),k,c);
+		out = setname(out,name);
+	elseif nargin == 2 & ismapping(par)  % execution
+		kdtree = getdata(par,'kdtree');
+		nlab = getdata(par,'nlab');
+		if strcmp(getdata(par,'type'),'fast')
+			kdtype = @kd_closestpointfast;
+		else
+			kdtype = @kd_closestpointgood;
+		end
+		a_data = +a;
+		% PRTools want posteriors. In this case these are just 0/1 's
+		out = zeros(size(a,1),size(getlab(par),1));
+		m = size(a,1);
+		s = sprintf('Testing %i objects: ',m);
+		prwaitbar(m,s);
+		for i=1:m;
+			prwaitbar(m,i,[s int2str(i)]);
+			j = kdtype(kdtree,a_data(i,:));
+			out(i,nlab(j)) = 1;
+		end
+		prwaitbar(0);
+		out = setdat(a,out);
+	end
+		
+	
Index: /prextra/prextra/kdtreecheck.m
===================================================================
--- /prextra/prextra/kdtreecheck.m	(revision 4)
+++ /prextra/prextra/kdtreecheck.m	(revision 4)
@@ -0,0 +1,9 @@
+%KDTREECHECK  Check whether the KDTree toolbox is in the path
+
+function kdtreecheck
+	
+	if exist('kd_buildtree','file') ~= 2
+		error([newline 'The KDTree package is not found. Download and install it from' ...
+			newline 'http://www.mathworks.com/matlabcentral/fileexchange/26649-kdtree-implementation-in-matlab/'])
+	end
+		
