Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis.Views/3.4/FeatureCorrelation/AbstractFeatureCorrelationView.cs @ 8863

Last change on this file since 8863 was 8863, checked in by sforsten, 11 years ago

#1776:

  • merged r8810:8862 from trunk into branch
  • fixed exception in ClassificationEnsembleSolutionAccuracyToCoveredSamples, if no estimated values are in a partition, so nothing can be shown
File size: 5.1 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 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
22using System.ComponentModel;
23using System.Linq;
24using System.Windows.Forms;
25using HeuristicLab.Data;
26using HeuristicLab.MainForm;
27using HeuristicLab.MainForm.WindowsForms;
28using HeuristicLab.PluginInfrastructure;
29
30namespace HeuristicLab.Problems.DataAnalysis.Views {
31  [View("Feature Correlation View")]
32  [Content(typeof(DataAnalysisProblemData), false)]
33  public abstract partial class AbstractFeatureCorrelationView : AsynchronousContentView {
34    protected FeatureCorrelationCalculator fcc;
35    protected DoubleMatrix currentCorrelation;
36
37    public new DataAnalysisProblemData Content {
38      get { return (DataAnalysisProblemData)base.Content; }
39      set { base.Content = value; }
40    }
41
42    protected AbstractFeatureCorrelationView() {
43      InitializeComponent();
44      fcc = new FeatureCorrelationCalculator();
45      var calculators = ApplicationManager.Manager.GetInstances<IDependencyCalculator>();
46      var calcList = calculators.OrderBy(c => c.Name).Select(c => new { Name = c.Name, Calculator = c }).ToList();
47      CorrelationCalcComboBox.ValueMember = "Calculator";
48      CorrelationCalcComboBox.DisplayMember = "Name";
49      CorrelationCalcComboBox.DataSource = calcList;
50      CorrelationCalcComboBox.SelectedItem = calcList.First(c => c.Calculator.GetType().Equals(typeof(PearsonsRDependenceCalculator)));
51      PartitionComboBox.DataSource = FeatureCorrelationPartitions.Partitions;
52      PartitionComboBox.SelectedItem = FeatureCorrelationPartitions.TRAININGSAMPLES;
53    }
54
55    protected override void RegisterContentEvents() {
56      base.RegisterContentEvents();
57      fcc.ProgressCalculation += new FeatureCorrelationCalculator.ProgressCalculationHandler(Content_ProgressCalculation);
58      fcc.CorrelationCalculationFinished += new FeatureCorrelationCalculator.CorrelationCalculationFinishedHandler(Content_CorrelationCalculationFinished);
59    }
60
61    protected override void DeregisterContentEvents() {
62      fcc.CorrelationCalculationFinished += new FeatureCorrelationCalculator.CorrelationCalculationFinishedHandler(Content_CorrelationCalculationFinished);
63      fcc.ProgressCalculation += new FeatureCorrelationCalculator.ProgressCalculationHandler(Content_ProgressCalculation);
64      base.DeregisterContentEvents();
65    }
66
67    protected override void OnContentChanged() {
68      base.OnContentChanged();
69      fcc.TryCancelCalculation();
70      if (Content != null) {
71        fcc.ProblemData = Content;
72        CalculateCorrelation();
73      } else {
74        dataView.Maximum = 0;
75        dataView.Minimum = 0;
76        dataView.Content = null;
77        dataView.ResetVisibility();
78      }
79    }
80
81    protected virtual bool[] SetInitialVariableVisibility() {
82      bool[] initialVisibility = new bool[Content.Dataset.DoubleVariables.Count()];
83      int i = 0;
84      foreach (var variable in Content.Dataset.DoubleVariables) {
85        initialVisibility[i] = Content.AllowedInputVariables.Contains(variable);
86        i++;
87      }
88      return initialVisibility;
89    }
90
91    protected void CorrelationMeasureComboBox_SelectedChangeCommitted(object sender, System.EventArgs e) {
92      CalculateCorrelation();
93    }
94    protected void PartitionComboBox_SelectedChangeCommitted(object sender, System.EventArgs e) {
95      CalculateCorrelation();
96    }
97
98    protected abstract void CalculateCorrelation();
99    protected abstract void Content_CorrelationCalculationFinished(object sender, FeatureCorrelationCalculator.CorrelationCalculationFinishedArgs e);
100
101    protected void UpdateDataView() {
102      IDependencyCalculator calc = (IDependencyCalculator)CorrelationCalcComboBox.SelectedValue;
103      maximumLabel.Text = calc.Maximum.ToString();
104      minimumLabel.Text = calc.Minimum.ToString();
105
106      currentCorrelation.SortableView = true;
107      dataView.Maximum = calc.Maximum;
108      dataView.Minimum = calc.Minimum;
109      dataView.Content = currentCorrelation;
110      dataView.Enabled = true;
111    }
112
113    protected void Content_ProgressCalculation(object sender, ProgressChangedEventArgs e) {
114      if (!CalculatingPanel.Visible && e.ProgressPercentage != HeatMapProgressBar.Maximum) {
115        CalculatingPanel.Show();
116      } else if (e.ProgressPercentage == HeatMapProgressBar.Maximum) {
117        CalculatingPanel.Hide();
118      }
119      HeatMapProgressBar.Value = e.ProgressPercentage;
120    }
121  }
122}
Note: See TracBrowser for help on using the repository browser.