srchbbt1nn.html
来自「一个关于数据聚类和模式识别的程序,在生物化学,化学中因该都可以用到.希望对大家有」· HTML 代码 · 共 127 行
HTML
127 行
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"><html><head> <title>Description of srchBBT1nn</title> <meta name="keywords" content="srchBBT1nn"> <meta name="description" content="SRCHBBT1NN Branch-and-bound tree search for 1 nearest neighbor."> <meta http-equiv="Content-Type" content="text/html; charset=big5"> <meta name="generator" content="m2html © 2003 Guillaume Flandin"> <meta name="robots" content="index, follow"> <link type="text/css" rel="stylesheet" href="../m2html.css"></head><body><a name="_top"></a><div><a href="../index.html">Home</a> > <a href="index.html">dcpr</a> > srchBBT1nn.m</div><!--<table width="100%"><tr><td align="left"><a href="../index.html"><img alt="<" border="0" src="../left.png"> Master index</a></td><td align="right"><a href="index.html">Index for dcpr <img alt=">" border="0" src="../right.png"></a></td></tr></table>--><h1>srchBBT1nn</h1><h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2><div class="box"><strong>SRCHBBT1NN Branch-and-bound tree search for 1 nearest neighbor.</strong></div><h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2><div class="box"><strong>function [NNINDEX, NNDIST, DISTCOMPCOUNT] = srchbbt1nn(vec, tree, alldata) </strong></div><h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2><div class="fragment"><pre class="comment"> 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 <a href="genBBT.html" class="code" title="function NODE = genbbt(data, clusterNum, levelNum);">GENBBT</a>, TRAVERSE.</pre></div><!-- crossreference --><h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>This function calls:<ul style="list-style-image:url(../matlabicon.gif)"></ul>This function is called by:<ul style="list-style-image:url(../matlabicon.gif)"></ul><!-- crossreference --><h2><a name="_subfunctions"></a>SUBFUNCTIONS <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2><ul style="list-style-image:url(../matlabicon.gif)"><li><a href="#_sub1" class="code">function treesearch(vec, tree, index, alldata)</a></li><li><a href="#_sub2" class="code">function out = distance(vec1, vec2)</a></li></ul><h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2><div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function [NNINDEX, NNDIST, DISTCOMPCOUNT] = srchbbt1nn(vec, tree, alldata)</a>0002 <span class="comment">% SRCHBBT1NN Branch-and-bound tree search for 1 nearest neighbor.</span>0003 <span class="comment">% Usage: [NNINDEX, NNDIST, DISTCOMPCOUNT] = srchbbt1nn(vec, tree, alldata)</span>0004 <span class="comment">% vec: test input vector</span>0005 <span class="comment">% tree: tree structure generated by genBBT.m</span>0006 <span class="comment">% alldata: all sample data points</span>0007 <span class="comment">% NNINDEX: index of the nearest neighbor</span>0008 <span class="comment">% NNDIST: distance to the nearest neighbor</span>0009 <span class="comment">% DISTCOMPCOUNT: no. of distance computation</span>0010 <span class="comment">%</span>0011 <span class="comment">% Field of tree structure:</span>0012 <span class="comment">% tree(i).mean: mean vector of a tree node</span>0013 <span class="comment">% tree(i).radius: radius vector of a tree node</span>0014 <span class="comment">% tree(i).child: indices of children for a non-terminal node</span>0015 <span class="comment">% tree(i).data: indices of data for a terminal node</span>0016 <span class="comment">% tree(i).dist2mean: distance to mean of a terminal node</span>0017 <span class="comment">%</span>0018 <span class="comment">% See also GENBBT, TRAVERSE.</span>0019 0020 <span class="comment">% Roger Jang, 20000114</span>0021 0022 <span class="keyword">global</span> NNINDEX <span class="comment">% Nearest neighbor index</span>0023 <span class="keyword">global</span> NNDIST <span class="comment">% Nearest neighbor distance</span>0024 <span class="keyword">global</span> DISTCOMPCOUNT <span class="comment">% No. of distance computation</span>0025 NNINDEX = nan;0026 NNDIST = inf;0027 DISTCOMPCOUNT = 0;0028 <a href="#_sub1" class="code" title="subfunction treesearch(vec, tree, index, alldata)">treesearch</a>(vec, tree, 1, alldata);0029 0030 <span class="comment">% ====== Definition of treesearch() subfunction</span>0031 <a name="_sub1" href="#_subfunctions" class="code">function treesearch(vec, tree, index, alldata)</a>0032 <span class="keyword">global</span> NNINDEX NNDIST DISTCOMPCOUNT0033 <span class="comment">% ====== According to rule 1</span>0034 <span class="keyword">if</span> <a href="#_sub2" class="code" title="subfunction out = distance(vec1, vec2)">distance</a>(vec, tree(index).mean) >= NNDIST+tree(index).radius, 0035 <span class="comment">% fprintf('Node %g is skipped.\n', index);</span>0036 <span class="keyword">return</span>;0037 <span class="keyword">end</span>0038 0039 <span class="keyword">if</span> ~isempty(tree(index).child),0040 <span class="comment">% ====== Recursion into the child nodes</span>0041 <span class="keyword">for</span> i=tree(index).child,0042 <a href="#_sub1" class="code" title="subfunction treesearch(vec, tree, index, alldata)">treesearch</a>(vec, tree, i, alldata);0043 <span class="keyword">end</span>0044 <span class="keyword">else</span>0045 <span class="comment">% ====== Check each data item</span>0046 dataindex = tree(index).data;0047 dist2mean = tree(index).dist2mean;0048 <span class="keyword">for</span> i = 1:length(dataindex),0049 <span class="comment">% ====== According to rule 2</span>0050 <span class="keyword">if</span> <a href="#_sub2" class="code" title="subfunction out = distance(vec1, vec2)">distance</a>(vec, tree(index).mean) < NNDIST+dist2mean(i),0051 temp = <a href="#_sub2" class="code" title="subfunction out = distance(vec1, vec2)">distance</a>(vec, alldata(dataindex(i), :));0052 <span class="keyword">if</span> temp < NNDIST,0053 NNDIST = temp;0054 NNINDEX = dataindex(i);0055 <span class="keyword">end</span>0056 DISTCOMPCOUNT = DISTCOMPCOUNT + 1;0057 <span class="keyword">end</span>0058 <span class="keyword">end</span>0059 <span class="keyword">end</span>0060 0061 <span class="comment">% ====== Definition of distance() subfunction</span>0062 <a name="_sub2" href="#_subfunctions" class="code">function out = distance(vec1, vec2)</a>0063 out = norm(vec1-vec2);</pre></div><hr><address>Generated on Thu 30-Oct-2008 12:53:56 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/">m2html</a></strong> © 2003</address></body></html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?