Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/20/12 09:39:00 (13 years ago)
Author:
sforsten
Message:

#1708:

  • changes according to mkommend's reviewing comments have been made
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  
    353353      <DependentUpon>DataAnalysisProblemView.cs</DependentUpon>
    354354    </EmbeddedResource>
    355     <EmbeddedResource Include="Regression\RegressionSolutionResidualHistogram.resx">
    356       <DependentUpon>RegressionSolutionResidualHistogram.cs</DependentUpon>
    357     </EmbeddedResource>
    358355  </ItemGroup>
    359356  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  • branches/RegressionBenchmarks/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionResidualHistogram.cs

    r7255 r7485  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    3333  [Content(typeof(IRegressionSolution))]
    3434  public partial class RegressionSolutionResidualHistogram : DataAnalysisSolutionEvaluationView {
     35
     36    #region variables
    3537    protected const string ALL_SAMPLES = "All samples";
    3638    protected const string TRAINING_SAMPLES = "Training samples";
    3739    protected const string TEST_SAMPLES = "Test samples";
    38 
    39     //to reduce code duplication
     40    /// <summary>
     41    /// used to reduce code duplication
     42    /// </summary>
    4043    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>
    4347    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>
    4952    protected Dictionary<string, List<List<double>>> relativeFrequencies;
     53    #endregion
    5054
    5155    public new IRegressionSolution Content {
     
    5761      : base() {
    5862      InitializeComponent();
    59 
    6063      relativeFrequencies = new Dictionary<string, List<List<double>>>();
    61 
    6264      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)";
    7273        relativeFrequencies[series] = new List<List<double>>();
    7374      }
    74 
    7575      //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;
    8786    }
    8887
    8988    private void RedrawChart() {
    90 
    9189      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      }
    9693      if (Content != null) {
    97 
    9894        Dictionary<string, List<double>> residuals = CalculateResiduals();
    99 
    10095        double max = Math.Max(Math.Abs(residuals[ALL_SAMPLES].Min()), Math.Abs(residuals[ALL_SAMPLES].Max()));
    10196        double intervalWidth = (max * 2.0) / bins;
    102 
    10397        max = HumanRoundMax(max);
    10498        intervalWidth = HumanRoundMax(intervalWidth);
     
    106100        foreach (string series in ALL_SERIES) {
    107101          CalculateFrequencies(residuals[series], series, max, intervalWidth);
     102          if (!series.Equals(ALL_SAMPLES))
     103            ShowValues(chart.Series[series], relativeFrequencies[series]);
    108104        }
    109105
    110106        ChartArea chartArea = chart.ChartAreas[0];
    111 
    112107        chartArea.AxisX.Minimum = -max - intervalWidth;
    113108        chartArea.AxisX.Maximum = max + intervalWidth;
    114109        chartArea.AxisY.Maximum = relativeFrequencies[ALL_SAMPLES].Select(x => x.ElementAt(1)).Max() + 0.02;
    115110        chartArea.AxisY.Interval = 0.1;
    116 
    117111        chartArea.AxisX.Interval = intervalWidth;
    118112        int curBins = (int)Math.Round(max / intervalWidth);
     
    131125        residuals[series] = new List<double>();
    132126      }
    133 
    134127      IRegressionProblemData problemdata = Content.ProblemData;
    135128      List<double> targetValues = problemdata.Dataset.GetDoubleValues(Content.ProblemData.TargetVariable).ToList();
     
    144137          residuals[TEST_SAMPLES].Add(residual);
    145138      }
    146 
    147139      return residuals;
    148140    }
    149141
    150142    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];
    153144      double intervalCenter = intervalWidth / 2.0;
    154145      double sampleCount = residualValues.Count();
     
    160151        current += intervalWidth;
    161152      }
    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]);
    186154    }
    187155
     
    217185      RedrawChart();
    218186    }
    219 
    220187    private void chart_MouseDown(object sender, MouseEventArgs e) {
    221188      HitTestResult result = chart.HitTest(e.X, e.Y);
     
    233200    private void chart_CustomizeLegend(object sender, CustomizeLegendEventArgs e) {
    234201      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;
    238205    }
    239206    #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    }
    240228  }
    241229}
Note: See TracChangeset for help on using the changeset viewer.