Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/16/11 12:00:36 (13 years ago)
Author:
mkommend
Message:

#1479: Integrated trunk changes.

Location:
branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionErrorCharacteristicsCurveView.cs

    r6647 r6784  
    139139        if (residuals[i] > chart.ChartAreas[0].AxisX.Maximum) {
    140140          point.XValue = chart.ChartAreas[0].AxisX.Maximum;
    141           point.YValues[0] = ((double)i - 1) / residuals.Count;
     141          point.YValues[0] = ((double)i) / residuals.Count;
    142142          point.ToolTip = "Error: " + point.XValue + "\n" + "Samples: " + point.YValues[0];
    143143          series.Points.Add(point);
     
    146146
    147147        point.XValue = residuals[i];
    148         point.YValues[0] = ((double)i) / residuals.Count;
     148        point.YValues[0] = ((double)i+1) / residuals.Count;
    149149        point.ToolTip = "Error: " + point.XValue + "\n" + "Samples: " + point.YValues[0];
    150150        series.Points.Add(point);
     
    164164      switch (cmbSamples.SelectedItem.ToString()) {
    165165        case TrainingSamples:
    166           originalValues = ProblemData.Dataset.GetEnumeratedVariableValues(ProblemData.TargetVariable, ProblemData.TrainingIndizes);
     166          originalValues = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndizes);
    167167          break;
    168168        case TestSamples:
    169           originalValues = ProblemData.Dataset.GetEnumeratedVariableValues(ProblemData.TargetVariable, ProblemData.TestIndizes);
     169          originalValues = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TestIndizes);
    170170          break;
    171171        case AllSamples:
    172           originalValues = ProblemData.Dataset.GetEnumeratedVariableValues(ProblemData.TargetVariable);
     172          originalValues = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable);
    173173          break;
    174174        default:
     
    197197
    198198    protected IEnumerable<double> GetMeanModelEstimatedValues(IEnumerable<double> originalValues) {
    199       double averageTrainingTarget = ProblemData.Dataset.GetEnumeratedVariableValues(ProblemData.TargetVariable, ProblemData.TrainingIndizes).Average();
     199      double averageTrainingTarget = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndizes).Average();
    200200      return Enumerable.Repeat(averageTrainingTarget, originalValues.Count());
    201201    }
  • branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionEstimatedValuesView.cs

    r6647 r6784  
    8888          string[,] values = new string[Content.ProblemData.Dataset.Rows, 7];
    8989
    90           double[] target = Content.ProblemData.Dataset.GetVariableValues(Content.ProblemData.TargetVariable);
     90          double[] target = Content.ProblemData.Dataset.GetDoubleValues(Content.ProblemData.TargetVariable).ToArray();
    9191          var estimated = Content.EstimatedValues.GetEnumerator();
    9292          var estimated_training = Content.EstimatedTrainingValues.GetEnumerator();
  • branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionLineChartView.Designer.cs

    r5809 r6784  
    6363      this.chart.Size = new System.Drawing.Size(358, 225);
    6464      this.chart.TabIndex = 0;
     65      this.chart.CustomizeLegend += new System.EventHandler<System.Windows.Forms.DataVisualization.Charting.CustomizeLegendEventArgs>(this.chart_CustomizeLegend);
    6566      this.chart.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.Chart_MouseDoubleClick);
     67      this.chart.MouseDown += new System.Windows.Forms.MouseEventHandler(this.chart_MouseDown);
     68      this.chart.MouseMove += new System.Windows.Forms.MouseEventHandler(this.chart_MouseMove);
    6669      //
    67       // LineChartView
     70      // RegressionSolutionLineChartView
    6871      //
    6972      this.AllowDrop = true;
     
    7174      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    7275      this.Controls.Add(this.chart);
    73       this.Name = "LineChartView";
     76      this.Name = "RegressionSolutionLineChartView";
    7477      this.Size = new System.Drawing.Size(358, 225);
    7578      ((System.ComponentModel.ISupportInitialize)(this.chart)).EndInit();
  • branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionLineChartView.cs

    r6647 r6784  
    2020#endregion
    2121using System;
     22using System.Collections.Generic;
    2223using System.Drawing;
    2324using System.Linq;
     
    3435    private const string ESTIMATEDVALUES_TRAINING_SERIES_NAME = "Estimated Values (training)";
    3536    private const string ESTIMATEDVALUES_TEST_SERIES_NAME = "Estimated Values (test)";
     37    private const string ESTIMATEDVALUES_ALL_SERIES_NAME = "Estimated Values (all samples)";
    3638
    3739    public new IRegressionSolution Content {
     
    6567        this.chart.Series[TARGETVARIABLE_SERIES_NAME].ChartType = SeriesChartType.FastLine;
    6668        this.chart.Series[TARGETVARIABLE_SERIES_NAME].Points.DataBindXY(Enumerable.Range(0, Content.ProblemData.Dataset.Rows).ToArray(),
    67           Content.ProblemData.Dataset.GetVariableValues(Content.ProblemData.TargetVariable));
     69          Content.ProblemData.Dataset.GetDoubleValues(Content.ProblemData.TargetVariable).ToArray());
    6870
    6971        this.chart.Series.Add(ESTIMATEDVALUES_TRAINING_SERIES_NAME);
    7072        this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME].LegendText = ESTIMATEDVALUES_TRAINING_SERIES_NAME;
    7173        this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME].ChartType = SeriesChartType.FastLine;
    72         this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME].Points.DataBindXY(Content.ProblemData.TrainingIndizes.ToArray(),
    73           Content.EstimatedTrainingValues.ToArray());
    74         this.chart.DataManipulator.InsertEmptyPoints(Content.ProblemData.Dataset.Rows, IntervalType.Number, ESTIMATEDVALUES_TRAINING_SERIES_NAME);
     74        this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME].Points.DataBindXY(Content.ProblemData.TrainingIndizes.ToArray(), Content.EstimatedTrainingValues.ToArray());
    7575        this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME].Tag = Content;
     76        this.chart.DataManipulator.InsertEmptyPoints(1, IntervalType.Number, ESTIMATEDVALUES_TRAINING_SERIES_NAME);
     77        this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME].EmptyPointStyle.BorderWidth = 0;
     78        this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME].EmptyPointStyle.MarkerStyle = MarkerStyle.None;
     79
    7680
    7781        this.chart.Series.Add(ESTIMATEDVALUES_TEST_SERIES_NAME);
    7882        this.chart.Series[ESTIMATEDVALUES_TEST_SERIES_NAME].LegendText = ESTIMATEDVALUES_TEST_SERIES_NAME;
    7983        this.chart.Series[ESTIMATEDVALUES_TEST_SERIES_NAME].ChartType = SeriesChartType.FastLine;
    80         this.chart.Series[ESTIMATEDVALUES_TEST_SERIES_NAME].Points.DataBindXY(Content.ProblemData.TestIndizes.ToArray(),
    81           Content.EstimatedTestValues.ToArray());
     84        this.chart.Series[ESTIMATEDVALUES_TEST_SERIES_NAME].Points.DataBindXY(Content.ProblemData.TestIndizes.ToArray(), Content.EstimatedTestValues.ToArray());
    8285        this.chart.Series[ESTIMATEDVALUES_TEST_SERIES_NAME].Tag = Content;
     86
     87
     88        int[] allIndizes = Enumerable.Range(0, Content.ProblemData.Dataset.Rows).Except(Content.ProblemData.TrainingIndizes).Except(Content.ProblemData.TestIndizes).ToArray();
     89        var estimatedValues = Content.EstimatedValues.ToArray();
     90        List<double> allEstimatedValues = allIndizes.Select(index => estimatedValues[index]).ToList();
     91
     92        this.chart.Series.Add(ESTIMATEDVALUES_ALL_SERIES_NAME);
     93        this.chart.Series[ESTIMATEDVALUES_ALL_SERIES_NAME].LegendText = ESTIMATEDVALUES_ALL_SERIES_NAME;
     94        this.chart.Series[ESTIMATEDVALUES_ALL_SERIES_NAME].ChartType = SeriesChartType.FastLine;
     95        this.chart.Series[ESTIMATEDVALUES_ALL_SERIES_NAME].Points.DataBindXY(allIndizes, allEstimatedValues);
     96        this.chart.Series[ESTIMATEDVALUES_ALL_SERIES_NAME].Tag = Content;
     97        this.chart.DataManipulator.InsertEmptyPoints(1, IntervalType.Number, ESTIMATEDVALUES_ALL_SERIES_NAME);
     98        this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME].EmptyPointStyle.BorderWidth = 0;
     99        this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME].EmptyPointStyle.MarkerStyle = MarkerStyle.None;
     100        this.ToggleSeriesData(this.chart.Series[ESTIMATEDVALUES_ALL_SERIES_NAME]);
     101
    83102        UpdateCursorInterval();
    84103        this.UpdateStripLines();
     
    109128    }
    110129
    111     private void Content_ProblemDataChanged(object sender, EventArgs e) {
    112       RedrawChart();
    113     }
    114 
    115     private void Content_ModelChanged(object sender, EventArgs e) {
    116       UpdateEstimatedValuesLineChart();
    117     }
    118 
    119130    protected override void OnContentChanged() {
    120131      base.OnContentChanged();
    121132      RedrawChart();
    122133    }
    123 
    124     private void UpdateEstimatedValuesLineChart() {
    125       if (InvokeRequired) Invoke((Action)UpdateEstimatedValuesLineChart);
    126       else {
    127         if (this.chart.Series.Count > 0) {
    128           Series s = this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME];
    129           if (s != null) {
    130             s.Points.DataBindXY(Content.ProblemData.TrainingIndizes.ToArray(), Content.EstimatedTrainingValues.ToArray());
    131             s.LegendText = ESTIMATEDVALUES_TRAINING_SERIES_NAME;
    132           }
    133           s = this.chart.Series[ESTIMATEDVALUES_TEST_SERIES_NAME];
    134           if (s != null) {
    135             s.Points.DataBindXY(Content.ProblemData.TestIndizes.ToArray(), Content.EstimatedTestValues.ToArray());
    136             s.LegendText = ESTIMATEDVALUES_TEST_SERIES_NAME;
    137           }
    138           this.UpdateStripLines();
    139           UpdateCursorInterval();
    140         }
    141       }
    142     }
     134    private void Content_ProblemDataChanged(object sender, EventArgs e) {
     135      RedrawChart();
     136    }
     137    private void Content_ModelChanged(object sender, EventArgs e) {
     138      RedrawChart();
     139    }
     140
     141
    143142
    144143    private void Chart_MouseDoubleClick(object sender, MouseEventArgs e) {
     
    201200      this.chart.ChartAreas[0].AxisX.StripLines.Add(stripLine);
    202201    }
     202
     203    private void ToggleSeriesData(Series series) {
     204      if (series.Points.Count > 0) {  //checks if series is shown
     205        if (this.chart.Series.Any(s => s != series && s.Points.Count > 0)) {
     206          series.Points.Clear();
     207        }
     208      } else if (Content != null) {
     209        string targetVariableName = Content.ProblemData.TargetVariable;
     210
     211        IEnumerable<int> indizes = null;
     212        IEnumerable<double> predictedValues = null;
     213        switch (series.Name) {
     214          case ESTIMATEDVALUES_ALL_SERIES_NAME:
     215            indizes = Enumerable.Range(0, Content.ProblemData.Dataset.Rows).Except(Content.ProblemData.TrainingIndizes).Except(Content.ProblemData.TestIndizes).ToArray();
     216            var estimatedValues = Content.EstimatedValues.ToArray();
     217            predictedValues = indizes.Select(index => estimatedValues[index]).ToList();
     218            break;
     219          case ESTIMATEDVALUES_TRAINING_SERIES_NAME:
     220            indizes = Content.ProblemData.TrainingIndizes.ToArray();
     221            predictedValues = Content.EstimatedTrainingValues.ToArray();
     222            break;
     223          case ESTIMATEDVALUES_TEST_SERIES_NAME:
     224            indizes = Content.ProblemData.TestIndizes.ToArray();
     225            predictedValues = Content.EstimatedTestValues.ToArray();
     226            break;
     227        }
     228        series.Points.DataBindXY(indizes, predictedValues);
     229        chart.DataManipulator.InsertEmptyPoints(1, IntervalType.Number, series.Name);
     230        chart.Legends[series.Legend].ForeColor = Color.Black;
     231        UpdateCursorInterval();
     232        chart.Refresh();
     233      }
     234    }
     235
     236    private void chart_MouseMove(object sender, MouseEventArgs e) {
     237      HitTestResult result = chart.HitTest(e.X, e.Y);
     238      if (result.ChartElementType == ChartElementType.LegendItem && result.Series.Name != TARGETVARIABLE_SERIES_NAME)
     239        Cursor = Cursors.Hand;
     240      else
     241        Cursor = Cursors.Default;
     242    }
     243    private void chart_MouseDown(object sender, MouseEventArgs e) {
     244      HitTestResult result = chart.HitTest(e.X, e.Y);
     245      if (result.ChartElementType == ChartElementType.LegendItem && result.Series.Name != TARGETVARIABLE_SERIES_NAME) {
     246        ToggleSeriesData(result.Series);
     247      }
     248    }
     249
     250    private void chart_CustomizeLegend(object sender, CustomizeLegendEventArgs e) {
     251      if (chart.Series.Count != 4) return;
     252      e.LegendItems[0].Cells[1].ForeColor = this.chart.Series[TARGETVARIABLE_SERIES_NAME].Points.Count == 0 ? Color.Gray : Color.Black;
     253      e.LegendItems[1].Cells[1].ForeColor = this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME].Points.Count == 0 ? Color.Gray : Color.Black;
     254      e.LegendItems[2].Cells[1].ForeColor = this.chart.Series[ESTIMATEDVALUES_TEST_SERIES_NAME].Points.Count == 0 ? Color.Gray : Color.Black;
     255      e.LegendItems[3].Cells[1].ForeColor = this.chart.Series[ESTIMATEDVALUES_ALL_SERIES_NAME].Points.Count == 0 ? Color.Gray : Color.Black;
     256    }
    203257  }
    204258}
  • branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionScatterPlotView.Designer.cs

    r5809 r6784  
    6464      this.chart.Size = new System.Drawing.Size(527, 392);
    6565      this.chart.TabIndex = 1;
     66      this.chart.PostPaint += new System.EventHandler<System.Windows.Forms.DataVisualization.Charting.ChartPaintEventArgs>(this.chart_PostPaint);
     67      this.chart.CustomizeLegend += new System.EventHandler<System.Windows.Forms.DataVisualization.Charting.CustomizeLegendEventArgs>(this.chart_CustomizeLegend);
     68      this.chart.MouseDown += new System.Windows.Forms.MouseEventHandler(this.chart_MouseDown);
    6669      this.chart.MouseMove += new System.Windows.Forms.MouseEventHandler(this.chart_MouseMove);
    67       this.chart.MouseDown += new System.Windows.Forms.MouseEventHandler(this.chart_MouseDown);
    68       this.chart.CustomizeLegend += new System.EventHandler<System.Windows.Forms.DataVisualization.Charting.CustomizeLegendEventArgs>(chart_CustomizeLegend);
    6970      //
    70       // ScatterPlotView
     71      // RegressionSolutionScatterPlotView
    7172      //
     73      this.AllowDrop = true;
    7274      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    7375      this.Controls.Add(this.chart);
    74       this.Name = "ScatterPlotView";
    75       this.AllowDrop = true;
     76      this.Name = "RegressionSolutionScatterPlotView";
    7677      this.Size = new System.Drawing.Size(527, 392);
    7778      ((System.ComponentModel.ISupportInitialize)(this.chart)).EndInit();
  • branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionScatterPlotView.cs

    r6647 r6784  
    130130        if (this.chart.Series[ALL_SERIES].Points.Count > 0)
    131131          this.chart.Series[ALL_SERIES].Points.DataBindXY(Content.EstimatedValues.ToArray(), "",
    132             dataset.GetVariableValues(targetVariableName), "");
     132            dataset.GetDoubleValues(targetVariableName).ToArray(), "");
    133133        if (this.chart.Series[TRAINING_SERIES].Points.Count > 0)
    134134          this.chart.Series[TRAINING_SERIES].Points.DataBindXY(Content.EstimatedTrainingValues.ToArray(), "",
    135             dataset.GetEnumeratedVariableValues(targetVariableName, Content.ProblemData.TrainingIndizes).ToArray(), "");
     135            dataset.GetDoubleValues(targetVariableName, Content.ProblemData.TrainingIndizes).ToArray(), "");
    136136        if (this.chart.Series[TEST_SERIES].Points.Count > 0)
    137137          this.chart.Series[TEST_SERIES].Points.DataBindXY(Content.EstimatedTestValues.ToArray(), "",
    138            dataset.GetEnumeratedVariableValues(targetVariableName, Content.ProblemData.TestIndizes).ToArray(), "");
    139 
    140         double max = Content.EstimatedTrainingValues.Concat(Content.EstimatedTestValues.Concat(Content.EstimatedValues.Concat(dataset.GetVariableValues(targetVariableName)))).Max();
    141         double min = Content.EstimatedTrainingValues.Concat(Content.EstimatedTestValues.Concat(Content.EstimatedValues.Concat(dataset.GetVariableValues(targetVariableName)))).Min();
     138           dataset.GetDoubleValues(targetVariableName, Content.ProblemData.TestIndizes).ToArray(), "");
     139
     140        double max = Content.EstimatedTrainingValues.Concat(Content.EstimatedTestValues.Concat(Content.EstimatedValues.Concat(dataset.GetDoubleValues(targetVariableName)))).Max();
     141        double min = Content.EstimatedTrainingValues.Concat(Content.EstimatedTestValues.Concat(Content.EstimatedValues.Concat(dataset.GetDoubleValues(targetVariableName)))).Min();
    142142
    143143        max = max + 0.2 * Math.Abs(max);
     
    177177          case ALL_SERIES:
    178178            predictedValues = Content.EstimatedValues.ToArray();
    179             targetValues = Content.ProblemData.Dataset.GetVariableValues(targetVariableName);
     179            targetValues = Content.ProblemData.Dataset.GetDoubleValues(targetVariableName).ToArray();
    180180            break;
    181181          case TRAINING_SERIES:
    182182            predictedValues = Content.EstimatedTrainingValues.ToArray();
    183             targetValues = Content.ProblemData.Dataset.GetEnumeratedVariableValues(targetVariableName, Content.ProblemData.TrainingIndizes).ToArray();
     183            targetValues = Content.ProblemData.Dataset.GetDoubleValues(targetVariableName, Content.ProblemData.TrainingIndizes).ToArray();
    184184            break;
    185185          case TEST_SERIES:
    186186            predictedValues = Content.EstimatedTestValues.ToArray();
    187             targetValues = Content.ProblemData.Dataset.GetEnumeratedVariableValues(targetVariableName, Content.ProblemData.TestIndizes).ToArray();
     187            targetValues = Content.ProblemData.Dataset.GetDoubleValues(targetVariableName, Content.ProblemData.TestIndizes).ToArray();
    188188            break;
    189189        }
     
    219219      e.LegendItems[2].Cells[1].ForeColor = this.chart.Series[TEST_SERIES].Points.Count == 0 ? Color.Gray : Color.Black;
    220220    }
     221
     222    private void chart_PostPaint(object sender, ChartPaintEventArgs e) {
     223      var chartArea = e.ChartElement as ChartArea;
     224      if (chartArea != null) {
     225        ChartGraphics chartGraphics = e.ChartGraphics;
     226        using (Pen p = new Pen(Color.DarkGray)) {
     227          double xmin = chartArea.AxisX.ScaleView.ViewMinimum;
     228          double xmax = chartArea.AxisX.ScaleView.ViewMaximum;
     229          double ymin = chartArea.AxisY.ScaleView.ViewMinimum;
     230          double ymax = chartArea.AxisY.ScaleView.ViewMaximum;
     231
     232          if (xmin > ymax || ymin > xmax) return;
     233
     234          PointF start = PointF.Empty;
     235          start.X = (float)chartGraphics.GetPositionFromAxis(chartArea.Name, chartArea.AxisX.AxisName, Math.Max(xmin, ymin));
     236          start.Y = (float)chartGraphics.GetPositionFromAxis(chartArea.Name, chartArea.AxisY.AxisName, Math.Max(xmin, ymin));
     237          PointF end = PointF.Empty;
     238          end.X = (float)chartGraphics.GetPositionFromAxis(chartArea.Name, chartArea.AxisX.AxisName, Math.Min(xmax, ymax));
     239          end.Y = (float)chartGraphics.GetPositionFromAxis(chartArea.Name, chartArea.AxisY.AxisName, Math.Min(xmax, ymax));
     240
     241          chartGraphics.Graphics.DrawLine(p, chartGraphics.GetAbsolutePoint(start), chartGraphics.GetAbsolutePoint(end));
     242        }
     243      }
     244    }
    221245  }
    222246}
Note: See TracChangeset for help on using the changeset viewer.