Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2870_AutoDiff-nuget/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/ClassificationSolutionVariableImpactsView.cs @ 16124

Last change on this file since 16124 was 15638, checked in by bburlacu, 7 years ago

#2884: Implement variable impacts calculation and view for classification solutions.

File size: 4.4 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2018 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;
26
27namespace HeuristicLab.Problems.DataAnalysis.Views {
28  [View("Variable Impacts")]
29  [Content(typeof(IClassificationSolution))]
30  public partial class ClassificationSolutionVariableImpactsView : DataAnalysisSolutionEvaluationView {
31
32    public new IClassificationSolution Content {
33      get { return (IClassificationSolution)base.Content; }
34      set {
35        base.Content = value;
36      }
37    }
38
39    public ClassificationSolutionVariableImpactsView()
40      : base() {
41      InitializeComponent();
42      this.dataPartitionComboBox.SelectedIndex = 0;
43      this.replacementComboBox.SelectedIndex = 0;
44      this.factorVarReplComboBox.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
79        || factorVarReplComboBox.SelectedIndex < 0
80        || dataPartitionComboBox.SelectedIndex < 0) return;
81      var mainForm = (MainForm.WindowsForms.MainForm)MainFormManager.MainForm;
82      variableImactsArrayView.Caption = Content.Name + " Variable Impacts";
83      var replMethod =
84         (ClassificationSolutionVariableImpactsCalculator.ReplacementMethodEnum)
85           replacementComboBox.Items[replacementComboBox.SelectedIndex];
86      var factorReplMethod =
87        (ClassificationSolutionVariableImpactsCalculator.FactorReplacementMethodEnum)
88          factorVarReplComboBox.Items[factorVarReplComboBox.SelectedIndex];
89      var dataPartition =
90        (ClassificationSolutionVariableImpactsCalculator.DataPartitionEnum)dataPartitionComboBox.SelectedItem;
91
92      Task.Factory.StartNew(() => {
93        try {
94          mainForm.AddOperationProgressToView(this, "Calculating variable impacts for " + Content.Name);
95
96          var impacts = ClassificationSolutionVariableImpactsCalculator.CalculateImpacts(Content, dataPartition, replMethod, factorReplMethod);
97          var impactArray = new DoubleArray(impacts.Select(i => i.Item2).ToArray());
98          impactArray.ElementNames = impacts.Select(i => i.Item1);
99          variableImactsArrayView.Content = (DoubleArray)impactArray.AsReadOnly();
100        } finally {
101          mainForm.RemoveOperationProgressFromView(this);
102        }
103      });
104    }
105
106    #endregion
107
108    private void dataPartitionComboBox_SelectedIndexChanged(object sender, EventArgs e) {
109      UpdateVariableImpacts();
110    }
111
112    private void replacementComboBox_SelectedIndexChanged(object sender, EventArgs e) {
113      UpdateVariableImpacts();
114    }
115  }
116}
Note: See TracBrowser for help on using the repository browser.