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