Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2522_RefactorPluginInfrastructure/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/ClassificationSolutionEstimatedClassValuesView.cs @ 16146

Last change on this file since 16146 was 15973, checked in by gkronber, 6 years ago

#2522: merged trunk changes from r13402:15972 to branch resolving conflicts where necessary

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