static void Knn() { IPoints points = Dataset.LoadDataset(@"c:\temp\points.csv"); // Used for testing K nearest neighbor IPointsKnn dataset = new PointsKnn(); dataset.Data.AddRange(points.Data.Select(i => i as IPKnn)); // Used for testing K nearest neighbor var rect = new SingleDetectLibrary.Code.Data.Rectangle { XMin = -180, XMax = 180, YMin = -90, YMax = 90, MaxDistance = 20, }; rect.Validate(); const int k = 3; IAlgorithm algo = new Algorithm(dataset, rect, StrategyType.Grid); var origin = new SingleDetectLibrary.Code.Data.P { X = 0, Y = 0 }; algo.UpdateIndex(origin); var duration = algo.UpdateKnn(origin, new KnnConfiguration{K = k}); // Print result CW(string.Format("{0} msec. {1}:", algo.Strategy.Name, duration)); CW("K Nearest Neighbors:"); CW(string.Format("Origin: {0}", origin)); CW(string.Format("Distance sum: {0}", algo.Knn.GetDistanceSum())); algo.Knn.NNs.OrderBy(i => i.Distance).ToList().ForEach(CW); // Update strategy algo.SetAlgorithmStrategy(new NaiveStrategy()); // Use algo duration = algo.UpdateKnn(origin, new KnnConfiguration{K = k}); // Print result CW(string.Format("\n{0} msec. {1}:", algo.Strategy.Name, duration)); CW("K Nearest Neighbors:"); CW(string.Format("Distance sum: {0}", algo.Knn.GetDistanceSum())); algo.Knn.NNs.OrderBy(i => i.Distance).ToList().ForEach(CW); }