have this \[code\]dbscan\[/code\] algorithm grouping data from an array into clusters based on their values...Going wrong somewhere.. Couldn't figure out\[code\]using System; using System.Collections.Generic; using System.Linq;using System.Text;namespace ConsoleApplication1 { class value { public const int NOISE = -1; public const int UNCLASSIFIED = 0; public int X, ClusterId; public value(int x) { this.X = x; } public static double DistanceSquared(int p1,int p2) { int diff1 = p2 - p1; int diff2 = p1 - p2; return Math.Sqrt (diff1 * diff2); } } static class DBSCAN { static void Main() { int[] numbers = { 28,26,27,29,26,22,27,28,28,22,28,26,27,00,30,27,25,25,29,27,26,28,29,32,26,19,28,30,33,32,00,30,30,32,28,31,30,30,29,28,33,19,18,30,32,32,25,31,31,29,29,30,28,28}; List<int> points = new List<int>(numbers); double eps = 1; int minPts = 3; List<List<int>> clusters = GetClusters(points, eps, minPts); Console.Clear(); // print points to console Console.WriteLine("The {0} points are :\n", points.Count); foreach (int p in points) Console.Write(" {0} ", p); Console.WriteLine(); // print clusters to console int total = 0; for (int i = 0; i < clusters.Count; i++) { int count = clusters.Count; total += count; string plural = (count != 1) ? "s" : ""; Console.WriteLine("\nCluster {0} consists of the following {1} point{2} :\n", i + 1, count, plural); foreach ( int p in clusters) Console.Write(" {0} ", p); Console.WriteLine(); } // print any points which are NOISE total = points.Count - total; if (total > 0) { string plural = (total != 1) ? "s" : ""; string verb = (total != 1) ? "are" : "is"; Console.WriteLine("\nThe following {0} point{1} {2} NOISE :\n", total, plural, verb); foreach (int p in points) { if (p.ClusterId == value.NOISE) Console.Write(" {0} ", p); } Console.WriteLine(); } else { Console.WriteLine("\nNo points are NOISE"); } Console.ReadKey(); } static List<List<int>> GetClusters(List<int> points, double eps, int minPts) { if (points == null) return null; List<List<int>> clusters = new List<List<int>>(); // eps *= eps; // square eps int clusterId = 1; for (int i = 0; i < points.Count; i++) { int p = points; if (p.ClusterId == value.UNCLASSIFIED) { if (ExpandCluster(points, p, clusterId, eps, minPts)) clusterId++; } } // sort out points into their clusters, if any int maxClusterId = points.OrderBy(p => p.ClusterId).Last().ClusterId; if (maxClusterId < 1) return clusters; // no clusters, so list is empty for (int i = 0; i < maxClusterId; i++) clusters.Add(new List<int>()); foreach (int p in points) { if (p.ClusterId > 0) clusters[p.ClusterId - 1].Add(p); } return clusters; } static List<int> GetRegion(List<int> points, int p, double eps) { List<int> region = new List<int>(); for (int i = 0; i < points.Count; i++) { double distSquared = value.DistanceSquared(p, points); if (distSquared <= eps) region.Add(points); } return region; } static bool ExpandCluster(List<int> points, int p, int clusterId, double eps, int minPts) { List<int> seeds = GetRegion(points, p, eps); if (seeds.Count < minPts) // no core point { p.ClusterId = value.NOISE; return false; } else // all points in seeds are density reachable from point 'p' { for (int i = 0; i < seeds.Count; i++) seeds.ClusterId = clusterId; seeds.Remove(p); while (seeds.Count > 0) { int currentP = seeds[0]; List<int> result = GetRegion(points, currentP, eps); if (result.Count >= minPts) { for (int i = 0; i < result.Count; i++) { int resultP = result; if (resultP.ClusterId == value.UNCLASSIFIED || resultP.ClusterId == value.NOISE) { if (resultP.ClusterId == value.UNCLASSIFIED) seeds.Add(resultP); resultP.ClusterId = clusterId; } } } seeds.Remove(currentP); } return true; } } } }\[/code\]