www.gusucode.com > 混沌时间序列工具箱 > 混沌时间序列工具箱/ChaosToolbox1p0_trial/LargestLyapunov_Rosenstein/SearchNN.m

    function [index,distance] = SearchNN(xn,query_indices,k,exclude)
% 在重构相空间中寻找最近邻点对 (调用工具箱 OpenTSTOOL 函数 nn_prepare.dll, nn_search.dll)
% 输入:   xn                重构的相空间
%         query_indices     最近邻参考点缺省为,[1:size(xn,2)]'  
%         k                 最近邻点的个数,缺省为 1
%         exclude           限制短暂分离,大于序列平均周期,缺省为 0
% 输出:   index             最近邻点下标
%         distance          最近邻距离  

%--------------------------------------------------

if nargin < 4 
    exclude = 0;        % 限制短暂分离,大于序列平均周期        
    if nargin < 3
        k = 1;                  % 最近邻点的个数
        if nargin < 2
            N = size(xn,2);             % 重构轨道点数
            query_indices = [1:N]';     % 参考点    
        end
    end
end

[rows,cols] = size(query_indices);
if rows<cols
    query_indices = query_indices';         % query_indices 必须是列向量
end

pointset = xn';             % 相空间中的点,每行为一个点
epsilon = 0;                % 最近邻点计算的相对误差 

atria = SearchNN_Buffer1(pointset);
[index,distance] = SearchNN_Buffer2(pointset,atria,query_indices,k,exclude,epsilon);