Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.3/ResultsView.cs @ 4468

Last change on this file since 4468 was 4468, checked in by mkommend, 14 years ago

Preparation for cross validation - removed the test samples from the trainining samples and added ValidationPercentage parameter (ticket #1199).

File size: 4.2 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 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.Collections.Generic;
23using System.Windows.Forms;
24using HeuristicLab.Data;
25using HeuristicLab.MainForm;
26using HeuristicLab.MainForm.WindowsForms;
27using HeuristicLab.Problems.DataAnalysis.Evaluators;
28
29namespace HeuristicLab.Problems.DataAnalysis.Views {
30  [Content(typeof(DataAnalysisSolution), false)]
31  [View("Results View")]
32  public partial class ResultsView : AsynchronousContentView {
33    private List<string> rowNames = new List<string>() { "MeanSquaredError", "CoefficientOfDetermination", "MeanAbsolutePercentageError" };
34    private List<string> columnNames = new List<string>() { "Training", "Test" };
35
36    public ResultsView() {
37      InitializeComponent();
38    }
39
40    public new DataAnalysisSolution Content {
41      get { return (DataAnalysisSolution)base.Content; }
42      set { base.Content = value; }
43    }
44
45    protected override void RegisterContentEvents() {
46      base.RegisterContentEvents();
47      Content.ModelChanged += new EventHandler(Content_ModelChanged);
48      Content.ProblemDataChanged += new EventHandler(Content_ProblemDataChanged);
49      Content.EstimatedValuesChanged += new EventHandler(Content_EstimatedValuesChanged);
50    }
51    protected override void DeregisterContentEvents() {
52      base.DeregisterContentEvents();
53      Content.ModelChanged -= new EventHandler(Content_ModelChanged);
54      Content.ProblemDataChanged -= new EventHandler(Content_ProblemDataChanged);
55      Content.EstimatedValuesChanged -= new EventHandler(Content_EstimatedValuesChanged);
56    }
57
58    private void Content_ModelChanged(object sender, EventArgs e) {
59      UpdateView();
60    }
61    private void Content_ProblemDataChanged(object sender, EventArgs e) {
62      UpdateView();
63    }
64    private void Content_EstimatedValuesChanged(object sender, EventArgs e) {
65      UpdateView();
66    }
67
68    protected override void OnContentChanged() {
69      base.OnContentChanged();
70      UpdateView();
71    }
72    private void UpdateView() {
73      if (Content != null) {
74        DoubleMatrix matrix = new DoubleMatrix(rowNames.Count, columnNames.Count);
75        matrix.RowNames = rowNames;
76        matrix.ColumnNames = columnNames;
77        matrix.SortableView = false;
78
79        IEnumerable<double> originalTrainingValues = Content.ProblemData.Dataset.GetEnumeratedVariableValues(Content.ProblemData.TargetVariable.Value, Content.ProblemData.TrainingIndizes);
80        IEnumerable<double> originalTestValues = Content.ProblemData.Dataset.GetEnumeratedVariableValues(Content.ProblemData.TargetVariable.Value, Content.ProblemData.TestIndizes);
81        matrix[0, 0] = SimpleMSEEvaluator.Calculate(originalTrainingValues, Content.EstimatedTrainingValues);
82        matrix[0, 1] = SimpleMSEEvaluator.Calculate(originalTestValues, Content.EstimatedTestValues);
83        matrix[1, 0] = SimpleRSquaredEvaluator.Calculate(originalTrainingValues, Content.EstimatedTrainingValues);
84        matrix[1, 1] = SimpleRSquaredEvaluator.Calculate(originalTestValues, Content.EstimatedTestValues);
85        matrix[2, 0] = SimpleMeanAbsolutePercentageErrorEvaluator.Calculate(originalTrainingValues, Content.EstimatedTrainingValues);
86        matrix[2, 1] = SimpleMeanAbsolutePercentageErrorEvaluator.Calculate(originalTestValues, Content.EstimatedTestValues);
87
88        matrixView.Content = matrix;
89      } else
90        matrixView.Content = null;
91    }
92  }
93}
Note: See TracBrowser for help on using the repository browser.