[14348] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2016 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 | using System;
|
---|
| 22 | using System.Linq;
|
---|
| 23 | using System.Threading.Tasks;
|
---|
| 24 | using HeuristicLab.Data;
|
---|
| 25 | using HeuristicLab.MainForm;
|
---|
| 26 |
|
---|
| 27 | namespace HeuristicLab.Problems.DataAnalysis.Views {
|
---|
| 28 | [View("Variable Impacts")]
|
---|
| 29 | [Content(typeof(IRegressionSolution))]
|
---|
| 30 | public partial class RegressionSolutionVariableImpactsView : DataAnalysisSolutionEvaluationView {
|
---|
| 31 |
|
---|
| 32 | public new IRegressionSolution Content {
|
---|
| 33 | get { return (IRegressionSolution)base.Content; }
|
---|
| 34 | set {
|
---|
| 35 | base.Content = value;
|
---|
| 36 | }
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | public RegressionSolutionVariableImpactsView()
|
---|
| 40 | : base() {
|
---|
| 41 | InitializeComponent();
|
---|
| 42 | this.dataPartitionComboBox.SelectedIndex = 0;
|
---|
| 43 | this.replacementComboBox.SelectedIndex = 0;
|
---|
[14826] | 44 | this.factorVarReplComboBox.SelectedIndex = 0;
|
---|
[14348] | 45 | }
|
---|
| 46 |
|
---|
| 47 | #region events
|
---|
| 48 | protected override void RegisterContentEvents() {
|
---|
| 49 | base.RegisterContentEvents();
|
---|
| 50 | Content.ModelChanged += new EventHandler(Content_ModelChanged);
|
---|
| 51 | Content.ProblemDataChanged += new EventHandler(Content_ProblemDataChanged);
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | protected override void DeregisterContentEvents() {
|
---|
| 55 | base.DeregisterContentEvents();
|
---|
| 56 | Content.ModelChanged -= new EventHandler(Content_ModelChanged);
|
---|
| 57 | Content.ProblemDataChanged -= new EventHandler(Content_ProblemDataChanged);
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | protected virtual void Content_ProblemDataChanged(object sender, EventArgs e) {
|
---|
| 61 | OnContentChanged();
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | protected virtual void Content_ModelChanged(object sender, EventArgs e) {
|
---|
| 65 | OnContentChanged();
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | protected override void OnContentChanged() {
|
---|
| 69 | base.OnContentChanged();
|
---|
| 70 | if (Content == null) {
|
---|
| 71 | variableImactsArrayView.Content = null;
|
---|
| 72 | } else {
|
---|
| 73 | UpdateVariableImpacts();
|
---|
| 74 | }
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | private void UpdateVariableImpacts() {
|
---|
[14826] | 78 | if (Content == null || replacementComboBox.SelectedIndex < 0
|
---|
| 79 | || factorVarReplComboBox.SelectedIndex < 0
|
---|
| 80 | || dataPartitionComboBox.SelectedIndex < 0) return;
|
---|
[14348] | 81 | variableImactsArrayView.Caption = Content.Name + " Variable Impacts";
|
---|
| 82 | var replMethod =
|
---|
[14826] | 83 | (RegressionSolutionVariableImpactsCalculator.ReplacementMethodEnum)
|
---|
| 84 | replacementComboBox.Items[replacementComboBox.SelectedIndex];
|
---|
| 85 | var factorReplMethod =
|
---|
| 86 | (RegressionSolutionVariableImpactsCalculator.FactorReplacementMethodEnum)
|
---|
| 87 | factorVarReplComboBox.Items[factorVarReplComboBox.SelectedIndex];
|
---|
[14348] | 88 | var dataPartition =
|
---|
| 89 | (RegressionSolutionVariableImpactsCalculator.DataPartitionEnum)dataPartitionComboBox.SelectedItem;
|
---|
| 90 |
|
---|
| 91 | Task.Factory.StartNew(() => {
|
---|
| 92 | try {
|
---|
[15477] | 93 | Progress.ShowMarquee(this, "Calculating variable impacts for " + Content.Name);
|
---|
[14348] | 94 |
|
---|
[14826] | 95 | var impacts = RegressionSolutionVariableImpactsCalculator.CalculateImpacts(Content, dataPartition, replMethod, factorReplMethod);
|
---|
[14348] | 96 | var impactArray = new DoubleArray(impacts.Select(i => i.Item2).ToArray());
|
---|
| 97 | impactArray.ElementNames = impacts.Select(i => i.Item1);
|
---|
| 98 | variableImactsArrayView.Content = (DoubleArray)impactArray.AsReadOnly();
|
---|
| 99 | } finally {
|
---|
[15477] | 100 | Progress.Hide(this);
|
---|
[14348] | 101 | }
|
---|
| 102 | });
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | #endregion
|
---|
| 106 |
|
---|
| 107 | private void dataPartitionComboBox_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
| 108 | UpdateVariableImpacts();
|
---|
| 109 | }
|
---|
| 110 |
|
---|
| 111 | private void replacementComboBox_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
| 112 | UpdateVariableImpacts();
|
---|
| 113 | }
|
---|
| 114 | }
|
---|
| 115 | }
|
---|