/// <summary> /// Find how accurate NearestFromRange is on average when searching for the neighbors of every point (or a large sample of points). /// This finds the true K-nearest neighbors of each reference point (using Nearest) /// and the approximate K-nearest neighbors using the Hilbert index, /// then computes how accurate the Hilbert index was. /// </summary> /// <param name="k">Number of nearest neighbors sought.</param> /// <param name="rangeLength">Number of points in the Hilbert index to sample. /// The higher the number, the poorer the performance but higher the accuracy. /// </param> /// <param name="sampleSize">If zero, then analyze all points. /// Otherwise, base the accuracy on a sample of the points.</param> /// <returns>A value from zero to 1.0, where 1.0 means perfectly accurate.</returns> public double Accuracy(int k, int rangeLength, int sampleSize = 0) { if (sampleSize == 0) { sampleSize = Count; } var avg = UnsortedPoints.Take(sampleSize).Select(p => Accuracy(p, k, rangeLength)).Average(); return(avg); }
private void InitIndexing() { Index = new Dictionary <UnsignedPoint, Position>(); foreach (var pointWithIndex in UnsortedPoints.Select((p, i) => new { Point = p, OriginalPosition = i })) { Index[pointWithIndex.Point] = new Position(pointWithIndex.OriginalPosition, -1); } foreach (var pointWithIndex in SortedPoints.Select((p, i) => new { Point = p, SortedPosition = i })) { Index[pointWithIndex.Point].Sorted = pointWithIndex.SortedPosition; } IdsToPoints = new Dictionary <int, UnsignedPoint>(); foreach (var p in UnsortedPoints) { IdsToPoints[p.UniqueId] = p; } }