Пример #1
0
        private void DetermineClusters()
        {
            clusters = CreateRandomClusters();

            for (int i = 0; i < iterations; i++)
            {
                //Resets all of the clusters
                for (int c = 0; c < clusters.Length; c++)
                {
                    clusters[c].Clear();
                }

                //Adds each point to their closest cluster
                for (int p = 0; p < points.Length; p++)
                {
                    Cluster closestCluster = GetClosestCluster(points[p]);
                    closestCluster.AddIndex(p);
                }

                //Repositions each cluster's centroid to the average position of all of the points under it
                for (int c = 0; c < clusters.Length; c++)
                {
                    clusters[c].RecalculateCentroid();
                }
            }
        }