Free cookie consent management tool by TermsFeed Policy Generator

source: branches/QAPAlgorithms/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionEstimatedValuesView.cs @ 6433

Last change on this file since 6433 was 6255, checked in by gkronber, 14 years ago

#1450 Implemented changes in estimated values views for regression and classification solutions specific to ensemble solutions.

File size: 4.9 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
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;
24using HeuristicLab.Core.Views;
25using HeuristicLab.Data;
26using HeuristicLab.Data.Views;
27using HeuristicLab.MainForm;
28using HeuristicLab.MainForm.WindowsForms;
29using System.Globalization;
30
31namespace HeuristicLab.Problems.DataAnalysis.Views {
32  [View("Estimated Values")]
33  [Content(typeof(IRegressionSolution))]
34  public partial class RegressionSolutionEstimatedValuesView : ItemView, IRegressionSolutionEvaluationView {
35    private const string TARGETVARIABLE_SERIES_NAME = "Target Variable";
36    private const string ESTIMATEDVALUES_SERIES_NAME = "Estimated Values (all)";
37    private const string ESTIMATEDVALUES_TRAINING_SERIES_NAME = "Estimated Values (training)";
38    private const string ESTIMATEDVALUES_TEST_SERIES_NAME = "Estimated Values (test)";
39
40    public new IRegressionSolution Content {
41      get { return (IRegressionSolution)base.Content; }
42      set {
43        base.Content = value;
44      }
45    }
46
47    private StringConvertibleMatrixView matrixView;
48
49    public RegressionSolutionEstimatedValuesView()
50      : base() {
51      InitializeComponent();
52      matrixView = new StringConvertibleMatrixView();
53      matrixView.ShowRowsAndColumnsTextBox = false;
54      matrixView.ShowStatisticalInformation = false;
55      matrixView.Dock = DockStyle.Fill;
56      this.Controls.Add(matrixView);
57    }
58
59    #region events
60    protected override void RegisterContentEvents() {
61      base.RegisterContentEvents();
62      Content.ModelChanged += new EventHandler(Content_ModelChanged);
63      Content.ProblemDataChanged += new EventHandler(Content_ProblemDataChanged);
64    }
65
66    protected override void DeregisterContentEvents() {
67      base.DeregisterContentEvents();
68      Content.ModelChanged -= new EventHandler(Content_ModelChanged);
69      Content.ProblemDataChanged -= new EventHandler(Content_ProblemDataChanged);
70    }
71
72    private void Content_ProblemDataChanged(object sender, EventArgs e) {
73      OnContentChanged();
74    }
75
76    private void Content_ModelChanged(object sender, EventArgs e) {
77      OnContentChanged();
78    }
79
80    protected override void OnContentChanged() {
81      base.OnContentChanged();
82      UpdateEstimatedValues();
83    }
84
85    private void UpdateEstimatedValues() {
86      if (InvokeRequired) Invoke((Action)UpdateEstimatedValues);
87      else {
88        StringMatrix matrix = null;
89        if (Content != null) {
90          string[,] values = new string[Content.ProblemData.Dataset.Rows, 7];
91
92          double[] target = Content.ProblemData.Dataset.GetVariableValues(Content.ProblemData.TargetVariable);
93          var estimated = Content.EstimatedValues.GetEnumerator();
94          var estimated_training = Content.EstimatedTrainingValues.GetEnumerator();
95          var estimated_test = Content.EstimatedTestValues.GetEnumerator();
96
97          foreach (var row in Content.ProblemData.TrainingIndizes) {
98            estimated_training.MoveNext();
99            values[row, 3] = estimated_training.Current.ToString();
100          }
101
102          foreach (var row in Content.ProblemData.TestIndizes) {
103            estimated_test.MoveNext();
104            values[row, 4] = estimated_test.Current.ToString();
105          }
106
107          foreach (var row in Enumerable.Range(0, Content.ProblemData.Dataset.Rows)) {
108            estimated.MoveNext();
109            double est = estimated.Current;
110            double res = Math.Abs(est - target[row]);
111            values[row, 0] = row.ToString();
112            values[row, 1] = target[row].ToString();
113            values[row, 2] = est.ToString();
114            values[row, 5] = Math.Abs(res).ToString();
115            values[row, 6] = Math.Abs(res / est).ToString();
116          }
117
118          matrix = new StringMatrix(values);
119          matrix.ColumnNames = new string[] { "Id", TARGETVARIABLE_SERIES_NAME, ESTIMATEDVALUES_SERIES_NAME, ESTIMATEDVALUES_TRAINING_SERIES_NAME, ESTIMATEDVALUES_TEST_SERIES_NAME, "Absolute Error (all)", "Relative Error (all)" };
120          matrix.SortableView = true;
121        }
122        matrixView.Content = matrix;
123      }
124    }
125    #endregion
126  }
127}
Note: See TracBrowser for help on using the repository browser.