Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.Views/3.3/RunCollectionValidationStatisticsView.cs @ 8607

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

Merged changes from trunk to data analysis exploration branch and added fractional distance metric evaluator. #1142

File size: 6.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
21
22using System.Collections.Generic;
23using System.Linq;
24using System.Windows.Forms;
25using HeuristicLab.Common;
26using HeuristicLab.Data;
27using HeuristicLab.MainForm;
28using HeuristicLab.MainForm.WindowsForms;
29using HeuristicLab.Optimization;
30using System;
31using HeuristicLab.Problems.DataAnalysis.Regression.Symbolic;
32using HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols;
33using HeuristicLab.Problems.DataAnalysis.Evaluators;
34using HeuristicLab.Analysis;
35
36namespace HeuristicLab.Problems.DataAnalysis.Views {
37  [Content(typeof(RunCollection), false)]
38  [View("RunCollection Validation Statistics View")]
39  public partial class RunCollectionValidationStatisticsView : AsynchronousContentView {
40    private const string validationQualityResultName = "Best solution quality table";
41    private const string validationComplexityResultName = "Best solution complexity";
42    public RunCollectionValidationStatisticsView() {
43      InitializeComponent();
44    }
45
46    public new RunCollection Content {
47      get { return (RunCollection)base.Content; }
48      set { base.Content = value; }
49    }
50
51    protected override void RegisterContentEvents() {
52      base.RegisterContentEvents();
53      this.Content.ItemsAdded += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_ItemsAdded);
54      this.Content.ItemsRemoved += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_ItemsRemoved);
55      this.Content.CollectionReset += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_CollectionReset);
56    }
57    protected override void DeregisterContentEvents() {
58      base.RegisterContentEvents();
59      this.Content.ItemsAdded -= new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_ItemsAdded);
60      this.Content.ItemsRemoved -= new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_ItemsRemoved);
61      this.Content.CollectionReset -= new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_CollectionReset);
62    }
63
64    protected override void OnContentChanged() {
65      base.OnContentChanged();
66      this.UpdateData();
67    }
68    private void Content_ItemsAdded(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<IRun> e) {
69      this.UpdateData();
70    }
71    private void Content_ItemsRemoved(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<IRun> e) {
72      this.UpdateData();
73    }
74    private void Content_CollectionReset(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<IRun> e) {
75      this.UpdateData();
76    }
77
78    private void UpdateData() {
79      matrixView.Content = CalculateValidationStatisticsMatrix();
80    }
81
82    private DoubleMatrix CalculateValidationStatisticsMatrix() {
83      DoubleMatrix matrix = null;
84      if (Content != null) {
85        List<IRun> runsWithSolutions = (from run in Content
86                                        where run.Results.ContainsKey(validationComplexityResultName)
87                                        where run.Results.ContainsKey(validationQualityResultName)
88                                        select run)
89                                              .ToList();
90        IList<DataTable> allComplexityTables = (from run in Content
91                                                where run.Results.ContainsKey(validationComplexityResultName)
92                                                select run.Results[validationComplexityResultName])
93                                                      .Cast<DataTable>()
94                                                      .ToList();
95        IList<DataTable> allQualityTables = (from run in Content
96                                             where run.Results.ContainsKey(validationQualityResultName)
97                                             select run.Results[validationQualityResultName])
98                                                   .Cast<DataTable>()
99                                                   .ToList();
100
101        List<string> attributes = new List<string>() {
102          "Best solution size",
103          "Best solution height",
104          "Best solution variables",
105          "Training MSE",
106          "Test MSE",
107          "Training R²",
108          "Test R²"
109        };
110
111        List<string> rowNames = (from run in runsWithSolutions
112                                 select run.Name).ToList();
113
114        matrix = new DoubleMatrix(rowNames.Count, attributes.Count);
115        matrix.SortableView = true;
116        matrix.RowNames = rowNames;
117        matrix.ColumnNames = attributes;
118
119        for (int column = 0; column < attributes.Count; column++) {
120          string attribute = attributes[column];
121          for (int row = 0; row < runsWithSolutions.Count; row++) {
122            if (allComplexityTables[row].Rows.ContainsKey(attribute)) {
123              matrix[row, column] = allComplexityTables[row].Rows[attribute].Values.Last();
124            } else if (allQualityTables[row].Rows.ContainsKey(attribute)) {
125              matrix[row, column] = allQualityTables[row].Rows[attribute].Values.Last();
126            }
127          }
128        }
129
130      }
131      return matrix;
132    }
133  }
134}
Note: See TracBrowser for help on using the repository browser.