示例#1
0
        private int[] compute(double[][] points)
        {
            // first, select initial points
            double[][] seeds         = createSeeds(points, 2 * Bandwidth);
            var        maxcandidates = new ConcurrentStack <double[]>();

            // construct map of the data
            tree = KDTree.FromData <int>(points, distance);

            // now, for each initial point
            if (UseParallelProcessing)
            {
                Parallel.For(0, seeds.Length, (index) =>
                             iterate(seeds, maxcandidates, index));
            }
            else
            {
                for (int index = 0; index < seeds.Length; index++)
                {
                    iterate(seeds, maxcandidates, index);
                }
            }


            // suppress non-maximum points
            double[][] maximum = cut ? maxcandidates.ToArray() : supress(seeds);

            // create a decision map using seeds
            int[] seedLabels = classifySeeds(seeds, maximum);
            tree = KDTree.FromData(seeds, seedLabels, distance);

            // create the cluster structure
            clusters = new MeanShiftClusterCollection(tree, maximum);

            // label each point
            return(clusters.Nearest(points));
        }
示例#2
0
 /// <summary>
 ///   Initializes a new instance of the <see cref="MeanShiftCluster"/> class.
 /// </summary>
 ///
 /// <param name="owner">The owner.</param>
 /// <param name="index">The cluster index.</param>
 ///
 public MeanShiftCluster(MeanShiftClusterCollection owner, int index)
 {
     this.owner = owner;
     this.index = index;
 }