コード例 #1
0
ファイル: KMeans.cs プロジェクト: JoyceRen0116/SpatialSlur
        /// <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);
        }
コード例 #2
0
 /// <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()));
 }
コード例 #3
0
 /// <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)));
 }
コード例 #4
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));
 }
コード例 #5
0
 /// <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));
 }