using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication10 { class Program { static void Main(string[] args) { } public static List DoKMeans(PointCollection points, int clusterCount) { List allClusters = new List(); List> allGroups = ListUtility.SplitList(points, clusterCount); foreach (List group in allGroups) { PointCollection cluster = new PointCollection(); cluster.AddRange(group); allClusters.Add(cluster); } int movements = 1; while (movements > 0) { movements = 0; foreach (PointCollection cluster in allClusters) { for (int pointIndex = 0; pointIndex < cluster.Count; pointIndex++) { Point point = cluster[pointIndex]; int nearestCluster = FindNearestCluster(allClusters, point); if (nearestCluster != allClusters.IndexOf(cluster)) if (cluster.Count > 1) { Point removedPoint = cluster.RemovePoint(point); allClusters[nearestCluster].AddPoint(removedPoint); movements += 1; } } } } } return allClusters; } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)