public FixedSizePriorityQueue <float, IPointIdFloat> NearestNNeighborsAndDistance(IPointIdFloat target, int N) { ValidatePoint(target); ValidateSize(N, "N"); if (N <= 0) { throw new ArgumentException("N must be positive."); } var results = new FixedSizePriorityQueue <float, IPointIdFloat>(N); var nns = root.NearestNNeighbors(target, results, _distFunc); return(nns); }
public FixedSizePriorityQueue <float, IPointIdFloat> NearestNNeighbors(IPointIdFloat target, FixedSizePriorityQueue <float, IPointIdFloat> nns, Func <VBuffer <float>, VBuffer <float>, float> distFunc) { float key = KeyByDepth(point, depth); float targetKey = KeyByDepth(target, depth); float d = distFunc(point.coordinates, target.coordinates); IKdTreeNode closestBranch, fartherBranch; float nthNnDist = -nns.Peek().GetValueOrDefault(InfinitePoint).Key; if (!nns.IsFull || d < nthNnDist) { nns.Enqueue(-d, point); } if (targetKey <= key) { closestBranch = left; fartherBranch = right; } else { closestBranch = right; fartherBranch = left; } nns = closestBranch.NearestNNeighbors(target, nns, distFunc); nthNnDist = -nns.Peek().GetValueOrDefault(InfinitePoint).Key; if (Math.Abs(targetKey - key) <= nthNnDist) { nns = fartherBranch.NearestNNeighbors(target, nns, distFunc); } return(nns); }
public FixedSizePriorityQueue <float, IPointIdFloat> NearestNNeighbors(IPointIdFloat target, FixedSizePriorityQueue <float, IPointIdFloat> nns, Func <VBuffer <float>, VBuffer <float>, float> distFunc) { return(nns); }