1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2016 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 |
|
---|
22 | using System.Collections.Generic;
|
---|
23 | using System.ComponentModel;
|
---|
24 | using System.Linq;
|
---|
25 | using System.Windows.Forms;
|
---|
26 | using HeuristicLab.Data;
|
---|
27 | using HeuristicLab.MainForm;
|
---|
28 | using HeuristicLab.MainForm.WindowsForms;
|
---|
29 | using HeuristicLab.PluginInfrastructure;
|
---|
30 |
|
---|
31 | namespace HeuristicLab.Problems.DataAnalysis.Views {
|
---|
32 | [View("Feature Correlation View")]
|
---|
33 | [Content(typeof(DataAnalysisProblemData), false)]
|
---|
34 | public abstract partial class AbstractFeatureCorrelationView : AsynchronousContentView {
|
---|
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 }.AsReadOnly();
|
---|
40 |
|
---|
41 | protected AbstractFeatureCorrelationCalculator CorrelationCalculator { get; set; }
|
---|
42 |
|
---|
43 | public new DataAnalysisProblemData Content {
|
---|
44 | get { return (DataAnalysisProblemData)base.Content; }
|
---|
45 | set { base.Content = value; }
|
---|
46 | }
|
---|
47 |
|
---|
48 | protected AbstractFeatureCorrelationView() {
|
---|
49 | InitializeComponent();
|
---|
50 | dataView.FormatPattern = "0.000";
|
---|
51 | var calculators = ApplicationManager.Manager.GetInstances<IDependencyCalculator>();
|
---|
52 | var calcList = calculators.OrderBy(c => c.Name).Select(c => new { Name = c.Name, Calculator = c }).ToList();
|
---|
53 | correlationCalcComboBox.ValueMember = "Calculator";
|
---|
54 | correlationCalcComboBox.DisplayMember = "Name";
|
---|
55 | correlationCalcComboBox.DataSource = calcList;
|
---|
56 | correlationCalcComboBox.SelectedItem = calcList.First(c => c.Calculator.GetType() == typeof(PearsonsRDependenceCalculator));
|
---|
57 | partitionComboBox.DataSource = Partitions;
|
---|
58 | partitionComboBox.SelectedItem = TRAININGSAMPLES;
|
---|
59 | progressPanel.Visible = false;
|
---|
60 | }
|
---|
61 |
|
---|
62 | protected override void OnClosing(FormClosingEventArgs e) {
|
---|
63 | base.OnClosing(e);
|
---|
64 | CorrelationCalculator.TryCancelCalculation();
|
---|
65 | }
|
---|
66 |
|
---|
67 | protected override void RegisterContentEvents() {
|
---|
68 | base.RegisterContentEvents();
|
---|
69 | CorrelationCalculator.ProgressChanged += FeatureCorrelation_ProgressChanged;
|
---|
70 | CorrelationCalculator.CorrelationCalculationFinished += FeatureCorrelation_CalculationFinished;
|
---|
71 | }
|
---|
72 |
|
---|
73 | protected override void DeregisterContentEvents() {
|
---|
74 | CorrelationCalculator.ProgressChanged -= FeatureCorrelation_ProgressChanged;
|
---|
75 | CorrelationCalculator.CorrelationCalculationFinished -= FeatureCorrelation_CalculationFinished;
|
---|
76 | base.DeregisterContentEvents();
|
---|
77 | }
|
---|
78 |
|
---|
79 | protected override void OnContentChanged() {
|
---|
80 | base.OnContentChanged();
|
---|
81 | CorrelationCalculator.TryCancelCalculation();
|
---|
82 | if (Content != null) {
|
---|
83 | CalculateCorrelation();
|
---|
84 | } else {
|
---|
85 | progressPanel.Visible = false;
|
---|
86 | dataView.Maximum = 0;
|
---|
87 | dataView.Minimum = 0;
|
---|
88 | dataView.Content = null;
|
---|
89 | dataView.ResetVisibility();
|
---|
90 | }
|
---|
91 | }
|
---|
92 |
|
---|
93 | protected virtual bool[] SetInitialVariableVisibility() {
|
---|
94 | bool[] initialVisibility = new bool[Content.Dataset.DoubleVariables.Count()];
|
---|
95 | int i = 0;
|
---|
96 | foreach (var variable in Content.Dataset.DoubleVariables) {
|
---|
97 | initialVisibility[i] = Content.AllowedInputVariables.Contains(variable);
|
---|
98 | i++;
|
---|
99 | }
|
---|
100 | return initialVisibility;
|
---|
101 | }
|
---|
102 |
|
---|
103 | protected void CorrelationMeasureComboBox_SelectedChangeCommitted(object sender, System.EventArgs e) {
|
---|
104 | CalculateCorrelation();
|
---|
105 | }
|
---|
106 | protected void PartitionComboBox_SelectedChangeCommitted(object sender, System.EventArgs e) {
|
---|
107 | CalculateCorrelation();
|
---|
108 | }
|
---|
109 |
|
---|
110 | protected abstract void CalculateCorrelation();
|
---|
111 |
|
---|
112 | protected abstract void FeatureCorrelation_CalculationFinished(object sender,
|
---|
113 | AbstractFeatureCorrelationCalculator.CorrelationCalculationFinishedArgs e);
|
---|
114 |
|
---|
115 | protected void UpdateDataView(DoubleMatrix correlation) {
|
---|
116 | IDependencyCalculator calc = (IDependencyCalculator)correlationCalcComboBox.SelectedValue;
|
---|
117 | maximumLabel.Text = calc.Maximum.ToString();
|
---|
118 | minimumLabel.Text = calc.Minimum.ToString();
|
---|
119 |
|
---|
120 | correlation.SortableView = true;
|
---|
121 | dataView.Maximum = calc.Maximum;
|
---|
122 | dataView.Minimum = calc.Minimum;
|
---|
123 |
|
---|
124 | dataView.Content = correlation;
|
---|
125 | dataView.Enabled = true;
|
---|
126 | }
|
---|
127 |
|
---|
128 | protected void FeatureCorrelation_ProgressChanged(object sender, ProgressChangedEventArgs e) {
|
---|
129 | if (!progressPanel.Visible && e.ProgressPercentage != progressBar.Maximum) {
|
---|
130 | progressPanel.Show();
|
---|
131 | } else if (e.ProgressPercentage == progressBar.Maximum) {
|
---|
132 | progressPanel.Hide();
|
---|
133 | }
|
---|
134 | progressBar.Value = e.ProgressPercentage;
|
---|
135 | }
|
---|
136 | }
|
---|
137 | } |
---|