Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/FeatureCorrelation/AbstractFeatureCorrelationView.cs @ 8874

Last change on this file since 8874 was 8874, checked in by mkommend, 10 years ago

#1292: Minor code cleanup in feature correlation classes.

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
36    public new DataAnalysisProblemData Content {
37      get { return (DataAnalysisProblemData)base.Content; }
38      set { base.Content = value; }
39    }
40
41    protected AbstractFeatureCorrelationView() {
42      InitializeComponent();
43      fcc = new FeatureCorrelationCalculator();
44      var calculators = ApplicationManager.Manager.GetInstances<IDependencyCalculator>();
45      var calcList = calculators.OrderBy(c => c.Name).Select(c => new { Name = c.Name, Calculator = c }).ToList();
46      CorrelationCalcComboBox.ValueMember = "Calculator";
47      CorrelationCalcComboBox.DisplayMember = "Name";
48      CorrelationCalcComboBox.DataSource = calcList;
49      CorrelationCalcComboBox.SelectedItem = calcList.First(c => c.Calculator.GetType().Equals(typeof(PearsonsRDependenceCalculator)));
50      PartitionComboBox.DataSource = FeatureCorrelationPartitions.Partitions;
51      PartitionComboBox.SelectedItem = FeatureCorrelationPartitions.TRAININGSAMPLES;
52    }
53
54    protected override void RegisterContentEvents() {
55      base.RegisterContentEvents();
56      fcc.ProgressCalculation += new FeatureCorrelationCalculator.ProgressCalculationHandler(Content_ProgressCalculation);
57      fcc.CorrelationCalculationFinished += new FeatureCorrelationCalculator.CorrelationCalculationFinishedHandler(Content_CorrelationCalculationFinished);
58    }
59
60    protected override void DeregisterContentEvents() {
61      fcc.CorrelationCalculationFinished += new FeatureCorrelationCalculator.CorrelationCalculationFinishedHandler(Content_CorrelationCalculationFinished);
62      fcc.ProgressCalculation += new FeatureCorrelationCalculator.ProgressCalculationHandler(Content_ProgressCalculation);
63      base.DeregisterContentEvents();
64    }
65
66    protected override void OnContentChanged() {
67      base.OnContentChanged();
68      fcc.TryCancelCalculation();
69      if (Content != null) {
70        fcc.ProblemData = Content;
71        CalculateCorrelation();
72      } else {
73        dataView.Maximum = 0;
74        dataView.Minimum = 0;
75        dataView.Content = null;
76        dataView.ResetVisibility();
77      }
78    }
79
80    protected virtual bool[] SetInitialVariableVisibility() {
81      bool[] initialVisibility = new bool[Content.Dataset.DoubleVariables.Count()];
82      int i = 0;
83      foreach (var variable in Content.Dataset.DoubleVariables) {
84        initialVisibility[i] = Content.AllowedInputVariables.Contains(variable);
85        i++;
86      }
87      return initialVisibility;
88    }
89
90    protected void CorrelationMeasureComboBox_SelectedChangeCommitted(object sender, System.EventArgs e) {
91      CalculateCorrelation();
92    }
93    protected void PartitionComboBox_SelectedChangeCommitted(object sender, System.EventArgs e) {
94      CalculateCorrelation();
95    }
96
97    protected abstract void CalculateCorrelation();
98    protected abstract void Content_CorrelationCalculationFinished(object sender, FeatureCorrelationCalculator.CorrelationCalculationFinishedArgs e);
99
100    protected void UpdateDataView(DoubleMatrix correlation) {
101      IDependencyCalculator calc = (IDependencyCalculator)CorrelationCalcComboBox.SelectedValue;
102      maximumLabel.Text = calc.Maximum.ToString();
103      minimumLabel.Text = calc.Minimum.ToString();
104
105      correlation.SortableView = true;
106      dataView.Maximum = calc.Maximum;
107      dataView.Minimum = calc.Minimum;
108      dataView.Content = correlation;
109      dataView.Enabled = true;
110    }
111
112    protected void Content_ProgressCalculation(object sender, ProgressChangedEventArgs e) {
113      if (!CalculatingPanel.Visible && e.ProgressPercentage != HeatMapProgressBar.Maximum) {
114        CalculatingPanel.Show();
115      } else if (e.ProgressPercentage == HeatMapProgressBar.Maximum) {
116        CalculatingPanel.Hide();
117      }
118      HeatMapProgressBar.Value = e.ProgressPercentage;
119    }
120  }
121}
Note: See TracBrowser for help on using the repository browser.