Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/25/12 15:05:28 (12 years ago)
Author:
sforsten
Message:

#1708:

  • Removed ALL_SERIES constant
  • Reordered methods
  • CalculateResiduals returns now all residuals instead of a dictionary
  • reduced number of parameters for methods were possible
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/RegressionSolutionResidualHistogram.Designer.cs

    r7967 r8104  
    4141      this.chart.Location = new System.Drawing.Point(0, 0);
    4242      this.chart.Name = "chart";
    43       this.chart.Size = new System.Drawing.Size(358, 225);
     43      this.chart.Size = new System.Drawing.Size(289, 220);
    4444      this.chart.TabIndex = 0;
    4545      this.chart.CustomizeLegend += new System.EventHandler<System.Windows.Forms.DataVisualization.Charting.CustomizeLegendEventArgs>(this.chart_CustomizeLegend);
     
    5050      //
    5151      this.AllowDrop = true;
    52       this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    5352      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
    5453      this.Controls.Add(this.chart);
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionResidualHistogram.cs

    r8098 r8104  
    3838    protected const string TRAINING_SAMPLES = "Training samples";
    3939    protected const string TEST_SAMPLES = "Test samples";
    40     /// <summary>
    41     /// used to reduce code duplication
    42     /// </summary>
    43     protected readonly string[] ALL_SERIES = new string[] { ALL_SAMPLES, TRAINING_SAMPLES, TEST_SAMPLES };
    4440    /// <summary>
    4541    /// approximate amount of bins
     
    6258      InitializeComponent();
    6359      relativeFrequencies = new Dictionary<string, List<List<double>>>();
    64       foreach (string series in ALL_SERIES) {
     60      foreach (string series in new List<String>() { ALL_SAMPLES, TRAINING_SAMPLES, TEST_SAMPLES }) {
    6561        chart.Series.Add(series);
    6662        chart.Series[series].LegendText = series;
     
    8783
    8884    private void RedrawChart() {
    89       foreach (string series in ALL_SERIES) {
    90         chart.Series[series].Points.Clear();
    91         relativeFrequencies[series].Clear();
     85      foreach (Series series in chart.Series) {
     86        series.Points.Clear();
     87        relativeFrequencies[series.Name].Clear();
    9288      }
    9389      if (Content != null) {
    94         Dictionary<string, List<double>> residuals = CalculateResiduals();
    95         double realMax = Math.Max(Math.Abs(residuals[ALL_SAMPLES].Min()), Math.Abs(residuals[ALL_SAMPLES].Max()));
     90        List<double> residuals = CalculateResiduals();
     91        double realMax = Math.Max(Math.Abs(residuals.Min()), Math.Abs(residuals.Max()));
    9692        double roundedMax = HumanRoundMax(realMax);
    9793        double intervalWidth = (roundedMax * 2.0) / bins;
     
    10298        roundedMax = help * intervalWidth;
    10399
    104         foreach (string series in ALL_SERIES) {
    105           CalculateFrequencies(residuals[series], series, roundedMax, intervalWidth);
     100        foreach (Series series in chart.Series) {
     101          CalculateFrequencies(residuals, series.Name, roundedMax, intervalWidth);
    106102          if (!series.Equals(ALL_SAMPLES))
    107             ShowValues(chart.Series[series], relativeFrequencies[series]);
     103            ShowValues(series);
    108104        }
    109105
     
    132128    }
    133129
    134     private Dictionary<string, List<double>> CalculateResiduals() {
    135       Dictionary<string, List<double>> residuals = new Dictionary<string, List<double>>();
    136 
    137       foreach (string series in ALL_SERIES) {
    138         residuals[series] = new List<double>();
    139       }
     130    private List<double> CalculateResiduals() {
     131      List<double> residuals = new List<double>();
     132
    140133      IRegressionProblemData problemdata = Content.ProblemData;
    141134      List<double> targetValues = problemdata.Dataset.GetDoubleValues(Content.ProblemData.TargetVariable).ToList();
     
    144137      for (int i = 0; i < Content.ProblemData.Dataset.Rows; i++) {
    145138        double residual = estimatedValues[i] - targetValues[i];
    146         residuals[ALL_SAMPLES].Add(residual);
    147         if (i >= problemdata.TrainingPartition.Start && i < problemdata.TrainingPartition.End)
    148           residuals[TRAINING_SAMPLES].Add(residual);
    149         if (i >= problemdata.TestPartition.Start && i < problemdata.TestPartition.End)
    150           residuals[TEST_SAMPLES].Add(residual);
     139        residuals.Add(residual);
    151140      }
    152141      return residuals;
     
    154143
    155144    private void CalculateFrequencies(List<double> residualValues, string series, double max, double intervalWidth) {
     145      IEnumerable<double> relevantResiduals = residualValues;
     146      IRegressionProblemData problemdata = Content.ProblemData;
     147      if (series.Equals(TRAINING_SAMPLES)) {
     148        relevantResiduals = residualValues.Skip(problemdata.TrainingPartition.Start).Take(problemdata.TrainingPartition.Size);
     149      } else if (series.Equals(TEST_SAMPLES)) {
     150        relevantResiduals = residualValues.Skip(problemdata.TestPartition.Start).Take(problemdata.TestPartition.Size);
     151      }
     152
    156153      double intervalCenter = intervalWidth / 2.0;
    157       double sampleCount = residualValues.Count;
     154      double sampleCount = relevantResiduals.Count();
    158155      double current = -max;
    159156
    160157      for (int i = 0; i <= bins; i++) {
    161         IEnumerable<double> help = residualValues.Where(x => x >= (current - intervalCenter) && x < (current + intervalCenter));
     158        IEnumerable<double> help = relevantResiduals.Where(x => x >= (current - intervalCenter) && x < (current + intervalCenter));
    162159        relativeFrequencies[series].Add(new List<double>() { current, help.Count() / sampleCount, current - intervalCenter, current + intervalCenter });
    163160        current += intervalWidth;
     161      }
     162    }
     163
     164    private void ShowValues(Series series) {
     165      List<List<double>> relativeSeriesFrequencies = relativeFrequencies[series.Name];
     166      DataPointCollection seriesPoints = series.Points;
     167
     168      foreach (var valueList in relativeSeriesFrequencies) {
     169        seriesPoints.AddXY(valueList[0], valueList[1]);
     170        seriesPoints[seriesPoints.Count - 1]["from"] = valueList[2].ToString();
     171        seriesPoints[seriesPoints.Count - 1]["to"] = valueList[3].ToString();
     172      }
     173    }
     174
     175    private void ToggleSeriesData(Series series) {
     176      if (series.Points.Count > 0) {  //checks if series is shown
     177        if (chart.Series.Any(s => s != series && s.Points.Count > 0)) {
     178          series.Points.Clear();
     179        }
     180      } else if (Content != null) {
     181        ShowValues(series);
     182        chart.Legends[series.Legend].ForeColor = Color.Black;
     183        chart.Refresh();
    164184      }
    165185    }
     
    216236    }
    217237    #endregion
    218 
    219     private void ToggleSeriesData(Series series) {
    220       if (series.Points.Count > 0) {  //checks if series is shown
    221         if (chart.Series.Any(s => s != series && s.Points.Count > 0)) {
    222           series.Points.Clear();
    223         }
    224       } else if (Content != null) {
    225         ShowValues(series, relativeFrequencies[series.Name]);
    226         chart.Legends[series.Legend].ForeColor = Color.Black;
    227         chart.Refresh();
    228       }
    229     }
    230     private void ShowValues(Series series, List<List<double>> relativeSeriesFrequencies) {
    231       DataPointCollection seriesPoints = series.Points;
    232 
    233       foreach (var valueList in relativeSeriesFrequencies) {
    234         seriesPoints.AddXY(valueList[0], valueList[1]);
    235         seriesPoints[seriesPoints.Count - 1]["from"] = valueList[2].ToString();
    236         seriesPoints[seriesPoints.Count - 1]["to"] = valueList[3].ToString();
    237       }
    238     }
    239238  }
    240239}
Note: See TracChangeset for help on using the changeset viewer.