Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionEstimatedValuesView.cs @ 14778

Last change on this file since 14778 was 14772, checked in by mkommend, 8 years ago

#2750: Added residuals to estiamted values view for regression solutions.

File size: 4.9 KB
RevLine 
[3442]1#region License Information
2/* HeuristicLab
[14185]3 * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[3442]4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21using System;
22using System.Linq;
23using System.Windows.Forms;
[4068]24using HeuristicLab.Data;
25using HeuristicLab.Data.Views;
[3442]26using HeuristicLab.MainForm;
27
28namespace HeuristicLab.Problems.DataAnalysis.Views {
[5975]29  [View("Estimated Values")]
[5663]30  [Content(typeof(IRegressionSolution))]
[6642]31  public partial class RegressionSolutionEstimatedValuesView : DataAnalysisSolutionEvaluationView {
[6238]32    private const string TARGETVARIABLE_SERIES_NAME = "Target Variable";
[6255]33    private const string ESTIMATEDVALUES_SERIES_NAME = "Estimated Values (all)";
[6238]34    private const string ESTIMATEDVALUES_TRAINING_SERIES_NAME = "Estimated Values (training)";
35    private const string ESTIMATEDVALUES_TEST_SERIES_NAME = "Estimated Values (test)";
[3442]36
[5663]37    public new IRegressionSolution Content {
38      get { return (IRegressionSolution)base.Content; }
[3442]39      set {
40        base.Content = value;
41      }
42    }
43
[13592]44    private StringConvertibleMatrixView matrixView;
[3442]45
[5663]46    public RegressionSolutionEstimatedValuesView()
[3442]47      : base() {
48      InitializeComponent();
49      matrixView = new StringConvertibleMatrixView();
[5014]50      matrixView.ShowRowsAndColumnsTextBox = false;
51      matrixView.ShowStatisticalInformation = false;
[3442]52      matrixView.Dock = DockStyle.Fill;
53      this.Controls.Add(matrixView);
54    }
55
56    #region events
57    protected override void RegisterContentEvents() {
58      base.RegisterContentEvents();
[5663]59      Content.ModelChanged += new EventHandler(Content_ModelChanged);
[3442]60      Content.ProblemDataChanged += new EventHandler(Content_ProblemDataChanged);
61    }
62
63    protected override void DeregisterContentEvents() {
64      base.DeregisterContentEvents();
[5663]65      Content.ModelChanged -= new EventHandler(Content_ModelChanged);
[3442]66      Content.ProblemDataChanged -= new EventHandler(Content_ProblemDataChanged);
67    }
68
[13592]69    protected virtual void Content_ProblemDataChanged(object sender, EventArgs e) {
[3442]70      OnContentChanged();
71    }
72
[13592]73    protected virtual void Content_ModelChanged(object sender, EventArgs e) {
[3442]74      OnContentChanged();
75    }
76
77    protected override void OnContentChanged() {
78      base.OnContentChanged();
79      UpdateEstimatedValues();
80    }
81
[13592]82    protected virtual StringMatrix CreateValueMatrix() {
[14772]83      string[,] values = new string[Content.ProblemData.Dataset.Rows, 8];
[5014]84
[13592]85      double[] target = Content.ProblemData.Dataset.GetDoubleValues(Content.ProblemData.TargetVariable).ToArray();
86      var estimated = Content.EstimatedValues.GetEnumerator();
87      var estimated_training = Content.EstimatedTrainingValues.GetEnumerator();
88      var estimated_test = Content.EstimatedTestValues.GetEnumerator();
[6238]89
[13592]90      foreach (var row in Content.ProblemData.TrainingIndices) {
91        estimated_training.MoveNext();
92        values[row, 3] = estimated_training.Current.ToString();
93      }
[6238]94
[13592]95      foreach (var row in Content.ProblemData.TestIndices) {
96        estimated_test.MoveNext();
97        values[row, 4] = estimated_test.Current.ToString();
98      }
[6238]99
[13592]100      foreach (var row in Enumerable.Range(0, Content.ProblemData.Dataset.Rows)) {
101        estimated.MoveNext();
102        double est = estimated.Current;
[14772]103        double res = target[row] - est;
[13592]104        values[row, 0] = row.ToString();
105        values[row, 1] = target[row].ToString();
106        values[row, 2] = est.ToString();
[14772]107        values[row, 5] = res.ToString();
108        values[row, 6] = Math.Abs(res).ToString();
109        values[row, 7] = Math.Abs(res / target[row]).ToString();
[13592]110      }
[5014]111
[13592]112      var matrix = new StringMatrix(values);
[14772]113      matrix.ColumnNames = new string[] { "Id", TARGETVARIABLE_SERIES_NAME, ESTIMATEDVALUES_SERIES_NAME, ESTIMATEDVALUES_TRAINING_SERIES_NAME, ESTIMATEDVALUES_TEST_SERIES_NAME, "Residuals (all)", "Absolute Error (all)", "Relative Error (all)" };
[13592]114      matrix.SortableView = true;
115      return matrix;
116    }
117
118    protected virtual void UpdateEstimatedValues() {
119      if (InvokeRequired) Invoke((Action)UpdateEstimatedValues);
120      else {
121        StringMatrix matrix = null;
122        if (Content != null) {
123          matrix = CreateValueMatrix();
[4011]124        }
125        matrixView.Content = matrix;
[3442]126      }
127    }
128    #endregion
129  }
130}
Note: See TracBrowser for help on using the repository browser.