private void CalculateDistances() { Console.WriteLine("DISTANCES"); Console.WriteLine("---------------------------------------------------------------------------------------------"); int count = this.m_set.Samples.Count; for (int i = 0; i < count; i++) { for (int j = i; j < count; j++) { if (i == j) { continue; } int refX1 = m_set.Samples[i].X1; int refX2 = m_set.Samples[i].X2; int X1 = m_set.Samples[j].X1; int X2 = m_set.Samples[j].X2; double distance = Math.Round(FindDistance(refX1, refX2, X1, X2), 2); m_results[i, j] = new TrainingResult(j + 1, i + 1, distance); Console.WriteLine($"d({i + 1}, {j + 1}) = SQRT( ({refX1} - {X1}) ^ 2 + ({refX2} - {X2}) ^ 2 ) \tDISTANCE = {distance}"); } } }
private void DestroyMinRow() { TrainingResult min = this.GetMin(this.m_results); if (min != null) { this.RemoveXYFromResults(min.X, min.Y); } }
private void RemoveXYFromResults(int X, int Y) { double lowDestroy = 0.0d; int lowX = -1; int lowY = -1; for (int i = 0; i < this.m_results.GetLength(0); i++) { for (int j = 0; j < this.m_results.GetLength(1); j++) { //Console.WriteLine($"X:{X} Y:{Y} i:{i} j:{j} Distance:{this.m_results[i, j]?.Distance}"); if (j == X - 1) { TrainingResult current = this.m_results[i, j]; if (current != null) { double val = this.m_results[i, j].Distance; if (lowDestroy == 0) { lowDestroy = val; lowX = current.X; lowY = current.Y; } else if (lowDestroy > val) { lowDestroy = val; lowX = current.X; lowY = current.Y; } this.m_results[i, j] = null; } } } } if (lowX >= lowY) { this.m_data.Move(lowX, lowY); } else { this.m_data.Move(lowY, lowX); } if (!m_clusters.ContainsKey(lowDestroy)) { this.m_clusters.Add(lowDestroy, new List <int>() { lowX, lowY }); } else { this.m_clusters[lowDestroy].AddRange(new int[] { lowX, lowY }); } }
private TrainingResult GetMin(TrainingResult[,] results) { double min = double.MaxValue; int okX = 0; int okY = 0; for (int i = 0; i < results.GetLength(0); i++) { for (int j = 0; j < results.GetLength(1); j++) { TrainingResult current = results[i, j]; if (current != null) { if (current.Distance < min) { min = current.Distance; okX = i; okY = j; } } } } return(results[okX, okY]); }