Changeset 13850 for branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis.Views/3.4/DensityTrackbar.cs
- Timestamp:
- 05/18/16 16:28:59 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis.Views/3.4/DensityTrackbar.cs
r13846 r13850 23 23 using System.Collections.Generic; 24 24 using System.Globalization; 25 using System.Linq;26 25 using System.Windows.Forms; 27 using System.Windows.Forms.DataVisualization.Charting;28 using HeuristicLab.Common;29 26 using HeuristicLab.Problems.DataAnalysis; 30 27 … … 76 73 77 74 private void UpdateDensityChart() { 78 var series = chart.Series[0]; 79 ClearPointsQuick(series.Points); 80 81 int numBuckets = trackBar.Maximum - trackBar.Minimum; 82 var buckets = new double[numBuckets]; 83 var bucketSize = (Limits.Upper - Limits.Lower) / buckets.Length; 84 foreach (var value in trainingValues) { 85 if (bucketSize > 0.0) { 86 int bucketIndex = (int)((value - Limits.Lower) / bucketSize); 87 if (bucketIndex == numBuckets) { 88 bucketIndex--; 89 } 90 buckets[bucketIndex] += 1.0; 91 } 92 } 93 94 // set minimum height of all non-zero buckets on 20% of maximum 95 double min = buckets.Max() / 20.0; 96 for (int i = 0; i < buckets.Length; i++) { 97 if (buckets[i] >= 1 && buckets[i] < min) 98 buckets[i] = min; 99 } 100 101 series.Points.DataBindY(buckets); 102 103 // Set trackbar on highest density 104 double highestDensity = buckets.Max(); 105 var highestIndices = buckets.Select((v, i) => new { v, i }).Where(x => x.v.IsAlmost(highestDensity)).Select(x => x.i).ToList(); 106 trackBar.Value = highestIndices[highestIndices.Count / 2]; 75 chart.UpdateChart(trainingValues, Limits.Lower, Limits.Upper, 76 numBuckets: trackBar.Maximum - trackBar.Minimum, minimumHeight: 0.1); 107 77 } 108 78 … … 155 125 return (int)((value - lower) / ((upper - lower) / numberOfTicks)); 156 126 } 157 158 // workaround as per http://stackoverflow.com/questions/5744930/datapointcollection-clear-performance159 private static void ClearPointsQuick(DataPointCollection points) {160 points.SuspendUpdates();161 while (points.Count > 0)162 points.RemoveAt(points.Count - 1);163 points.ResumeUpdates();164 }165 166 127 #endregion 167 128 }
Note: See TracChangeset
for help on using the changeset viewer.