- Timestamp:
- 02/20/12 09:39:00 (13 years ago)
- Location:
- branches/RegressionBenchmarks/HeuristicLab.Problems.DataAnalysis.Views/3.4
- Files:
-
- 1 deleted
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/RegressionBenchmarks/HeuristicLab.Problems.DataAnalysis.Views/3.4/HeuristicLab.Problems.DataAnalysis.Views-3.4.csproj
r7308 r7485 353 353 <DependentUpon>DataAnalysisProblemView.cs</DependentUpon> 354 354 </EmbeddedResource> 355 <EmbeddedResource Include="Regression\RegressionSolutionResidualHistogram.resx">356 <DependentUpon>RegressionSolutionResidualHistogram.cs</DependentUpon>357 </EmbeddedResource>358 355 </ItemGroup> 359 356 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> -
branches/RegressionBenchmarks/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionResidualHistogram.cs
r7255 r7485 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 1Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 33 33 [Content(typeof(IRegressionSolution))] 34 34 public partial class RegressionSolutionResidualHistogram : DataAnalysisSolutionEvaluationView { 35 36 #region variables 35 37 protected const string ALL_SAMPLES = "All samples"; 36 38 protected const string TRAINING_SAMPLES = "Training samples"; 37 39 protected const string TEST_SAMPLES = "Test samples"; 38 39 //to reduce code duplication 40 /// <summary> 41 /// used to reduce code duplication 42 /// </summary> 40 43 protected static string[] ALL_SERIES = new string[] { ALL_SAMPLES, TRAINING_SAMPLES, TEST_SAMPLES }; 41 42 //approximate amount of bins 44 /// <summary> 45 /// approximate amount of bins 46 /// </summary> 43 47 protected const double bins = 25; 44 45 /* 46 * keeps for all series a list for all bins with the position of the bin, the relative frequency of the 47 * residuals and the beginning and the end of the interval of the bin 48 */ 48 /// <summary> 49 /// keeps for all series a list for every bin with the position of the bin, the relative frequency of the 50 /// residuals and the beginning and the end of the interval of the bin 51 /// </summary> 49 52 protected Dictionary<string, List<List<double>>> relativeFrequencies; 53 #endregion 50 54 51 55 public new IRegressionSolution Content { … … 57 61 : base() { 58 62 InitializeComponent(); 59 60 63 relativeFrequencies = new Dictionary<string, List<List<double>>>(); 61 62 64 foreach (string series in ALL_SERIES) { 63 this.chart.Series.Add(series); 64 this.chart.Series[series].LegendText = series; 65 this.chart.Series[series].ChartType = SeriesChartType.Column; 66 this.chart.Series[series]["PointWidth"] = "0.9"; 67 this.chart.Series[series].BorderWidth = 1; 68 this.chart.Series[series].BorderDashStyle = ChartDashStyle.Solid; 69 this.chart.Series[series].BorderColor = Color.Black; 70 this.chart.Series[series].ToolTip = series + " Y = #VALY from #CUSTOMPROPERTY(from) to #CUSTOMPROPERTY(to)"; 71 65 chart.Series.Add(series); 66 chart.Series[series].LegendText = series; 67 chart.Series[series].ChartType = SeriesChartType.Column; 68 chart.Series[series]["PointWidth"] = "0.9"; 69 chart.Series[series].BorderWidth = 1; 70 chart.Series[series].BorderDashStyle = ChartDashStyle.Solid; 71 chart.Series[series].BorderColor = Color.Black; 72 chart.Series[series].ToolTip = series + " Y = #VALY from #CUSTOMPROPERTY(from) to #CUSTOMPROPERTY(to)"; 72 73 relativeFrequencies[series] = new List<List<double>>(); 73 74 } 74 75 75 //configure axis 76 this.chart.CustomizeAllChartAreas(); 77 this.chart.ChartAreas[0].AxisX.Title = "Residuals"; 78 this.chart.ChartAreas[0].CursorX.IsUserSelectionEnabled = true; 79 this.chart.ChartAreas[0].AxisX.ScaleView.Zoomable = true; 80 this.chart.ChartAreas[0].CursorX.Interval = 1; 81 this.chart.ChartAreas[0].CursorY.Interval = 1; 82 83 this.chart.ChartAreas[0].AxisY.Title = "Relative Frequency"; 84 this.chart.ChartAreas[0].CursorY.IsUserSelectionEnabled = true; 85 this.chart.ChartAreas[0].AxisY.ScaleView.Zoomable = true; 86 this.chart.ChartAreas[0].AxisY.IsStartedFromZero = true; 76 chart.CustomizeAllChartAreas(); 77 chart.ChartAreas[0].AxisX.Title = "Residuals"; 78 chart.ChartAreas[0].CursorX.IsUserSelectionEnabled = true; 79 chart.ChartAreas[0].AxisX.ScaleView.Zoomable = true; 80 chart.ChartAreas[0].CursorX.Interval = 1; 81 chart.ChartAreas[0].CursorY.Interval = 1; 82 chart.ChartAreas[0].AxisY.Title = "Relative Frequency"; 83 chart.ChartAreas[0].CursorY.IsUserSelectionEnabled = true; 84 chart.ChartAreas[0].AxisY.ScaleView.Zoomable = true; 85 chart.ChartAreas[0].AxisY.IsStartedFromZero = true; 87 86 } 88 87 89 88 private void RedrawChart() { 90 91 89 foreach (string series in ALL_SERIES) { 92 this.chart.Series[series].Points.Clear(); 93 this.relativeFrequencies[series].Clear(); 94 } 95 90 chart.Series[series].Points.Clear(); 91 relativeFrequencies[series].Clear(); 92 } 96 93 if (Content != null) { 97 98 94 Dictionary<string, List<double>> residuals = CalculateResiduals(); 99 100 95 double max = Math.Max(Math.Abs(residuals[ALL_SAMPLES].Min()), Math.Abs(residuals[ALL_SAMPLES].Max())); 101 96 double intervalWidth = (max * 2.0) / bins; 102 103 97 max = HumanRoundMax(max); 104 98 intervalWidth = HumanRoundMax(intervalWidth); … … 106 100 foreach (string series in ALL_SERIES) { 107 101 CalculateFrequencies(residuals[series], series, max, intervalWidth); 102 if (!series.Equals(ALL_SAMPLES)) 103 ShowValues(chart.Series[series], relativeFrequencies[series]); 108 104 } 109 105 110 106 ChartArea chartArea = chart.ChartAreas[0]; 111 112 107 chartArea.AxisX.Minimum = -max - intervalWidth; 113 108 chartArea.AxisX.Maximum = max + intervalWidth; 114 109 chartArea.AxisY.Maximum = relativeFrequencies[ALL_SAMPLES].Select(x => x.ElementAt(1)).Max() + 0.02; 115 110 chartArea.AxisY.Interval = 0.1; 116 117 111 chartArea.AxisX.Interval = intervalWidth; 118 112 int curBins = (int)Math.Round(max / intervalWidth); … … 131 125 residuals[series] = new List<double>(); 132 126 } 133 134 127 IRegressionProblemData problemdata = Content.ProblemData; 135 128 List<double> targetValues = problemdata.Dataset.GetDoubleValues(Content.ProblemData.TargetVariable).ToList(); … … 144 137 residuals[TEST_SAMPLES].Add(residual); 145 138 } 146 147 139 return residuals; 148 140 } 149 141 150 142 private void CalculateFrequencies(List<double> residualValues, string series, double max, double intervalWidth) { 151 Series residualSeries = this.chart.Series[series]; 152 143 //Series residualSeries = chart.Series[series]; 153 144 double intervalCenter = intervalWidth / 2.0; 154 145 double sampleCount = residualValues.Count(); … … 160 151 current += intervalWidth; 161 152 } 162 163 ShowValues(residualSeries, relativeFrequencies[series]); 164 } 165 166 private void ToggleSeriesData(Series series) { 167 if (series.Points.Count > 0) { //checks if series is shown 168 if (this.chart.Series.Any(s => s != series && s.Points.Count > 0)) { 169 series.Points.Clear(); 170 } 171 } else if (Content != null) { 172 ShowValues(series, relativeFrequencies[series.Name]); 173 chart.Legends[series.Legend].ForeColor = Color.Black; 174 chart.Refresh(); 175 } 176 } 177 178 private void ShowValues(Series series, List<List<double>> relativeSeriesFrequencies) { 179 DataPointCollection seriesPoints = series.Points; 180 181 foreach (var valueList in relativeSeriesFrequencies) { 182 seriesPoints.AddXY(valueList[0], valueList[1]); 183 seriesPoints[seriesPoints.Count - 1]["from"] = valueList[2].ToString(); 184 seriesPoints[seriesPoints.Count - 1]["to"] = valueList[3].ToString(); 185 } 153 //ShowValues(residualSeries, relativeFrequencies[series]); 186 154 } 187 155 … … 217 185 RedrawChart(); 218 186 } 219 220 187 private void chart_MouseDown(object sender, MouseEventArgs e) { 221 188 HitTestResult result = chart.HitTest(e.X, e.Y); … … 233 200 private void chart_CustomizeLegend(object sender, CustomizeLegendEventArgs e) { 234 201 if (chart.Series.Count != 3) return; 235 e.LegendItems[0].Cells[1].ForeColor = this.chart.Series[ALL_SAMPLES].Points.Count == 0 ? Color.Gray : Color.Black;236 e.LegendItems[1].Cells[1].ForeColor = this.chart.Series[TRAINING_SAMPLES].Points.Count == 0 ? Color.Gray : Color.Black;237 e.LegendItems[2].Cells[1].ForeColor = this.chart.Series[TEST_SAMPLES].Points.Count == 0 ? Color.Gray : Color.Black;202 e.LegendItems[0].Cells[1].ForeColor = chart.Series[ALL_SAMPLES].Points.Count == 0 ? Color.Gray : Color.Black; 203 e.LegendItems[1].Cells[1].ForeColor = chart.Series[TRAINING_SAMPLES].Points.Count == 0 ? Color.Gray : Color.Black; 204 e.LegendItems[2].Cells[1].ForeColor = chart.Series[TEST_SAMPLES].Points.Count == 0 ? Color.Gray : Color.Black; 238 205 } 239 206 #endregion 207 208 private void ToggleSeriesData(Series series) { 209 if (series.Points.Count > 0) { //checks if series is shown 210 if (chart.Series.Any(s => s != series && s.Points.Count > 0)) { 211 series.Points.Clear(); 212 } 213 } else if (Content != null) { 214 ShowValues(series, relativeFrequencies[series.Name]); 215 chart.Legends[series.Legend].ForeColor = Color.Black; 216 chart.Refresh(); 217 } 218 } 219 private void ShowValues(Series series, List<List<double>> relativeSeriesFrequencies) { 220 DataPointCollection seriesPoints = series.Points; 221 222 foreach (var valueList in relativeSeriesFrequencies) { 223 seriesPoints.AddXY(valueList[0], valueList[1]); 224 seriesPoints[seriesPoints.Count - 1]["from"] = valueList[2].ToString(); 225 seriesPoints[seriesPoints.Count - 1]["to"] = valueList[3].ToString(); 226 } 227 } 240 228 } 241 229 }
Note: See TracChangeset
for help on using the changeset viewer.