public Claster[] Clasterize(STATND statNd, int needClasterCount, IClasterMetrics D) { List <Claster> clasters = formClasterForEachPoint(statNd); Matrix distances = CalcMatrixOfDistances(clasters, D); while (clasters.Count > needClasterCount) { int[] ij = FindMinDistance(distances); int l = ij[0], h = ij[1]; //l always bigger than h??? clasters[h].AppendPointsFromClater(clasters[l]); distances = distances.RemoveRow(l); distances = distances.RemoveColumn(l); //go by row for (int m = 0; m < h; m++) { distances[h, m] = D.LansaWilliamsDistance(clasters[l], clasters[h], clasters[m]); } //go by column for (int m = h + 1; m < distances.Rows; m++) { int mReal = m >= l ? m + 1 : m; //in array of clasters distances[m, h] = D.LansaWilliamsDistance(clasters[l], clasters[h], clasters[mReal]); } //it is here, cause we need in Sl, Sh, Sm for Lansa Williamsa clasters.RemoveAt(l); } return(clasters.ToArray()); }
private static List <Claster> formClasterForEachPoint(STATND statNd) { double[][] data = statNd.getJaggedArrayOfData(); int N = data.GetLength(0); //Claster[] clasters = new Claster[N]; Claster[] clasters = Enumerable.Range(0, N).Select(el => new Claster()).ToArray(); for (int i = 0; i < N; i++) { clasters[i].AddPoint(data[i]); } return(clasters.ToList()); }