Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionVariableImpactsView.cs @ 14778

Last change on this file since 14778 was 14348, checked in by gkronber, 8 years ago

#2673: removed button for variable impacts calculation and implemented a separate SolutionView instead. Fixed a bug in Regression/RegressionSolutionVariableImpactsCalculator

File size: 4.1 KB
Line 
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
21using System;
22using System.Linq;
23using System.Threading.Tasks;
24using HeuristicLab.Data;
25using HeuristicLab.MainForm;
26using HeuristicLab.Problems.DataAnalysis.Symbolic.Regression;
27
28namespace HeuristicLab.Problems.DataAnalysis.Views {
29  [View("Variable Impacts")]
30  [Content(typeof(IRegressionSolution))]
31  public partial class RegressionSolutionVariableImpactsView : DataAnalysisSolutionEvaluationView {
32
33    public new IRegressionSolution Content {
34      get { return (IRegressionSolution)base.Content; }
35      set {
36        base.Content = value;
37      }
38    }
39
40    public RegressionSolutionVariableImpactsView()
41      : base() {
42      InitializeComponent();
43      this.dataPartitionComboBox.SelectedIndex = 0;
44      this.replacementComboBox.SelectedIndex = 0;
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() {
78      if (Content == null || replacementComboBox.SelectedIndex < 0 || dataPartitionComboBox.SelectedIndex < 0) return;
79      var mainForm = (MainForm.WindowsForms.MainForm)MainFormManager.MainForm;
80      variableImactsArrayView.Caption = Content.Name + " Variable Impacts";
81      var replMethod =
82         (RegressionSolutionVariableImpactsCalculator.ReplacementMethodEnum)replacementComboBox.Items[replacementComboBox.SelectedIndex];
83      var dataPartition =
84        (RegressionSolutionVariableImpactsCalculator.DataPartitionEnum)dataPartitionComboBox.SelectedItem;
85
86      Task.Factory.StartNew(() => {
87        try {
88          mainForm.AddOperationProgressToView(this, "Calculating variable impacts for " + Content.Name);
89
90          var impacts = RegressionSolutionVariableImpactsCalculator.CalculateImpacts(Content, dataPartition, replMethod);
91          var impactArray = new DoubleArray(impacts.Select(i => i.Item2).ToArray());
92          impactArray.ElementNames = impacts.Select(i => i.Item1);
93          variableImactsArrayView.Content = (DoubleArray)impactArray.AsReadOnly();
94        } finally {
95          mainForm.RemoveOperationProgressFromView(this);
96        }
97      });
98    }
99
100    #endregion
101
102    private void dataPartitionComboBox_SelectedIndexChanged(object sender, EventArgs e) {
103      UpdateVariableImpacts();
104    }
105
106    private void replacementComboBox_SelectedIndexChanged(object sender, EventArgs e) {
107      UpdateVariableImpacts();
108    }
109  }
110}
Note: See TracBrowser for help on using the repository browser.