Пример #1
0
        /// <summary>
        /// Returns the number of data points that changed clusters.
        /// </summary>
        private int UpdateNearestParallel()
        {
            // create balanced tree of cluster centers
            var tree = KdTree <int> .CreateBalanced(_clusterCenters, _clusterIndices);

            // for each data point, find the nearest cluster center
            int count = 0;

            Parallel.ForEach(Partitioner.Create(0, _points.Length), range =>
            {
                for (int i = range.Item1; i < range.Item2; i++)
                {
                    var nearest = tree.NearestL2(_points[i]);

                    // update if new nearest is different than previous
                    if (nearest != _nearestClusters[i])
                    {
                        _nearestClusters[i] = nearest;
                        Interlocked.Increment(ref count);
                    }
                }
            });

            return(count);
        }
Пример #2
0
        /// <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);
        }
Пример #3
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()));
 }
Пример #4
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)));
 }
Пример #5
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));
 }
Пример #6
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));
 }