[8578] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[12009] | 3 | * Copyright (C) 2002-2015 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] | 22 | using System.Collections.Generic;
|
---|
[8578] | 23 | using System.ComponentModel;
|
---|
| 24 | using System.Linq;
|
---|
| 25 | using System.Windows.Forms;
|
---|
[8861] | 26 | using HeuristicLab.Data;
|
---|
[8578] | 27 | using HeuristicLab.MainForm;
|
---|
| 28 | using HeuristicLab.MainForm.WindowsForms;
|
---|
[8833] | 29 | using HeuristicLab.PluginInfrastructure;
|
---|
[8578] | 30 |
|
---|
| 31 | namespace 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();
|
---|
[12199] | 50 | dataView.FormatPattern = "0.000";
|
---|
[8578] | 51 | fcc = new FeatureCorrelationCalculator();
|
---|
[8833] | 52 | var calculators = ApplicationManager.Manager.GetInstances<IDependencyCalculator>();
|
---|
| 53 | var calcList = calculators.OrderBy(c => c.Name).Select(c => new { Name = c.Name, Calculator = c }).ToList();
|
---|
[8880] | 54 | correlationCalcComboBox.ValueMember = "Calculator";
|
---|
| 55 | correlationCalcComboBox.DisplayMember = "Name";
|
---|
| 56 | correlationCalcComboBox.DataSource = calcList;
|
---|
| 57 | correlationCalcComboBox.SelectedItem = calcList.First(c => c.Calculator.GetType().Equals(typeof(PearsonsRDependenceCalculator)));
|
---|
| 58 | partitionComboBox.DataSource = Partitions;
|
---|
| 59 | partitionComboBox.SelectedItem = TRAININGSAMPLES;
|
---|
[11159] | 60 | progressPanel.Visible = false;
|
---|
[8578] | 61 | }
|
---|
| 62 |
|
---|
| 63 | protected override void RegisterContentEvents() {
|
---|
| 64 | base.RegisterContentEvents();
|
---|
[8729] | 65 | fcc.ProgressCalculation += new FeatureCorrelationCalculator.ProgressCalculationHandler(Content_ProgressCalculation);
|
---|
| 66 | fcc.CorrelationCalculationFinished += new FeatureCorrelationCalculator.CorrelationCalculationFinishedHandler(Content_CorrelationCalculationFinished);
|
---|
[8578] | 67 | }
|
---|
| 68 |
|
---|
| 69 | protected override void DeregisterContentEvents() {
|
---|
[8880] | 70 | fcc.CorrelationCalculationFinished -= new FeatureCorrelationCalculator.CorrelationCalculationFinishedHandler(Content_CorrelationCalculationFinished);
|
---|
| 71 | fcc.ProgressCalculation -= new FeatureCorrelationCalculator.ProgressCalculationHandler(Content_ProgressCalculation);
|
---|
[8578] | 72 | base.DeregisterContentEvents();
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | protected override void OnContentChanged() {
|
---|
| 76 | base.OnContentChanged();
|
---|
[8833] | 77 | fcc.TryCancelCalculation();
|
---|
[8578] | 78 | if (Content != null) {
|
---|
| 79 | fcc.ProblemData = Content;
|
---|
| 80 | CalculateCorrelation();
|
---|
| 81 | } else {
|
---|
[11159] | 82 | progressPanel.Visible = false;
|
---|
[8861] | 83 | dataView.Maximum = 0;
|
---|
| 84 | dataView.Minimum = 0;
|
---|
[8833] | 85 | dataView.Content = null;
|
---|
| 86 | dataView.ResetVisibility();
|
---|
[8578] | 87 | }
|
---|
| 88 | }
|
---|
| 89 |
|
---|
[8833] | 90 | protected virtual bool[] SetInitialVariableVisibility() {
|
---|
[8689] | 91 | bool[] initialVisibility = new bool[Content.Dataset.DoubleVariables.Count()];
|
---|
| 92 | int i = 0;
|
---|
| 93 | foreach (var variable in Content.Dataset.DoubleVariables) {
|
---|
| 94 | initialVisibility[i] = Content.AllowedInputVariables.Contains(variable);
|
---|
| 95 | i++;
|
---|
| 96 | }
|
---|
| 97 | return initialVisibility;
|
---|
| 98 | }
|
---|
| 99 |
|
---|
[8578] | 100 | protected void CorrelationMeasureComboBox_SelectedChangeCommitted(object sender, System.EventArgs e) {
|
---|
| 101 | CalculateCorrelation();
|
---|
| 102 | }
|
---|
| 103 | protected void PartitionComboBox_SelectedChangeCommitted(object sender, System.EventArgs e) {
|
---|
| 104 | CalculateCorrelation();
|
---|
| 105 | }
|
---|
| 106 |
|
---|
| 107 | protected abstract void CalculateCorrelation();
|
---|
[8729] | 108 | protected abstract void Content_CorrelationCalculationFinished(object sender, FeatureCorrelationCalculator.CorrelationCalculationFinishedArgs e);
|
---|
[8578] | 109 |
|
---|
[8874] | 110 | protected void UpdateDataView(DoubleMatrix correlation) {
|
---|
[8880] | 111 | IDependencyCalculator calc = (IDependencyCalculator)correlationCalcComboBox.SelectedValue;
|
---|
[8861] | 112 | maximumLabel.Text = calc.Maximum.ToString();
|
---|
| 113 | minimumLabel.Text = calc.Minimum.ToString();
|
---|
[8578] | 114 |
|
---|
[8874] | 115 | correlation.SortableView = true;
|
---|
[8861] | 116 | dataView.Maximum = calc.Maximum;
|
---|
| 117 | dataView.Minimum = calc.Minimum;
|
---|
[12199] | 118 |
|
---|
[8874] | 119 | dataView.Content = correlation;
|
---|
[8833] | 120 | dataView.Enabled = true;
|
---|
[8578] | 121 | }
|
---|
| 122 |
|
---|
| 123 | protected void Content_ProgressCalculation(object sender, ProgressChangedEventArgs e) {
|
---|
[8881] | 124 | if (!progressPanel.Visible && e.ProgressPercentage != progressBar.Maximum) {
|
---|
| 125 | progressPanel.Show();
|
---|
| 126 | } else if (e.ProgressPercentage == progressBar.Maximum) {
|
---|
| 127 | progressPanel.Hide();
|
---|
[8578] | 128 | }
|
---|
[8881] | 129 | progressBar.Value = e.ProgressPercentage;
|
---|
[8578] | 130 | }
|
---|
| 131 | }
|
---|
| 132 | } |
---|