Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/02/12 11:40:31 (13 years ago)
Author:
sforsten
Message:

#1708: merged r7209 from trunk

  • adjusted GUI
  • added toggle for the different series
  • X Axis labels are rounded to useful values
  • added ToolTip
Location:
branches/RegressionBenchmarks
Files:
3 deleted
5 edited

Legend:

Unmodified
Added
Removed
  • branches/RegressionBenchmarks

  • branches/RegressionBenchmarks/HeuristicLab.Problems.DataAnalysis.Views/3.4/DataAnalysisProblemView.cs

    r7127 r7255  
    7878      else if (Content is IClassificationProblem)
    7979        return ApplicationManager.Manager.GetInstances<IClassificationBenchmarkProblemDataGenerator>();
    80       else if (Content is ITimeSeriesPrognosisProblem)
    81         return ApplicationManager.Manager.GetInstances<ITimeSeriesBenchmarkProblemDataGenerator>();
    8280      else if (Content is IClusteringProblem)
    8381        return ApplicationManager.Manager.GetInstances<IClusteringBenchmarkProblemDataGenerator>();
  • branches/RegressionBenchmarks/HeuristicLab.Problems.DataAnalysis.Views/3.4/HeuristicLab.Problems.DataAnalysis.Views-3.4.csproj

    r6968 r7255  
    123123      <DependentUpon>ClassificationEnsembleSolutionModelView.cs</DependentUpon>
    124124    </Compile>
    125     <Compile Include="Plugin.cs" />
    126     <Compile Include="Solution Views\TimeSeriesPrognosisSolutionView.cs">
    127       <SubType>UserControl</SubType>
    128     </Compile>
    129     <Compile Include="Solution Views\TimeSeriesPrognosisSolutionView.Designer.cs">
    130       <DependentUpon>TimeSeriesPrognosisSolutionView.cs</DependentUpon>
    131     </Compile>
    132     <Compile Include="TimeSeriesPrognosis\TimeSeriesPrognosisSolutionErrorCharacteristicsCurveView.cs">
    133       <SubType>UserControl</SubType>
    134     </Compile>
    135     <Compile Include="TimeSeriesPrognosis\TimeSeriesPrognosisSolutionErrorCharacteristicsCurveView.Designer.cs">
    136       <DependentUpon>TimeSeriesPrognosisSolutionErrorCharacteristicsCurveView.cs</DependentUpon>
    137     </Compile>
    138     <Compile Include="TimeSeriesPrognosis\TimeSeriesPrognosisSolutionLineChartView.cs">
    139       <SubType>UserControl</SubType>
    140     </Compile>
    141     <Compile Include="TimeSeriesPrognosis\TimeSeriesPrognosisSolutionLineChartView.Designer.cs">
    142       <DependentUpon>TimeSeriesPrognosisSolutionLineChartView.cs</DependentUpon>
    143     </Compile>
    144     <Compile Include="TimeSeriesPrognosis\TimeSeriesPrognosisSolutionPrognosedValuesView.cs">
    145       <SubType>UserControl</SubType>
    146     </Compile>
    147     <Compile Include="TimeSeriesPrognosis\TimeSeriesPrognosisSolutionPrognosedValuesView.Designer.cs">
    148       <DependentUpon>TimeSeriesPrognosisSolutionPrognosedValuesView.cs</DependentUpon>
    149     </Compile>
    150     <Compile Include="TimeSeriesPrognosis\TimeSeriesPrognosisSolutionScatterPlotView.cs">
    151       <SubType>UserControl</SubType>
    152     </Compile>
    153     <Compile Include="TimeSeriesPrognosis\TimeSeriesPrognosisSolutionScatterPlotView.Designer.cs">
    154       <DependentUpon>TimeSeriesPrognosisSolutionScatterPlotView.cs</DependentUpon>
    155     </Compile>
    156125    <Compile Include="DataAnalysisSolutionEvaluationView.cs">
    157126      <SubType>UserControl</SubType>
     
    160129      <DependentUpon>DataAnalysisSolutionEvaluationView.cs</DependentUpon>
    161130    </Compile>
     131    <Compile Include="Plugin.cs" />
    162132    <Compile Include="Regression\RegressionSolutionErrorCharacteristicsCurveView.cs">
    163133      <SubType>UserControl</SubType>
     
    171141    <Compile Include="Regression\RegressionEnsembleSolutionModelView.Designer.cs">
    172142      <DependentUpon>RegressionEnsembleSolutionModelView.cs</DependentUpon>
     143    </Compile>
     144    <Compile Include="Regression\RegressionSolutionResidualHistogram.cs">
     145      <SubType>UserControl</SubType>
     146    </Compile>
     147    <Compile Include="Regression\RegressionSolutionResidualHistogram.Designer.cs">
     148      <DependentUpon>RegressionSolutionResidualHistogram.cs</DependentUpon>
    173149    </Compile>
    174150    <Compile Include="Solution Views\ClassificationSolutionView.cs">
     
    294270  </ItemGroup>
    295271  <ItemGroup>
     272    <ProjectReference Include="..\..\HeuristicLab.Analysis.Views\3.3\HeuristicLab.Analysis.Views-3.3.csproj">
     273      <Project>{76945D76-CA61-4147-9DC2-0ACDCDDF87F9}</Project>
     274      <Name>HeuristicLab.Analysis.Views-3.3</Name>
     275    </ProjectReference>
     276    <ProjectReference Include="..\..\HeuristicLab.Analysis\3.3\HeuristicLab.Analysis-3.3.csproj">
     277      <Project>{887425B4-4348-49ED-A457-B7D2C26DDBF9}</Project>
     278      <Name>HeuristicLab.Analysis-3.3</Name>
     279    </ProjectReference>
    296280    <ProjectReference Include="..\..\HeuristicLab.Collections\3.3\HeuristicLab.Collections-3.3.csproj">
    297281      <Project>{958B43BC-CC5C-4FA2-8628-2B3B01D890B6}</Project>
     
    405389      <DependentUpon>DataAnalysisProblemView.cs</DependentUpon>
    406390    </EmbeddedResource>
     391    <EmbeddedResource Include="Regression\RegressionSolutionResidualHistogram.resx">
     392      <DependentUpon>RegressionSolutionResidualHistogram.cs</DependentUpon>
     393    </EmbeddedResource>
    407394  </ItemGroup>
    408395  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  • branches/RegressionBenchmarks/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionResidualHistogram.Designer.cs

    r7186 r7255  
    1 namespace HeuristicLab.Problems.DataAnalysis.Views.Regression {
     1namespace HeuristicLab.Problems.DataAnalysis.Views {
    22  partial class RegressionSolutionResidualHistogram {
    33    /// <summary>
     
    4141      this.chart.Location = new System.Drawing.Point(0, 0);
    4242      this.chart.Name = "chart";
    43       this.chart.Size = new System.Drawing.Size(150, 150);
    44       this.chart.TabIndex = 2;
     43      this.chart.Size = new System.Drawing.Size(358, 225);
     44      this.chart.TabIndex = 0;
     45      this.chart.CustomizeLegend += new System.EventHandler<System.Windows.Forms.DataVisualization.Charting.CustomizeLegendEventArgs>(this.chart_CustomizeLegend);
     46      this.chart.MouseDown += new System.Windows.Forms.MouseEventHandler(this.chart_MouseDown);
     47      this.chart.MouseMove += new System.Windows.Forms.MouseEventHandler(this.chart_MouseMove);
    4548      //
    4649      // RegressionSolutionResidualHistogram
    4750      //
     51      this.AllowDrop = true;
    4852      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    4953      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    5054      this.Controls.Add(this.chart);
    5155      this.Name = "RegressionSolutionResidualHistogram";
     56      this.Size = new System.Drawing.Size(289, 220);
    5257      ((System.ComponentModel.ISupportInitialize)(this.chart)).EndInit();
    5358      this.ResumeLayout(false);
     
    5762    #endregion
    5863
    59     private Visualization.ChartControlsExtensions.EnhancedChart chart;
     64    private HeuristicLab.Visualization.ChartControlsExtensions.EnhancedChart chart;
    6065  }
    6166}
  • branches/RegressionBenchmarks/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionResidualHistogram.cs

    r7186 r7255  
    2222using System;
    2323using System.Collections.Generic;
     24using System.Drawing;
    2425using System.Linq;
     26using System.Windows.Forms;
    2527using System.Windows.Forms.DataVisualization.Charting;
    2628using HeuristicLab.MainForm;
    27 
    28 namespace HeuristicLab.Problems.DataAnalysis.Views.Regression {
     29using HeuristicLab.MainForm.WindowsForms;
     30
     31namespace HeuristicLab.Problems.DataAnalysis.Views {
    2932  [View("Residual Histogram")]
    3033  [Content(typeof(IRegressionSolution))]
    3134  public partial class RegressionSolutionResidualHistogram : DataAnalysisSolutionEvaluationView {
    32     private const string ALL_SERIES = "All samples";
    33     private const string TRAINING_SERIES = "Training samples";
    34     private const string TEST_SERIES = "Test samples";
    35 
    36     // for test purposes
    37     private const int bins = 9;
     35    protected const string ALL_SAMPLES = "All samples";
     36    protected const string TRAINING_SAMPLES = "Training samples";
     37    protected const string TEST_SAMPLES = "Test samples";
     38
     39    //to reduce code duplication
     40    protected static string[] ALL_SERIES = new string[] { ALL_SAMPLES, TRAINING_SAMPLES, TEST_SAMPLES };
     41
     42    //approximate amount of bins
     43    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     */
     49    protected Dictionary<string, List<List<double>>> relativeFrequencies;
    3850
    3951    public new IRegressionSolution Content {
     
    4254    }
    4355
    44     public RegressionSolutionResidualHistogram() {
     56    public RegressionSolutionResidualHistogram()
     57      : base() {
    4558      InitializeComponent();
    4659
    47       this.chart.Series.Add(ALL_SERIES);
    48       this.chart.Series[ALL_SERIES].LegendText = ALL_SERIES;
    49       this.chart.Series[ALL_SERIES].ChartType = SeriesChartType.Column;
    50 
    51       //this.chart.Series.Add(TRAINING_SERIES);
    52       //this.chart.Series[TRAINING_SERIES].LegendText = TRAINING_SERIES;
    53       //this.chart.Series[TRAINING_SERIES].ChartType = SeriesChartType.FastPoint;
    54       //this.chart.Series[TRAINING_SERIES].Points.Add(1.0);
    55 
    56       //this.chart.Series.Add(TEST_SERIES);
    57       //this.chart.Series[TEST_SERIES].LegendText = TEST_SERIES;
    58       //this.chart.Series[TEST_SERIES].ChartType = SeriesChartType.FastPoint;
     60      relativeFrequencies = new Dictionary<string, List<List<double>>>();
     61
     62      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
     72        relativeFrequencies[series] = new List<List<double>>();
     73      }
    5974
    6075      //configure axis
     
    7388
    7489    private void RedrawChart() {
    75       this.chart.Series[ALL_SERIES].Points.Clear();
     90
     91      foreach (string series in ALL_SERIES) {
     92        this.chart.Series[series].Points.Clear();
     93        this.relativeFrequencies[series].Clear();
     94      }
     95
    7696      if (Content != null) {
    77         List<double> residuals = new List<double>();
    78         IEnumerable<double> targetValues = Content.ProblemData.Dataset.GetDoubleValues(Content.ProblemData.TargetVariable);
    79         IEnumerable<double> estimatedValues = Content.EstimatedValues;
    80         for (int i = 0; i < Content.ProblemData.Dataset.Rows; i++) {
    81           residuals.Add(estimatedValues.ElementAt(i) - targetValues.ElementAt(i));
     97
     98        Dictionary<string, List<double>> residuals = CalculateResiduals();
     99
     100        double max = Math.Max(Math.Abs(residuals[ALL_SAMPLES].Min()), Math.Abs(residuals[ALL_SAMPLES].Max()));
     101        double intervalWidth = (max * 2.0) / bins;
     102
     103        max = HumanRoundMax(max);
     104        intervalWidth = HumanRoundMax(intervalWidth);
     105
     106        foreach (string series in ALL_SERIES) {
     107          CalculateFrequencies(residuals[series], series, max, intervalWidth);
    82108        }
    83109
    84         //no check if both are negative
    85         //assumption that all values are around zero
    86         double max = Math.Ceiling(Math.Max(Math.Abs(residuals.Min()), Math.Abs(residuals.Max())));
    87         double intervalWidth = (max * 2) / bins;
    88         double intervalCenter = intervalWidth / 2.0;
    89         double current = -max;
    90 
    91         Series histogramSeries = this.chart.Series[ALL_SERIES];
    92 
    93         Dictionary<double, int> frequencies = new Dictionary<double, int>();
    94 
    95         for (int i = 0; i <= bins; i++) {
    96           IEnumerable<double> help = residuals.Where(x => x >= (current - intervalCenter) && x < (current + intervalCenter));
    97           frequencies.Add(current, help.Count());
    98           current += intervalWidth;
     110        ChartArea chartArea = chart.ChartAreas[0];
     111
     112        chartArea.AxisX.Minimum = -max - intervalWidth;
     113        chartArea.AxisX.Maximum = max + intervalWidth;
     114        chartArea.AxisY.Maximum = relativeFrequencies[ALL_SAMPLES].Select(x => x.ElementAt(1)).Max() + 0.02;
     115        chartArea.AxisY.Interval = 0.1;
     116
     117        chartArea.AxisX.Interval = intervalWidth;
     118        int curBins = (int)Math.Round(max / intervalWidth);
     119        //shifts the x axis label so that zero is in the middle
     120        if (curBins % 2 == 0)
     121          chartArea.AxisX.IntervalOffset = intervalWidth;
     122        else
     123          chartArea.AxisX.IntervalOffset = intervalWidth / 2;
     124      }
     125    }
     126
     127    private Dictionary<string, List<double>> CalculateResiduals() {
     128      Dictionary<string, List<double>> residuals = new Dictionary<string, List<double>>();
     129
     130      foreach (string series in ALL_SERIES) {
     131        residuals[series] = new List<double>();
     132      }
     133
     134      IRegressionProblemData problemdata = Content.ProblemData;
     135      List<double> targetValues = problemdata.Dataset.GetDoubleValues(Content.ProblemData.TargetVariable).ToList();
     136      List<double> estimatedValues = Content.EstimatedValues.ToList();
     137
     138      for (int i = 0; i < Content.ProblemData.Dataset.Rows; i++) {
     139        double residual = estimatedValues[i] - targetValues[i];
     140        residuals[ALL_SAMPLES].Add(residual);
     141        if (i >= problemdata.TrainingPartition.Start && i < problemdata.TrainingPartition.End)
     142          residuals[TRAINING_SAMPLES].Add(residual);
     143        if (i >= problemdata.TestPartition.Start && i < problemdata.TestPartition.End)
     144          residuals[TEST_SAMPLES].Add(residual);
     145      }
     146
     147      return residuals;
     148    }
     149
     150    private void CalculateFrequencies(List<double> residualValues, string series, double max, double intervalWidth) {
     151      Series residualSeries = this.chart.Series[series];
     152
     153      double intervalCenter = intervalWidth / 2.0;
     154      double sampleCount = residualValues.Count();
     155      double current = -max;
     156
     157      for (int i = 0; i <= bins; i++) {
     158        IEnumerable<double> help = residualValues.Where(x => x >= (current - intervalCenter) && x < (current + intervalCenter));
     159        relativeFrequencies[series].Add(new List<double>() { current, help.Count() / sampleCount, current - intervalCenter, current + intervalCenter });
     160        current += intervalWidth;
     161      }
     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();
    99170        }
    100 
    101         foreach (var item in frequencies) {
    102           histogramSeries.Points.AddXY(item.Key, item.Value);
    103         }
    104       }
     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      }
     186    }
     187
     188    private double HumanRoundMax(double max) {
     189      double base10;
     190      if (max > 0) base10 = Math.Pow(10.0, Math.Floor(Math.Log10(max)));
     191      else base10 = Math.Pow(10.0, Math.Ceiling(Math.Log10(-max)));
     192      double rounding = (max > 0) ? base10 : -base10;
     193      while (rounding < max) rounding += base10;
     194      return rounding;
    105195    }
    106196
     
    127217      RedrawChart();
    128218    }
     219
     220    private void chart_MouseDown(object sender, MouseEventArgs e) {
     221      HitTestResult result = chart.HitTest(e.X, e.Y);
     222      if (result.ChartElementType == ChartElementType.LegendItem) {
     223        ToggleSeriesData(result.Series);
     224      }
     225    }
     226    private void chart_MouseMove(object sender, MouseEventArgs e) {
     227      HitTestResult result = chart.HitTest(e.X, e.Y);
     228      if (result.ChartElementType == ChartElementType.LegendItem)
     229        Cursor = Cursors.Hand;
     230      else
     231        Cursor = Cursors.Default;
     232    }
     233    private void chart_CustomizeLegend(object sender, CustomizeLegendEventArgs e) {
     234      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;
     238    }
    129239    #endregion
    130240  }
Note: See TracChangeset for help on using the changeset viewer.