Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionEstimatedValuesView.cs @ 12009

Last change on this file since 12009 was 12009, checked in by ascheibe, 9 years ago

#2212 updated copyright year

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