Changeset 7700 for trunk/sources
- Timestamp:
- 04/03/12 14:32:24 (13 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionErrorCharacteristicsCurveView.Designer.cs
r7043 r7700 49 49 this.chart.TabIndex = 0; 50 50 this.chart.Text = "chart"; 51 this.chart.CustomizeLegend += new System.EventHandler<System.Windows.Forms.DataVisualization.Charting.CustomizeLegendEventArgs>(this.chart_CustomizeLegend); 52 this.chart.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.Chart_MouseDoubleClick); 53 this.chart.MouseMove += new System.Windows.Forms.MouseEventHandler(this.chart_MouseMove); 51 54 this.chart.MouseDown += new System.Windows.Forms.MouseEventHandler(this.chart_MouseDown); 52 55 // -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionErrorCharacteristicsCurveView.cs
r7259 r7700 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Drawing; 24 25 using System.Linq; 25 26 using System.Windows.Forms; … … 36 37 protected const string AllSamples = "All Samples"; 37 38 39 protected Dictionary<string, List<double>> seriesResiduals = new Dictionary<string, List<double>>(); 40 38 41 public RegressionSolutionErrorCharacteristicsCurveView() 39 42 : base() { … … 99 102 protected virtual void UpdateChart() { 100 103 chart.Series.Clear(); 104 seriesResiduals.Clear(); 101 105 chart.Annotations.Clear(); 102 106 if (Content == null) return; … … 104 108 var originalValues = GetOriginalValues().ToList(); 105 109 constantModel = CreateConstantModel(); 106 var meanModelEstimatedValues = GetEstimatedValues(constantModel); 107 var meanModelResiduals = GetResiduals(originalValues, meanModelEstimatedValues); 108 109 meanModelResiduals.Sort(); 110 chart.ChartAreas[0].AxisX.Maximum = Math.Ceiling(meanModelResiduals.Last()); 111 chart.ChartAreas[0].CursorX.Interval = meanModelResiduals.First() / 100; 112 113 Series meanModelSeries = new Series("Mean Model"); 114 meanModelSeries.ChartType = SeriesChartType.FastLine; 115 UpdateSeries(meanModelResiduals, meanModelSeries); 116 meanModelSeries.ToolTip = "Area over Curve: " + CalculateAreaOverCurve(meanModelSeries); 117 meanModelSeries.Tag = constantModel; 118 chart.Series.Add(meanModelSeries); 110 var baselineEstimatedValues = GetEstimatedValues(constantModel); 111 var baselineResiduals = GetResiduals(originalValues, baselineEstimatedValues); 112 113 baselineResiduals.Sort(); 114 chart.ChartAreas[0].AxisX.Maximum = Math.Ceiling(baselineResiduals.Last()); 115 chart.ChartAreas[0].CursorX.Interval = baselineResiduals.First() / 100; 116 117 Series baselineSeries = new Series("Baseline"); 118 baselineSeries.ChartType = SeriesChartType.FastLine; 119 seriesResiduals[baselineSeries.Name] = baselineResiduals; 120 UpdateSeries(baselineResiduals, baselineSeries); 121 baselineSeries.ToolTip = "Area over Curve: " + CalculateAreaOverCurve(baselineSeries); 122 baselineSeries.Tag = constantModel; 123 chart.Series.Add(baselineSeries); 119 124 120 125 AddRegressionSolution(Content); … … 128 133 solutionSeries.ChartType = SeriesChartType.FastLine; 129 134 var estimatedValues = GetResiduals(GetOriginalValues(), GetEstimatedValues(solution)); 135 seriesResiduals[solutionSeries.Name] = estimatedValues; 130 136 UpdateSeries(estimatedValues, solutionSeries); 131 137 solutionSeries.ToolTip = "Area over Curve: " + CalculateAreaOverCurve(solutionSeries); … … 200 206 } 201 207 202 protected IEnumerable<double> Get MeanModelEstimatedValues(IEnumerable<double> originalValues) {208 protected IEnumerable<double> GetbaselineEstimatedValues(IEnumerable<double> originalValues) { 203 209 double averageTrainingTarget = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndizes).Average(); 204 210 return Enumerable.Repeat(averageTrainingTarget, originalValues.Count()); … … 229 235 } 230 236 231 #region Mean Model 232 private void chart_MouseDown(object sender, MouseEventArgs e) { 233 if (e.Clicks < 2) return; 237 #region events 238 private void Chart_MouseDoubleClick(object sender, MouseEventArgs e) { 234 239 HitTestResult result = chart.HitTest(e.X, e.Y); 235 240 if (result.ChartElementType != ChartElementType.LegendItem) return; … … 238 243 MainFormManager.MainForm.ShowContent((IRegressionSolution)result.Series.Tag); 239 244 } 245 private void chart_MouseMove(object sender, MouseEventArgs e) { 246 HitTestResult result = chart.HitTest(e.X, e.Y); 247 if (result.ChartElementType == ChartElementType.LegendItem) 248 Cursor = Cursors.Hand; 249 else 250 Cursor = Cursors.Default; 251 } 252 private void chart_MouseDown(object sender, MouseEventArgs e) { 253 HitTestResult result = chart.HitTest(e.X, e.Y); 254 if (result.ChartElementType == ChartElementType.LegendItem) { 255 ToggleSeriesData(result.Series); 256 } 257 } 258 private void chart_CustomizeLegend(object sender, CustomizeLegendEventArgs e) { 259 foreach (LegendItem legend in e.LegendItems) { 260 legend.Cells[1].ForeColor = this.chart.Series[legend.SeriesName].Points.Count == 0 ? Color.Gray : Color.Black; 261 } 262 } 263 #endregion 240 264 241 265 private IRegressionSolution CreateConstantModel() { 242 266 double averageTrainingTarget = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndizes).Average(); 243 267 var solution = new ConstantRegressionModel(averageTrainingTarget).CreateRegressionSolution(ProblemData); 244 solution.Name = " Mean Model";268 solution.Name = "Baseline"; 245 269 return solution; 246 270 } 247 #endregion 271 272 private void ToggleSeriesData(Series series) { 273 if (series.Points.Count > 0) { //checks if series is shown 274 if (this.chart.Series.Any(s => s != series && s.Points.Count > 0)) { 275 ClearPointsQuick(series.Points); 276 } 277 } else if (Content != null) { 278 List<double> residuals; 279 if (seriesResiduals.TryGetValue(series.Name, out residuals)) { 280 UpdateSeries(residuals, series); 281 chart.Legends[series.Legend].ForeColor = Color.Black; 282 chart.Refresh(); 283 } 284 } 285 } 286 287 // workaround as per http://stackoverflow.com/questions/5744930/datapointcollection-clear-performance 288 private static void ClearPointsQuick(DataPointCollection points) { 289 points.SuspendUpdates(); 290 while (points.Count > 0) 291 points.RemoveAt(points.Count - 1); 292 points.ResumeUpdates(); 293 } 248 294 } 249 295 }
Note: See TracChangeset
for help on using the changeset viewer.