Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.MultiVariate.Views/3.3/ResultsView.cs @ 6318

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

Added classes and views for analysis of symbolic time series prognosis results. #1142

File size: 5.0 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;
34using HeuristicLab.Problems.DataAnalysis.VectorRegression;
35
36namespace HeuristicLab.Problems.DataAnalysis.VectorRegression.Views {
37  [Content(typeof(IMultiTargetRegressionSolution), false)]
38  [View("Multi-target Results View")]
39  public partial class ResultsView : AsynchronousContentView {
40    private List<string> rowNames = new List<string>() {
41      "Mean squared error (training)", "Mean squared error (test)",
42      "Pearson's R² (training)", "Pearson's R² (test)",
43      "Mean relative error (training)", "Mean relative error (test)" };
44
45    public ResultsView() {
46      InitializeComponent();
47    }
48
49    public new IMultiTargetRegressionSolution Content {
50      get { return (IMultiTargetRegressionSolution)base.Content; }
51      set { base.Content = value; }
52    }
53
54    protected override void RegisterContentEvents() {
55      base.RegisterContentEvents();
56      //Content.ModelChanged += new EventHandler(Content_ModelChanged);
57      //Content.ProblemDataChanged += new EventHandler(Content_ProblemDataChanged);
58      //Content.EstimatedValuesChanged += new EventHandler(Content_EstimatedValuesChanged);
59    }
60    protected override void DeregisterContentEvents() {
61      base.DeregisterContentEvents();
62      //Content.ModelChanged -= new EventHandler(Content_ModelChanged);
63      //Content.ProblemDataChanged -= new EventHandler(Content_ProblemDataChanged);
64      //Content.EstimatedValuesChanged -= new EventHandler(Content_EstimatedValuesChanged);
65    }
66
67    private void Content_ModelChanged(object sender, EventArgs e) {
68      UpdateView();
69    }
70    private void Content_ProblemDataChanged(object sender, EventArgs e) {
71      UpdateView();
72    }
73    private void Content_EstimatedValuesChanged(object sender, EventArgs e) {
74      UpdateView();
75    }
76
77    protected override void OnContentChanged() {
78      base.OnContentChanged();
79      UpdateView();
80    }
81    private void UpdateView() {
82      if (Content != null) {
83        DoubleMatrix matrix = new DoubleMatrix(rowNames.Count, Content.TargetVariables.Count());
84        matrix.RowNames = rowNames;
85        matrix.ColumnNames = Content.TargetVariables;
86        matrix.SortableView = false;
87
88        int columnIndex = 0;
89        foreach (string targetVariable in Content.TargetVariables) {
90          DataAnalysisSolution targetVariableSolution = Content.GetModelFor(targetVariable);
91
92          IEnumerable<double> originalTrainingValues = targetVariableSolution.ProblemData.Dataset.GetVariableValues(targetVariable, targetVariableSolution.ProblemData.TrainingSamplesStart.Value, targetVariableSolution.ProblemData.TrainingSamplesEnd.Value);
93          IEnumerable<double> originalTestValues = targetVariableSolution.ProblemData.Dataset.GetVariableValues(targetVariable, targetVariableSolution.ProblemData.TestSamplesStart.Value, targetVariableSolution.ProblemData.TestSamplesEnd.Value);
94
95          matrix[0, columnIndex] = SimpleMSEEvaluator.Calculate(originalTrainingValues, targetVariableSolution.EstimatedTrainingValues);
96          matrix[1, columnIndex] = SimpleMSEEvaluator.Calculate(originalTestValues, targetVariableSolution.EstimatedTestValues);
97          matrix[2, columnIndex] = SimpleRSquaredEvaluator.Calculate(originalTrainingValues, targetVariableSolution.EstimatedTrainingValues);
98          matrix[3, columnIndex] = SimpleRSquaredEvaluator.Calculate(originalTestValues, targetVariableSolution.EstimatedTestValues);
99          matrix[4, columnIndex] = SimpleMeanAbsolutePercentageErrorEvaluator.Calculate(originalTrainingValues, targetVariableSolution.EstimatedTrainingValues);
100          matrix[5, columnIndex] = SimpleMeanAbsolutePercentageErrorEvaluator.Calculate(originalTestValues, targetVariableSolution.EstimatedTestValues);
101          columnIndex++;
102        }
103
104        matrixView.Content = matrix;
105      } else
106        matrixView.Content = null;
107    }
108  }
109}
Note: See TracBrowser for help on using the repository browser.