Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/20/11 15:07:45 (13 years ago)
Author:
gkronber
Message:

#1450 adapted views for regression solution to work for ensembles of regression solutions as well.

Location:
trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4
Files:
6 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/HeuristicLab.Problems.DataAnalysis.Views-3.4.csproj

    r6184 r6238  
    158158      <DependentUpon>ClusteringSolutionView.cs</DependentUpon>
    159159    </Compile>
    160     <Compile Include="Interfaces\IRegressionEnsembleSolutionEvaluationView.cs" />
    161     <Compile Include="RegressionEnsembleSolutionView.cs">
    162       <SubType>UserControl</SubType>
    163     </Compile>
    164     <Compile Include="RegressionEnsembleSolutionView.Designer.cs">
    165       <DependentUpon>RegressionEnsembleSolutionView.cs</DependentUpon>
    166     </Compile>
    167160    <Compile Include="DiscriminantFunctionClassificationSolutionView.cs">
    168161      <SubType>UserControl</SubType>
     
    193186    <Compile Include="RegressionSolutionView.Designer.cs">
    194187      <DependentUpon>RegressionSolutionView.cs</DependentUpon>
    195     </Compile>
    196     <Compile Include="Regression\RegressionEnsembleSolutionLineChartView.cs">
    197       <SubType>UserControl</SubType>
    198     </Compile>
    199     <Compile Include="Regression\RegressionEnsembleSolutionLineChartView.Designer.cs">
    200       <DependentUpon>RegressionEnsembleSolutionLineChartView.cs</DependentUpon>
    201     </Compile>
    202     <Compile Include="Regression\RegressionEnsembleSolutionScatterPlotView.cs">
    203       <SubType>UserControl</SubType>
    204     </Compile>
    205     <Compile Include="Regression\RegressionEnsembleSolutionScatterPlotView.Designer.cs">
    206       <DependentUpon>RegressionEnsembleSolutionScatterPlotView.cs</DependentUpon>
    207188    </Compile>
    208189    <Compile Include="Regression\RegressionSolutionEstimatedValuesView.cs">
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionEstimatedValuesView.cs

    r6058 r6238  
    3232  [Content(typeof(IRegressionSolution))]
    3333  public partial class RegressionSolutionEstimatedValuesView : ItemView, IRegressionSolutionEvaluationView {
    34     private const string TARGETVARIABLE_SERIES_NAME = "TargetVariable";
    35     private const string ESTIMATEDVALUES_SERIES_NAME = "EstimatedValues";
     34    private const string TARGETVARIABLE_SERIES_NAME = "Target Variable";
     35    private const string ESTIMATEDVALUES_TRAINING_SERIES_NAME = "Estimated Values (training)";
     36    private const string ESTIMATEDVALUES_TEST_SERIES_NAME = "Estimated Values (test)";
    3637
    3738    public new IRegressionSolution Content {
     
    8586        DoubleMatrix matrix = null;
    8687        if (Content != null) {
    87           double[,] values = new double[Content.ProblemData.Dataset.Rows, 4];
     88          double[,] values = new double[Content.ProblemData.Dataset.Rows, 5];
     89          // initialize to double.NaN
     90          for (int row = 0; row < Content.ProblemData.Dataset.Rows; row++)
     91            for (int column = 0; column < 5; column++)
     92              values[row, column] = double.NaN;
    8893
    8994          double[] target = Content.ProblemData.Dataset.GetVariableValues(Content.ProblemData.TargetVariable);
    90           double[] estimated = Content.EstimatedValues.ToArray();
     95          var estimated_training = Content.EstimatedTrainingValues.GetEnumerator();
     96          var estimated_test = Content.EstimatedTestValues.GetEnumerator();
     97
     98          foreach (var row in Content.ProblemData.TrainingIndizes) {
     99            estimated_training.MoveNext();
     100            values[row, 1] = estimated_training.Current;
     101          }
     102
     103          foreach (var row in Content.ProblemData.TestIndizes) {
     104            estimated_test.MoveNext();
     105            values[row, 2] = estimated_test.Current;
     106          }
     107
    91108          for (int row = 0; row < target.Length; row++) {
    92109            values[row, 0] = target[row];
    93             values[row, 1] = estimated[row];
    94             values[row, 2] = Math.Abs(estimated[row] - target[row]);
    95             values[row, 3] = Math.Abs(values[row, 2] / target[row]);
     110            double est = values[row, 1];
     111            if (!double.IsNaN(est)) {
     112              values[row, 3] = Math.Abs(est - target[row]);
     113              values[row, 4] = Math.Abs(values[row, 3] / target[row]);
     114            }
    96115          }
    97116
    98117          matrix = new DoubleMatrix(values);
    99           matrix.ColumnNames = new string[] { TARGETVARIABLE_SERIES_NAME, ESTIMATEDVALUES_SERIES_NAME, "Absolute Error", "Relative Error" };
     118          matrix.ColumnNames = new string[] { TARGETVARIABLE_SERIES_NAME, ESTIMATEDVALUES_TRAINING_SERIES_NAME, ESTIMATEDVALUES_TEST_SERIES_NAME, "Absolute Error (training)", "Relative Error (training)" };
    100119        }
    101120        matrixView.Content = matrix;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionLineChartView.cs

    r5975 r6238  
    3232  [Content(typeof(IRegressionSolution))]
    3333  public partial class RegressionSolutionLineChartView : ItemView, IRegressionSolutionEvaluationView {
    34     private const string TARGETVARIABLE_SERIES_NAME = "TargetVariable";
    35     private const string ESTIMATEDVALUES_SERIES_NAME = "EstimatedValues";
     34    private const string TARGETVARIABLE_SERIES_NAME = "Target Variable";
     35    private const string ESTIMATEDVALUES_TRAINING_SERIES_NAME = "Estimated Values (training)";
     36    private const string ESTIMATEDVALUES_TEST_SERIES_NAME = "Estimated Values (test)";
    3637
    3738    public new IRegressionSolution Content {
     
    4748      this.chart.ChartAreas[0].CursorX.IsUserSelectionEnabled = true;
    4849      this.chart.ChartAreas[0].AxisX.ScaleView.Zoomable = true;
     50      this.chart.ChartAreas[0].AxisX.IsStartedFromZero = true;
    4951      this.chart.ChartAreas[0].CursorX.Interval = 1;
    5052
     
    5759      this.chart.Series.Clear();
    5860      if (Content != null) {
     61        this.chart.ChartAreas[0].AxisX.Minimum = 0;
     62        this.chart.ChartAreas[0].AxisX.Maximum = Content.ProblemData.Dataset.Rows - 1;
     63
    5964        this.chart.Series.Add(TARGETVARIABLE_SERIES_NAME);
    6065        this.chart.Series[TARGETVARIABLE_SERIES_NAME].LegendText = Content.ProblemData.TargetVariable;
    6166        this.chart.Series[TARGETVARIABLE_SERIES_NAME].ChartType = SeriesChartType.FastLine;
    62         this.chart.Series[TARGETVARIABLE_SERIES_NAME].Points.DataBindY(Content.ProblemData.Dataset.GetVariableValues(Content.ProblemData.TargetVariable));
     67        this.chart.Series[TARGETVARIABLE_SERIES_NAME].Points.DataBindXY(Enumerable.Range(0, Content.ProblemData.Dataset.Rows).ToArray(),
     68          Content.ProblemData.Dataset.GetVariableValues(Content.ProblemData.TargetVariable));
     69
     70        this.chart.Series.Add(ESTIMATEDVALUES_TRAINING_SERIES_NAME);
     71        this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME].LegendText = ESTIMATEDVALUES_TRAINING_SERIES_NAME;
     72        this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME].ChartType = SeriesChartType.FastLine;
     73        this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME].Points.DataBindXY(Content.ProblemData.TrainingIndizes.ToArray(),
     74          Content.EstimatedTrainingValues.ToArray());
     75        this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME].Tag = Content;
     76
     77        this.chart.Series.Add(ESTIMATEDVALUES_TEST_SERIES_NAME);
     78        this.chart.Series[ESTIMATEDVALUES_TEST_SERIES_NAME].LegendText = ESTIMATEDVALUES_TEST_SERIES_NAME;
     79        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());
     82        this.chart.Series[ESTIMATEDVALUES_TEST_SERIES_NAME].Tag = Content;
     83        UpdateCursorInterval();
    6384        this.UpdateStripLines();
    64 
    65         this.chart.Series.Add(ESTIMATEDVALUES_SERIES_NAME);
    66         this.chart.Series[ESTIMATEDVALUES_SERIES_NAME].LegendText = Content.ItemName;
    67         this.chart.Series[ESTIMATEDVALUES_SERIES_NAME].ChartType = SeriesChartType.FastLine;
    68         this.chart.Series[ESTIMATEDVALUES_SERIES_NAME].Points.DataBindY(Content.EstimatedValues.ToArray());
    69         this.chart.Series[ESTIMATEDVALUES_SERIES_NAME].Tag = Content;
    70         UpdateCursorInterval();
    7185      }
    7286    }
    7387
    7488    private void UpdateCursorInterval() {
    75       var estimatedValues = this.chart.Series[ESTIMATEDVALUES_SERIES_NAME].Points.Select(x => x.YValues[0]).DefaultIfEmpty(1.0);
     89      var estimatedValues = this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME].Points.Select(x => x.YValues[0]).DefaultIfEmpty(1.0);
    7690      var targetValues = this.chart.Series[TARGETVARIABLE_SERIES_NAME].Points.Select(x => x.YValues[0]).DefaultIfEmpty(1.0);
    7791      double estimatedValuesRange = estimatedValues.Max() - estimatedValues.Min();
     
    112126      else {
    113127        if (this.chart.Series.Count > 0) {
    114           Series s = this.chart.Series.SingleOrDefault(x => x.Tag == Content);
     128          Series s = this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME];
    115129          if (s != null) {
    116             s.Points.DataBindY(Content.EstimatedValues.ToArray());
    117             s.LegendText = Content.ItemName;
    118             this.UpdateStripLines();
    119             UpdateCursorInterval();
     130            s.Points.DataBindXY(Content.ProblemData.TrainingIndizes.ToArray(), Content.EstimatedTrainingValues.ToArray());
     131            s.LegendText = ESTIMATEDVALUES_TRAINING_SERIES_NAME;
    120132          }
     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();
    121140        }
    122141      }
     
    136155    private void UpdateStripLines() {
    137156      this.chart.ChartAreas[0].AxisX.StripLines.Clear();
    138       this.CreateAndAddStripLine("Training", Color.FromArgb(20, Color.Green),
    139         Content.ProblemData.TrainingPartition.Start,
    140         Content.ProblemData.TrainingPartition.End);
    141       this.CreateAndAddStripLine("Test", Color.FromArgb(20, Color.Red),
    142         Content.ProblemData.TestPartition.Start,
    143         Content.ProblemData.TestPartition.End);
    144     }
    145 
    146     private void CreateAndAddStripLine(string title, Color c, int start, int end) {
     157
     158      int[] attr = new int[Content.ProblemData.Dataset.Rows + 1]; // add a virtual last row that is again empty to simplify loop further down
     159      foreach (var row in Content.ProblemData.TrainingIndizes) {
     160        attr[row] += 1;
     161      }
     162      foreach (var row in Content.ProblemData.TestIndizes) {
     163        attr[row] += 2;
     164      }
     165      int start = 0;
     166      int curAttr = attr[start];
     167      for (int row = 0; row < attr.Length; row++) {
     168        if (attr[row] != curAttr) {
     169          switch (curAttr) {
     170            case 0: break;
     171            case 1:
     172              this.CreateAndAddStripLine("Training", start, row, Color.FromArgb(40, Color.Green), Color.Transparent);
     173              break;
     174            case 2:
     175              this.CreateAndAddStripLine("Test", start, row, Color.FromArgb(40, Color.Red), Color.Transparent);
     176              break;
     177            case 3:
     178              this.CreateAndAddStripLine("Training and Test", start, row, Color.FromArgb(40, Color.Green), Color.FromArgb(40, Color.Red), ChartHatchStyle.WideUpwardDiagonal);
     179              break;
     180            default:
     181              // should not happen
     182              break;
     183          }
     184          curAttr = attr[row];
     185          start = row;
     186        }
     187      }
     188    }
     189
     190    private void CreateAndAddStripLine(string title, int start, int end, Color color, Color secondColor, ChartHatchStyle hatchStyle = ChartHatchStyle.None) {
    147191      StripLine stripLine = new StripLine();
    148       stripLine.BackColor = c;
     192      stripLine.BackColor = color;
     193      stripLine.BackSecondaryColor = secondColor;
     194      stripLine.BackHatchStyle = hatchStyle;
    149195      stripLine.Text = title;
    150196      stripLine.Font = new Font("Times New Roman", 12, FontStyle.Bold);
    151       stripLine.StripWidth = end - start;
     197      stripLine.StripWidth = end - start - 1; // strip range is [start .. end] inclusive, but we evaluate [start..end[ (end is exclusive)
    152198      stripLine.IntervalOffset = start;
    153199      this.chart.ChartAreas[0].AxisX.StripLines.Add(stripLine);
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionScatterPlotView.cs

    r5975 r6238  
    139139           dataset.GetEnumeratedVariableValues(targetVariableName, Content.ProblemData.TestIndizes).ToArray(), "");
    140140
    141         double max = Math.Max(Content.EstimatedValues.Max(), dataset.GetVariableValues(targetVariableName).Max());
    142         double min = Math.Min(Content.EstimatedValues.Min(), dataset.GetVariableValues(targetVariableName).Min());
     141        double max = Content.EstimatedTrainingValues.Concat(Content.EstimatedTestValues.Concat(Content.EstimatedValues.Concat(dataset.GetVariableValues(targetVariableName)))).Max();
     142        double min = Content.EstimatedTrainingValues.Concat(Content.EstimatedTestValues.Concat(Content.EstimatedValues.Concat(dataset.GetVariableValues(targetVariableName)))).Min();
    143143
    144144        max = max + 0.2 * Math.Abs(max);
Note: See TracChangeset for help on using the changeset viewer.