/// <summary> /// Returns the number of data points that changed clusters. /// </summary> private int UpdateNearest() { // create balanced tree of cluster centers var tree = KdTree.CreateBalanced(_clusterCenters, _clusterIndices); // for each data point, find the nearest cluster center int count = 0; for (int i = 0; i < _points.Length; i++) { var nearest = tree.NearestL2(_points[i]); // update if new nearest is different than previous if (nearest != _nearestClusters[i]) { _nearestClusters[i] = nearest; count++; } } return(count); }
/// <summary> /// Inserts point value pairs in a way that produces a balanced tree. /// </summary> public static KdTree <int> CreateBalanced(double[][] points) { return(KdTree <int> .CreateBalanced(points, Enumerable.Range(0, points.Length).ToArray())); }
/// <summary> /// Inserts point value pairs in a way that produces a balanced tree. /// </summary> public static KdTree <int> CreateBalanced(IEnumerable <double[]> points) { return(KdTree <int> .CreateBalanced(points, Sequences.CountFrom(0))); }
/// <summary> /// Inserts point value pairs in a way that produces a balanced tree. /// </summary> public static KdTree <T> CreateBalanced <T>(double[][] points, T[] values) { return(KdTree <T> .CreateBalanced(points, values)); }
/// <summary> /// Inserts point value pairs in a way that produces a balanced tree. /// </summary> public static KdTree <T> CreateBalanced <T>(IEnumerable <double[]> points, IEnumerable <T> values) { return(KdTree <T> .CreateBalanced(points, values)); }