Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/ClassificationSolutionEstimatedClassValuesView.cs @ 6255

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

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

File size: 4.7 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;
29
30namespace HeuristicLab.Problems.DataAnalysis.Views {
31  [View("Estimated Class Values")]
32  [Content(typeof(IClassificationSolution))]
33  public partial class ClassificationSolutionEstimatedClassValuesView : ItemView, IClassificationSolutionEvaluationView {
34    private const string TARGETVARIABLE_SERIES_NAME = "Target Variable";
35    private const string ESTIMATEDVALUES_SERIES_NAME = "Estimated Class Values (all)";
36    private const string ESTIMATEDVALUES_TRAINING_SERIES_NAME = "Estimated Class Values (training)";
37    private const string ESTIMATEDVALUES_TEST_SERIES_NAME = "Estimated Class Values (test)";
38
39    public new IClassificationSolution Content {
40      get { return (IClassificationSolution)base.Content; }
41      set {
42        base.Content = value;
43      }
44    }
45
46    private StringConvertibleMatrixView matrixView;
47
48    public ClassificationSolutionEstimatedClassValuesView()
49      : base() {
50      InitializeComponent();
51      matrixView = new StringConvertibleMatrixView();
52      matrixView.ShowRowsAndColumnsTextBox = false;
53      matrixView.ShowStatisticalInformation = false;
54      matrixView.Dock = DockStyle.Fill;
55      this.Controls.Add(matrixView);
56    }
57
58    #region events
59    protected override void RegisterContentEvents() {
60      base.RegisterContentEvents();
61      Content.ModelChanged += new EventHandler(Content_ModelChanged);
62      Content.ProblemDataChanged += new EventHandler(Content_ProblemDataChanged);
63    }
64
65    protected override void DeregisterContentEvents() {
66      base.DeregisterContentEvents();
67      Content.ModelChanged -= new EventHandler(Content_ModelChanged);
68      Content.ProblemDataChanged -= new EventHandler(Content_ProblemDataChanged);
69    }
70
71    private void Content_ProblemDataChanged(object sender, EventArgs e) {
72      OnContentChanged();
73    }
74
75    private void Content_ModelChanged(object sender, EventArgs e) {
76      OnContentChanged();
77    }
78
79    protected override void OnContentChanged() {
80      base.OnContentChanged();
81      UpdateEstimatedValues();
82    }
83
84    private void UpdateEstimatedValues() {
85      if (InvokeRequired) Invoke((Action)UpdateEstimatedValues);
86      else {
87        StringMatrix matrix = null;
88        if (Content != null) {
89          string[,] values = new string[Content.ProblemData.Dataset.Rows, 5];
90
91          double[] target = Content.ProblemData.Dataset.GetVariableValues(Content.ProblemData.TargetVariable);
92          double[] estimated = Content.EstimatedClassValues.ToArray();
93          for (int row = 0; row < target.Length; row++) {
94            values[row, 0] = row.ToString();
95            values[row, 1] = target[row].ToString();
96            values[row, 2] = estimated[row].ToString();
97          }
98
99          var estimatedTraining = Content.EstimatedTrainingClassValues.GetEnumerator();
100          estimatedTraining.MoveNext();
101          foreach (var trainingRow in Content.ProblemData.TrainingIndizes) {
102            values[trainingRow, 3] = estimatedTraining.Current.ToString();
103            estimatedTraining.MoveNext();
104          }
105          var estimatedTest = Content.EstimatedTestClassValues.GetEnumerator();
106          estimatedTest.MoveNext();
107          foreach (var testRow in Content.ProblemData.TestIndizes) {
108            values[testRow, 4] = estimatedTest.Current.ToString();
109            estimatedTest.MoveNext();
110          }
111
112          matrix = new StringMatrix(values);
113          matrix.ColumnNames = new string[] {"Id", TARGETVARIABLE_SERIES_NAME, ESTIMATEDVALUES_SERIES_NAME, ESTIMATEDVALUES_TRAINING_SERIES_NAME, ESTIMATEDVALUES_TEST_SERIES_NAME };
114          matrix.SortableView = true;
115        }
116        matrixView.Content = matrix;
117      }
118    }
119    #endregion
120  }
121}
Note: See TracBrowser for help on using the repository browser.