示例#1
0
        private Coord GetNearestNeighbour(Coord coord)
        {
            double minDistance = double.PositiveInfinity;
            Coord  nearest     = new Coord(250, 250, 0);

            foreach (Coord seenCoord in seen)
            {
                double distance = metric.GetDistance(seenCoord, coord);
                if (distance < minDistance && distance != 0)
                {
                    minDistance = distance;
                    nearest     = seenCoord;
                }
            }
            return(nearest);
        }
示例#2
0
文件: Knn.cs 项目: jurczewski/KSR
        public static string guesLabel(IMetric metric, int k, List <ProcessedArticle> trainingArticles, ProcessedArticle articleToLabel)
        {
            List <ProcessedArticle> knn = trainingArticles.OrderBy(a => metric.GetDistance(a.getFeatureVector(), articleToLabel.getFeatureVector())).ToList();

            return(knn.Take(k).GroupBy(a => a.label).OrderBy(g => g.Count()).Last().Key);
        }