Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ClassificationModelComparison/HeuristicLab.Problems.DataAnalysis.Views/3.4/FeatureCorrelation/AbstractFeatureCorrelationView.cs @ 10556

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

#1998: Updated classification model comparison branch with trunk changes (remaining changes).

File size: 5.3 KB
RevLine 
[8578]1#region License Information
2/* HeuristicLab
[10556]3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[8578]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
[8880]22using System.Collections.Generic;
[8578]23using System.ComponentModel;
24using System.Linq;
25using System.Windows.Forms;
[8861]26using HeuristicLab.Data;
[8578]27using HeuristicLab.MainForm;
28using HeuristicLab.MainForm.WindowsForms;
[8833]29using HeuristicLab.PluginInfrastructure;
[8578]30
31namespace HeuristicLab.Problems.DataAnalysis.Views {
32  [View("Feature Correlation View")]
33  [Content(typeof(DataAnalysisProblemData), false)]
34  public abstract partial class AbstractFeatureCorrelationView : AsynchronousContentView {
[8880]35    public const string ALLSAMPLES = "All Samples";
36    public const string TRAININGSAMPLES = "Training Samples";
37    public const string TESTSAMPLES = "Test Samples";
38
39    public static readonly IList<string> Partitions = new List<string>() { ALLSAMPLES, TRAININGSAMPLES, TESTSAMPLES };
40
[8578]41    protected FeatureCorrelationCalculator fcc;
42
43    public new DataAnalysisProblemData Content {
44      get { return (DataAnalysisProblemData)base.Content; }
45      set { base.Content = value; }
46    }
47
[8729]48    protected AbstractFeatureCorrelationView() {
[8578]49      InitializeComponent();
50      fcc = new FeatureCorrelationCalculator();
[8833]51      var calculators = ApplicationManager.Manager.GetInstances<IDependencyCalculator>();
52      var calcList = calculators.OrderBy(c => c.Name).Select(c => new { Name = c.Name, Calculator = c }).ToList();
[8880]53      correlationCalcComboBox.ValueMember = "Calculator";
54      correlationCalcComboBox.DisplayMember = "Name";
55      correlationCalcComboBox.DataSource = calcList;
56      correlationCalcComboBox.SelectedItem = calcList.First(c => c.Calculator.GetType().Equals(typeof(PearsonsRDependenceCalculator)));
57      partitionComboBox.DataSource = Partitions;
58      partitionComboBox.SelectedItem = TRAININGSAMPLES;
[8578]59    }
60
61    protected override void RegisterContentEvents() {
62      base.RegisterContentEvents();
[8729]63      fcc.ProgressCalculation += new FeatureCorrelationCalculator.ProgressCalculationHandler(Content_ProgressCalculation);
64      fcc.CorrelationCalculationFinished += new FeatureCorrelationCalculator.CorrelationCalculationFinishedHandler(Content_CorrelationCalculationFinished);
[8578]65    }
66
67    protected override void DeregisterContentEvents() {
[8880]68      fcc.CorrelationCalculationFinished -= new FeatureCorrelationCalculator.CorrelationCalculationFinishedHandler(Content_CorrelationCalculationFinished);
69      fcc.ProgressCalculation -= new FeatureCorrelationCalculator.ProgressCalculationHandler(Content_ProgressCalculation);
[8578]70      base.DeregisterContentEvents();
71    }
72
73    protected override void OnContentChanged() {
74      base.OnContentChanged();
[8833]75      fcc.TryCancelCalculation();
[8578]76      if (Content != null) {
77        fcc.ProblemData = Content;
78        CalculateCorrelation();
79      } else {
[8861]80        dataView.Maximum = 0;
81        dataView.Minimum = 0;
[8833]82        dataView.Content = null;
83        dataView.ResetVisibility();
[8578]84      }
85    }
86
[8833]87    protected virtual bool[] SetInitialVariableVisibility() {
[8689]88      bool[] initialVisibility = new bool[Content.Dataset.DoubleVariables.Count()];
89      int i = 0;
90      foreach (var variable in Content.Dataset.DoubleVariables) {
91        initialVisibility[i] = Content.AllowedInputVariables.Contains(variable);
92        i++;
93      }
94      return initialVisibility;
95    }
96
[8578]97    protected void CorrelationMeasureComboBox_SelectedChangeCommitted(object sender, System.EventArgs e) {
98      CalculateCorrelation();
99    }
100    protected void PartitionComboBox_SelectedChangeCommitted(object sender, System.EventArgs e) {
101      CalculateCorrelation();
102    }
103
104    protected abstract void CalculateCorrelation();
[8729]105    protected abstract void Content_CorrelationCalculationFinished(object sender, FeatureCorrelationCalculator.CorrelationCalculationFinishedArgs e);
[8578]106
[8874]107    protected void UpdateDataView(DoubleMatrix correlation) {
[8880]108      IDependencyCalculator calc = (IDependencyCalculator)correlationCalcComboBox.SelectedValue;
[8861]109      maximumLabel.Text = calc.Maximum.ToString();
110      minimumLabel.Text = calc.Minimum.ToString();
[8578]111
[8874]112      correlation.SortableView = true;
[8861]113      dataView.Maximum = calc.Maximum;
114      dataView.Minimum = calc.Minimum;
[8874]115      dataView.Content = correlation;
[8833]116      dataView.Enabled = true;
[8578]117    }
118
119    protected void Content_ProgressCalculation(object sender, ProgressChangedEventArgs e) {
[8881]120      if (!progressPanel.Visible && e.ProgressPercentage != progressBar.Maximum) {
121        progressPanel.Show();
122      } else if (e.ProgressPercentage == progressBar.Maximum) {
123        progressPanel.Hide();
[8578]124      }
[8881]125      progressBar.Value = e.ProgressPercentage;
[8578]126    }
127  }
128}
Note: See TracBrowser for help on using the repository browser.