/// <summary> /// Finds the specified number of neighbours to the specified data point /// </summary> /// <returns>Indecies for nearest</returns> public static int[] NearestNeighbours(this INormalizedData normalizedData, double[] point, int limit) { var normalizedPoint = normalizedData.Normalize(point); var nearestList = normalizedData .Data .Select((col, i) => new { i, Distance = Distance.EuclideanDistance(col, normalizedPoint) }) .OrderBy(x => x.Distance) .Take(limit) .Select(x => x.i) .ToArray(); return(nearestList); }
/// <summary> /// Normalizes a row of data given an existing min/max value /// </summary> /// <returns>Returns the normalized matrix</returns> public static double[] Normalize(this INormalizedData data, double[] row) { return(NormalizeTuple(data.MinMaxValues, row)); }