Free cookie consent management tool by TermsFeed Policy Generator

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

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

corrected DataAnalysis.Views.ResultsView to use an internal DoubleMatrix (ticket #1020)

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