Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 8833 was 8833, checked in by sforsten, 12 years ago

#1292:

  • removed combo box in TimeframeCorrelationView and added a textbox instead
  • caches are directly in (Timeframe-)FeatureCorrelationView
  • caches use Tuple<> instead of nested dictionaries
  • a control EnhancedStringConvertibleMatrix inherits from StringConvertibleMatrixView to reduce code duplication
  • add interface IDependencyCalculator to several calculators
  • fixed bug: a previous started calculation is cancelled, if a new calculation shall be started and the values are already in the cache
  • fixed bug: if the content is changed, the calculation is cancelled

HeatMap is still used for the dependency representation, because a class is needed which implements IStringConvertibleMatrix and it has a maximum and minimum value.

File size: 4.9 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.Analysis;
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 HeatMap 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.Content = null;
75        dataView.ResetVisibility();
76      }
77    }
78
79    protected virtual bool[] SetInitialVariableVisibility() {
80      bool[] initialVisibility = new bool[Content.Dataset.DoubleVariables.Count()];
81      int i = 0;
82      foreach (var variable in Content.Dataset.DoubleVariables) {
83        initialVisibility[i] = Content.AllowedInputVariables.Contains(variable);
84        i++;
85      }
86      return initialVisibility;
87    }
88
89    protected void CorrelationMeasureComboBox_SelectedChangeCommitted(object sender, System.EventArgs e) {
90      CalculateCorrelation();
91    }
92    protected void PartitionComboBox_SelectedChangeCommitted(object sender, System.EventArgs e) {
93      CalculateCorrelation();
94    }
95
96    protected abstract void CalculateCorrelation();
97    protected abstract void Content_CorrelationCalculationFinished(object sender, FeatureCorrelationCalculator.CorrelationCalculationFinishedArgs e);
98
99    protected void UpdateDataView() {
100      maximumLabel.Text = currentCorrelation.Maximum.ToString();
101      minimumLabel.Text = currentCorrelation.Minimum.ToString();
102
103      currentCorrelation.SortableView = true;
104      dataView.Content = currentCorrelation;
105      dataView.Enabled = true;
106    }
107
108    protected void Content_ProgressCalculation(object sender, ProgressChangedEventArgs e) {
109      if (!CalculatingPanel.Visible && e.ProgressPercentage != HeatMapProgressBar.Maximum) {
110        CalculatingPanel.Show();
111      } else if (e.ProgressPercentage == HeatMapProgressBar.Maximum) {
112        CalculatingPanel.Hide();
113      }
114      HeatMapProgressBar.Value = e.ProgressPercentage;
115    }
116  }
117}
Note: See TracBrowser for help on using the repository browser.