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

📄 srchbbt1nn.m

📁 一个关于数据聚类和模式识别的程序,在生物化学,化学中因该都可以用到.希望对大家有用,谢谢支持
💻 M
字号:
function [NNINDEX, NNDIST, DISTCOMPCOUNT] = srchbbt1nn(vec, tree, alldata)
% SRCHBBT1NN Branch-and-bound tree search for 1 nearest neighbor.
%	Usage: [NNINDEX, NNDIST, DISTCOMPCOUNT] = srchbbt1nn(vec, tree, alldata)
%		vec: test input vector
%		tree: tree structure generated by genBBT.m
%		alldata: all sample data points
%		NNINDEX: index of the nearest neighbor
%		NNDIST: distance to the nearest neighbor
%		DISTCOMPCOUNT: no. of distance computation
%
%	Field of tree structure:
%		tree(i).mean: mean vector of a tree node
%		tree(i).radius: radius vector of a tree node
%		tree(i).child: indices of children for a non-terminal node
%		tree(i).data: indices of data for a terminal node
%		tree(i).dist2mean: distance to mean of a terminal node
%
%	See also GENBBT, TRAVERSE.

%	Roger Jang, 20000114

global NNINDEX		% Nearest neighbor index
global NNDIST		% Nearest neighbor distance
global DISTCOMPCOUNT	% No. of distance computation
NNINDEX = nan;
NNDIST = inf;
DISTCOMPCOUNT = 0;
treesearch(vec, tree, 1, alldata);

% ====== Definition of treesearch() subfunction
function treesearch(vec, tree, index, alldata)
	global NNINDEX NNDIST DISTCOMPCOUNT
	% ====== According to rule 1
	if distance(vec, tree(index).mean) >= NNDIST+tree(index).radius, 
	%	fprintf('Node %g is skipped.\n', index);
		return;
	end

	if ~isempty(tree(index).child),
		% ====== Recursion into the child nodes
		for i=tree(index).child,
			treesearch(vec, tree, i, alldata);
		end
	else
		% ====== Check each data item
		dataindex = tree(index).data;
		dist2mean = tree(index).dist2mean;
		for i = 1:length(dataindex),
			% ====== According to rule 2
			if distance(vec, tree(index).mean) < NNDIST+dist2mean(i),
				temp = distance(vec, alldata(dataindex(i), :));
				if temp < NNDIST,
					NNDIST = temp;
					NNINDEX = dataindex(i);
				end
				DISTCOMPCOUNT = DISTCOMPCOUNT + 1;
			end
		end
	end

% ====== Definition of distance() subfunction
function out = distance(vec1, vec2)
	out = norm(vec1-vec2);

⌨️ 快捷键说明

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