Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/22/15 20:47:33 (9 years ago)
Author:
gkronber
Message:

#2369: added support for squared errors and relative errors to error-characteristic-curve view

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

    r12012 r12493  
    4646    private void InitializeComponent() {
    4747      this.components = new System.ComponentModel.Container();
    48       System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
    49       System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend();
     48      System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea2 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
     49      System.Windows.Forms.DataVisualization.Charting.Legend legend2 = new System.Windows.Forms.DataVisualization.Charting.Legend();
    5050      this.chart = new HeuristicLab.Visualization.ChartControlsExtensions.EnhancedChart();
    5151      this.label1 = new System.Windows.Forms.Label();
    5252      this.cmbSamples = new System.Windows.Forms.ComboBox();
     53      this.residualComboBox = new System.Windows.Forms.ComboBox();
    5354      ((System.ComponentModel.ISupportInitialize)(this.chart)).BeginInit();
    5455      this.SuspendLayout();
     
    5657      // chart
    5758      //
    58       this.chart.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    59                   | System.Windows.Forms.AnchorStyles.Left)
    60                   | System.Windows.Forms.AnchorStyles.Right)));
    61       chartArea1.Name = "ChartArea1";
    62       this.chart.ChartAreas.Add(chartArea1);
    63       legend1.Alignment = System.Drawing.StringAlignment.Center;
    64       legend1.Docking = System.Windows.Forms.DataVisualization.Charting.Docking.Top;
    65       legend1.Name = "Legend1";
    66       this.chart.Legends.Add(legend1);
     59      this.chart.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
     60            | System.Windows.Forms.AnchorStyles.Left)
     61            | System.Windows.Forms.AnchorStyles.Right)));
     62      chartArea2.Name = "ChartArea1";
     63      this.chart.ChartAreas.Add(chartArea2);
     64      legend2.Alignment = System.Drawing.StringAlignment.Center;
     65      legend2.Docking = System.Windows.Forms.DataVisualization.Charting.Docking.Top;
     66      legend2.Name = "Legend1";
     67      this.chart.Legends.Add(legend2);
    6768      this.chart.Location = new System.Drawing.Point(6, 28);
    6869      this.chart.Name = "chart";
     
    9293      this.cmbSamples.SelectedIndexChanged += new System.EventHandler(this.cmbSamples_SelectedIndexChanged);
    9394      //
     95      // residualComboBox
     96      //
     97      this.residualComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
     98      this.residualComboBox.FormattingEnabled = true;
     99      this.residualComboBox.Items.AddRange(new object[] {
     100            "Absolute error",
     101            "Squared error",
     102            "Relative error"});
     103      this.residualComboBox.Location = new System.Drawing.Point(183, 3);
     104      this.residualComboBox.Name = "residualComboBox";
     105      this.residualComboBox.Size = new System.Drawing.Size(121, 21);
     106      this.residualComboBox.TabIndex = 5;
     107      this.residualComboBox.SelectedIndexChanged += new System.EventHandler(this.residualComboBox_SelectedIndexChanged);
     108      //
    94109      // RegressionSolutionErrorCharacteristicsCurveView
    95110      //
    96111      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
     112      this.Controls.Add(this.residualComboBox);
    97113      this.Controls.Add(this.label1);
    98114      this.Controls.Add(this.cmbSamples);
     
    111127    protected System.Windows.Forms.Label label1;
    112128    protected System.Windows.Forms.ComboBox cmbSamples;
     129    protected System.Windows.Forms.ComboBox residualComboBox;
    113130  }
    114131}
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionErrorCharacteristicsCurveView.cs

    r12365 r12493  
    2525using System.Windows.Forms;
    2626using System.Windows.Forms.DataVisualization.Charting;
     27using HeuristicLab.Common;
    2728using HeuristicLab.MainForm;
    2829
     
    4546      cmbSamples.SelectedIndex = 0;
    4647
     48      residualComboBox.SelectedIndex = 0;
     49
    4750      chart.CustomizeAllChartAreas();
    48       chart.ChartAreas[0].AxisX.Title = "Absolute Error";
     51      chart.ChartAreas[0].AxisX.Title = residualComboBox.SelectedItem.ToString();
    4952      chart.ChartAreas[0].AxisX.Minimum = 0.0;
    5053      chart.ChartAreas[0].AxisX.Maximum = 0.0;
     
    109112
    110113      AddRegressionSolution(Content);
     114
     115      chart.ChartAreas[0].AxisX.Title = residualComboBox.SelectedItem.ToString();
    111116    }
    112117
     
    119124      var residuals = GetResiduals(GetOriginalValues(), GetEstimatedValues(solution));
    120125
    121 
    122126      var maxValue = residuals.Max();
    123       if (maxValue >= chart.ChartAreas[0].AxisX.Maximum) {
    124         double scale = Math.Pow(10, Math.Floor(Math.Log10(maxValue)));
    125         var maximum = scale * (1 + (int)(maxValue / scale));
    126         chart.ChartAreas[0].AxisX.Maximum = maximum;
    127       }
     127      double scale = Math.Pow(10, Math.Floor(Math.Log10(maxValue)));
     128      var maximum = scale * (1 + (int)(maxValue / scale));
     129      chart.ChartAreas[0].AxisX.Maximum = maximum;
    128130      chart.ChartAreas[0].CursorX.Interval = residuals.Min() / 100;
    129131
     
    203205
    204206    protected virtual List<double> GetResiduals(IEnumerable<double> originalValues, IEnumerable<double> estimatedValues) {
    205       return originalValues.Zip(estimatedValues, (x, y) => Math.Abs(x - y)).ToList();
     207      switch (residualComboBox.SelectedItem.ToString()) {
     208        case "Absolute error": return originalValues.Zip(estimatedValues, (x, y) => Math.Abs(x - y)).ToList();
     209        case "Squared error": return originalValues.Zip(estimatedValues, (x, y) => (x - y) * (x - y)).ToList();
     210        case "Relative error": return originalValues.Zip(estimatedValues, (x, y) => x.IsAlmost(0.0) ? -1 : Math.Abs((x - y) / x))
     211          .Where(x => x > 0) // remove entries where the original value is 0
     212          .ToList();
     213      }
     214      // should never happen
     215      return new List<double>();
    206216    }
    207217
     
    251261      }
    252262    }
     263
     264    private void residualComboBox_SelectedIndexChanged(object sender, EventArgs e) {
     265      UpdateChart();
     266    }
    253267  }
    254268}
Note: See TracChangeset for help on using the changeset viewer.