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

Last change on this file since 14826 was 14826, checked in by gkronber, 6 months ago

#2650: merged the factors branch into trunk

File size: 4.4 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      this.factorVarReplComboBox.SelectedIndex = 0;
46    }
47
48    #region events
49    protected override void RegisterContentEvents() {
50      base.RegisterContentEvents();
51      Content.ModelChanged += new EventHandler(Content_ModelChanged);
52      Content.ProblemDataChanged += new EventHandler(Content_ProblemDataChanged);
53    }
54
55    protected override void DeregisterContentEvents() {
56      base.DeregisterContentEvents();
57      Content.ModelChanged -= new EventHandler(Content_ModelChanged);
58      Content.ProblemDataChanged -= new EventHandler(Content_ProblemDataChanged);
59    }
60
61    protected virtual void Content_ProblemDataChanged(object sender, EventArgs e) {
62      OnContentChanged();
63    }
64
65    protected virtual void Content_ModelChanged(object sender, EventArgs e) {
66      OnContentChanged();
67    }
68
69    protected override void OnContentChanged() {
70      base.OnContentChanged();
71      if (Content == null) {
72        variableImactsArrayView.Content = null;
73      } else {
74        UpdateVariableImpacts();
75      }
76    }
77
78    private void UpdateVariableImpacts() {
79      if (Content == null || replacementComboBox.SelectedIndex < 0
80        || factorVarReplComboBox.SelectedIndex < 0
81        || dataPartitionComboBox.SelectedIndex < 0) return;
82      var mainForm = (MainForm.WindowsForms.MainForm)MainFormManager.MainForm;
83      variableImactsArrayView.Caption = Content.Name + " Variable Impacts";
84      var replMethod =
85         (RegressionSolutionVariableImpactsCalculator.ReplacementMethodEnum)
86           replacementComboBox.Items[replacementComboBox.SelectedIndex];
87      var factorReplMethod =
88        (RegressionSolutionVariableImpactsCalculator.FactorReplacementMethodEnum)
89          factorVarReplComboBox.Items[factorVarReplComboBox.SelectedIndex];
90      var dataPartition =
91        (RegressionSolutionVariableImpactsCalculator.DataPartitionEnum)dataPartitionComboBox.SelectedItem;
92
93      Task.Factory.StartNew(() => {
94        try {
95          mainForm.AddOperationProgressToView(this, "Calculating variable impacts for " + Content.Name);
96
97          var impacts = RegressionSolutionVariableImpactsCalculator.CalculateImpacts(Content, dataPartition, replMethod, factorReplMethod);
98          var impactArray = new DoubleArray(impacts.Select(i => i.Item2).ToArray());
99          impactArray.ElementNames = impacts.Select(i => i.Item1);
100          variableImactsArrayView.Content = (DoubleArray)impactArray.AsReadOnly();
101        } finally {
102          mainForm.RemoveOperationProgressFromView(this);
103        }
104      });
105    }
106
107    #endregion
108
109    private void dataPartitionComboBox_SelectedIndexChanged(object sender, EventArgs e) {
110      UpdateVariableImpacts();
111    }
112
113    private void replacementComboBox_SelectedIndexChanged(object sender, EventArgs e) {
114      UpdateVariableImpacts();
115    }
116  }
117}
Note: See TracBrowser for help on using the repository browser.