Free cookie consent management tool by TermsFeed Policy Generator

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

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

#1450: implemented support for ensemble solutions for classification.

File size: 4.6 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";
35    private const string ESTIMATEDVALUES_TRAINING_SERIES_NAME = "Estimated Class Values (training)";
36    private const string ESTIMATEDVALUES_TEST_SERIES_NAME = "Estimated Class Values (test)";
[3442]37
[5663]38    public new IClassificationSolution Content {
39      get { return (IClassificationSolution)base.Content; }
[3442]40      set {
41        base.Content = value;
42      }
43    }
44
45    private StringConvertibleMatrixView matrixView;
46
[5663]47    public ClassificationSolutionEstimatedClassValuesView()
[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 {
[4011]86        DoubleMatrix matrix = null;
87        if (Content != null) {
[6239]88          double[,] values = new double[Content.ProblemData.Dataset.Rows, 3];
89          // fill with NaN
90          for (int row = 0; row < Content.ProblemData.Dataset.Rows; row++)
91            for (int column = 0; column < 3; column++)
92              values[row, column] = double.NaN;
[5014]93
[5663]94          double[] target = Content.ProblemData.Dataset.GetVariableValues(Content.ProblemData.TargetVariable);
[5014]95          for (int row = 0; row < target.Length; row++) {
96            values[row, 0] = target[row];
97          }
[6239]98          var estimatedTraining = Content.EstimatedTrainingClassValues.GetEnumerator();
99          estimatedTraining.MoveNext();
100          foreach (var trainingRow in Content.ProblemData.TrainingIndizes) {
101            values[trainingRow, 1] = estimatedTraining.Current;
102            estimatedTraining.MoveNext();
103          }
104          var estimatedTest = Content.EstimatedTestClassValues.GetEnumerator();
105          estimatedTest.MoveNext();
106          foreach (var testRow in Content.ProblemData.TestIndizes) {
107            values[testRow, 2] = estimatedTest.Current;
108            estimatedTest.MoveNext();
109          }
[5014]110
[4011]111          matrix = new DoubleMatrix(values);
[6239]112          matrix.ColumnNames = new string[] { TARGETVARIABLE_SERIES_NAME, ESTIMATEDVALUES_TRAINING_SERIES_NAME, ESTIMATEDVALUES_TEST_SERIES_NAME };
[4011]113        }
114        matrixView.Content = matrix;
[3442]115      }
116    }
117    #endregion
118  }
119}
Note: See TracBrowser for help on using the repository browser.