Plot CreateIntraClusterPlot(ModelAnalyzer analyzer) { Plot intraClusterPlot = new Plot(); int pointsCount = analyzer.AnalyzedSongs.Count; double[] xValues = new double[pointsCount]; double[] yValues = new double[pointsCount]; int currentClusterIndex = analyzer.AnalyzedSongs[0].ClusterIndex; for (int i = 0; i < pointsCount; i++) { AnalyzedSong point = analyzer.AnalyzedSongs[i]; xValues[i] = i; yValues[i] = point.CentroidDistance; if (currentClusterIndex != point.ClusterIndex) { double value = (i + (i - 1)) / 2.0; string label = $"cluster {currentClusterIndex}"; intraClusterPlot.PlotVLine(value, VerticalDividerColor, label: label); } currentClusterIndex = point.ClusterIndex; } intraClusterPlot.PlotScatter(xValues, yValues, IntraClusterDistanceColor); intraClusterPlot.PlotHLine(analyzer.IntraClusterMeanDistance, IntraClustersMeanDistanceColor); return(intraClusterPlot); }
void AnalyzeIntraClusterDistance() { List <Song> centroids = Model.Centroids; IntraClusterDistances = new List <double>(centroids.Capacity); IntraClusterMeanDistance = 0.0; List <int> clusterCounts = new List <int>(centroids.Capacity); int songsCount = 0; for (int i = 0; i < centroids.Count; i++) { IntraClusterDistances.Add(0.0); clusterCounts.Add(0); } AnalyzedSongs = Model.ClusterizedSongs.Select(song => { double distance = Model.DistanceFunc.GetDistance(song.Song, centroids[song.ClusterIndex]); int index = song.ClusterIndex; AnalyzedSong analyzedSong = new AnalyzedSong { AssociatedSong = song.Song, ClusterIndex = index, CentroidDistance = distance, }; IntraClusterDistances[index] += distance; IntraClusterMeanDistance += distance; clusterCounts[index] += 1; songsCount += 1; return(analyzedSong); }).ToList(); for (int i = 0; i < IntraClusterDistances.Count; i++) { IntraClusterDistances[i] /= clusterCounts[i]; } IntraClusterMeanDistance /= songsCount; }