public void CalculateClusterContents() { bool exit = false; int iteration = 0; while (!exit) { foreach (Cluster cluster in clusters) { cluster.Clear(); } ArrayList lastCentroids = GetCentroids(); DeterminePointsInCluster(); SetClusters(); iteration++; ArrayList currentCentroids = GetCentroids(); iteration++; double distance = 0; for (int i = 0; i < lastCentroids.Count; i++) { distance += Point.EuclideanDistance(((Point)lastCentroids[i]), ((Point)currentCentroids[i])); } ClusterIO.WriteClusters(numberOfClusters, clusters, iteration, distance); if (distance == 0) { exit = true; } } }
public void PlantSeeds() { Random random = new Random(); for (int i = 0; i < numberOfClusters; i++) { Cluster cluster = new Cluster(i); Point centroid = new Point(2 * random.Next(minimumCoord, 15), random.Next(0, maximumCoord * random.Next(0, 3))); cluster.centroid = centroid; clusters.Add(cluster); } ClusterIO.WriteClusters(numberOfClusters, clusters, 0, 0); }
public void DetermineOutliers() { foreach (Cluster cluster in clusters) { points = cluster.GetPoints(); for (int i = 0; i < points.Count; i++) { if (Point.EuclideanDistance((Point)points[i], cluster.centroid) > clusterThreshold) { outliers.Add(points[i]); points.Remove(points[i]); } } } ClusterIO.WriteClusters(numberOfClusters, clusters, 0, 0); ClusterIO.WriteOutliers(outliers); }