Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 6618 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.7 KB
RevLine 
[3442]1#region License Information
2/* HeuristicLab
[5445]3 * Copyright (C) 2002-2011 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;
[5829]24using HeuristicLab.Core.Views;
[4068]25using HeuristicLab.Data;
26using HeuristicLab.Data.Views;
[3442]27using HeuristicLab.MainForm;
28using HeuristicLab.MainForm.WindowsForms;
29
30namespace HeuristicLab.Problems.DataAnalysis.Views {
[5975]31  [View("Estimated Class Values")]
[5663]32  [Content(typeof(IClassificationSolution))]
[5829]33  public partial class ClassificationSolutionEstimatedClassValuesView : ItemView, IClassificationSolutionEvaluationView {
[6239]34    private const string TARGETVARIABLE_SERIES_NAME = "Target Variable";
[6255]35    private const string ESTIMATEDVALUES_SERIES_NAME = "Estimated Class Values (all)";
[6239]36    private const string ESTIMATEDVALUES_TRAINING_SERIES_NAME = "Estimated Class Values (training)";
37    private const string ESTIMATEDVALUES_TEST_SERIES_NAME = "Estimated Class Values (test)";
[3442]38
[5663]39    public new IClassificationSolution Content {
40      get { return (IClassificationSolution)base.Content; }
[3442]41      set {
42        base.Content = value;
43      }
44    }
45
46    private StringConvertibleMatrixView matrixView;
47
[5663]48    public ClassificationSolutionEstimatedClassValuesView()
[3442]49      : base() {
50      InitializeComponent();
51      matrixView = new StringConvertibleMatrixView();
[5014]52      matrixView.ShowRowsAndColumnsTextBox = false;
53      matrixView.ShowStatisticalInformation = false;
[3442]54      matrixView.Dock = DockStyle.Fill;
55      this.Controls.Add(matrixView);
56    }
57
58    #region events
59    protected override void RegisterContentEvents() {
60      base.RegisterContentEvents();
[5663]61      Content.ModelChanged += new EventHandler(Content_ModelChanged);
[3442]62      Content.ProblemDataChanged += new EventHandler(Content_ProblemDataChanged);
63    }
64
65    protected override void DeregisterContentEvents() {
66      base.DeregisterContentEvents();
[5663]67      Content.ModelChanged -= new EventHandler(Content_ModelChanged);
[3442]68      Content.ProblemDataChanged -= new EventHandler(Content_ProblemDataChanged);
69    }
70
[5663]71    private void Content_ProblemDataChanged(object sender, EventArgs e) {
[3442]72      OnContentChanged();
73    }
74
[5663]75    private void Content_ModelChanged(object sender, EventArgs e) {
[3442]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 {
[6255]87        StringMatrix matrix = null;
[4011]88        if (Content != null) {
[6255]89          string[,] values = new string[Content.ProblemData.Dataset.Rows, 5];
[5014]90
[5663]91          double[] target = Content.ProblemData.Dataset.GetVariableValues(Content.ProblemData.TargetVariable);
[6255]92          double[] estimated = Content.EstimatedClassValues.ToArray();
[5014]93          for (int row = 0; row < target.Length; row++) {
[6255]94            values[row, 0] = row.ToString();
95            values[row, 1] = target[row].ToString();
96            values[row, 2] = estimated[row].ToString();
[5014]97          }
[6255]98
[6239]99          var estimatedTraining = Content.EstimatedTrainingClassValues.GetEnumerator();
100          estimatedTraining.MoveNext();
101          foreach (var trainingRow in Content.ProblemData.TrainingIndizes) {
[6255]102            values[trainingRow, 3] = estimatedTraining.Current.ToString();
[6239]103            estimatedTraining.MoveNext();
104          }
105          var estimatedTest = Content.EstimatedTestClassValues.GetEnumerator();
106          estimatedTest.MoveNext();
107          foreach (var testRow in Content.ProblemData.TestIndizes) {
[6255]108            values[testRow, 4] = estimatedTest.Current.ToString();
[6239]109            estimatedTest.MoveNext();
110          }
[5014]111
[6255]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;
[4011]115        }
116        matrixView.Content = matrix;
[3442]117      }
118    }
119    #endregion
120  }
121}
Note: See TracBrowser for help on using the repository browser.