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