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;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.ComponentModel;
|
---|
25 | using System.Drawing;
|
---|
26 | using System.Data;
|
---|
27 | using System.Linq;
|
---|
28 | using System.Text;
|
---|
29 | using System.Windows.Forms;
|
---|
30 | using HeuristicLab.MainForm;
|
---|
31 | using HeuristicLab.MainForm.WindowsForms;
|
---|
32 | using HeuristicLab.Core;
|
---|
33 | using HeuristicLab.Common;
|
---|
34 | using HeuristicLab.Data;
|
---|
35 | using alglib;
|
---|
36 |
|
---|
37 | namespace HeuristicLab.Optimization.Views {
|
---|
38 | [Content(typeof(RunCollection), false)]
|
---|
39 | [View("RunCollection Variable Impact View")]
|
---|
40 | public partial class RunCollectionVariableImpactView : AsynchronousContentView {
|
---|
41 | private const string variableImpactResultName = "Integrated variable frequencies";
|
---|
42 | public RunCollectionVariableImpactView() {
|
---|
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 = CalculateVariableImpactMatrix();
|
---|
80 | }
|
---|
81 |
|
---|
82 | private DoubleMatrix CalculateVariableImpactMatrix() {
|
---|
83 | DoubleMatrix matrix = null;
|
---|
84 | if (Content != null) {
|
---|
85 | List<IRun> runsWithVariables = Content.Where(r => r.Results.ContainsKey(variableImpactResultName)).ToList() ;
|
---|
86 | IEnumerable<DoubleMatrix> variableImpacts = (from run in runsWithVariables
|
---|
87 | select run.Results[variableImpactResultName]).Cast<DoubleMatrix>();
|
---|
88 | List<string> variableNames = (from varImpact in variableImpacts
|
---|
89 | from variableName in varImpact.RowNames
|
---|
90 | select variableName).Distinct().ToList();
|
---|
91 | List<string> statictics = new List<string> { "Mean", "Median", "StdDev", "Significance Mean>0", "Significance Median>0" };
|
---|
92 | List<string> columnNames = runsWithVariables.Select(r => r.Name).ToList();
|
---|
93 | columnNames.AddRange(statictics);
|
---|
94 | int runs = runsWithVariables.Count();
|
---|
95 |
|
---|
96 | matrix = new DoubleMatrix(variableNames.Count, runs + statictics.Count);
|
---|
97 | matrix.SortableView = true;
|
---|
98 | matrix.RowNames = variableNames;
|
---|
99 | matrix.ColumnNames = columnNames;
|
---|
100 |
|
---|
101 | for(int i = 0; i< runsWithVariables.Count; i++) {
|
---|
102 | IRun run = runsWithVariables[i];
|
---|
103 | DoubleMatrix runVariableImpacts = (DoubleMatrix)run.Results[variableImpactResultName];
|
---|
104 | for (int j = 0; j < runVariableImpacts.Rows; j++) {
|
---|
105 | int rowIndex = variableNames.FindIndex(s => s == runVariableImpacts.RowNames.ElementAt(j));
|
---|
106 | matrix[rowIndex, i] = runVariableImpacts[j, 0];
|
---|
107 | }
|
---|
108 | }
|
---|
109 |
|
---|
110 | for (int variableIndex = 0; variableIndex < matrix.Rows; variableIndex++) {
|
---|
111 | List<double> impacts = new List<double>();
|
---|
112 | for (int runIndex = 0; runIndex < runs; runIndex++)
|
---|
113 | impacts.Add(matrix[variableIndex, runIndex]);
|
---|
114 | matrix[variableIndex, runs] = impacts.Average();
|
---|
115 | matrix[variableIndex, runs + 1] = impacts.Median();
|
---|
116 | matrix[variableIndex, runs + 2] = impacts.StandardDeviation();
|
---|
117 | double leftTail = 0; double rightTail = 0; double bothTails = 0;
|
---|
118 | double[] impactsArray = impacts.ToArray();
|
---|
119 | studentttests.studentttest1(ref impactsArray, impactsArray.Length, 0, ref bothTails, ref leftTail, ref rightTail);
|
---|
120 | matrix[variableIndex, runs + 3] = leftTail;
|
---|
121 | wsr.wilcoxonsignedranktest(impacts.ToArray(), impactsArray.Length, 0, ref bothTails, ref leftTail, ref rightTail);
|
---|
122 | matrix[variableIndex, runs + 4] = leftTail;
|
---|
123 | }
|
---|
124 | }
|
---|
125 | return matrix;
|
---|
126 | }
|
---|
127 | }
|
---|
128 | }
|
---|