[8578] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[16140] | 3 | * Copyright (C) 2002-2018 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 |
|
---|
[8833] | 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
[8578] | 24 | using System.Windows.Forms;
|
---|
| 25 | using HeuristicLab.Data;
|
---|
| 26 | using HeuristicLab.MainForm;
|
---|
| 27 | using HeuristicLab.MainForm.WindowsForms;
|
---|
[8833] | 28 | using HeuristicLab.PluginInfrastructure;
|
---|
[8578] | 29 |
|
---|
| 30 | namespace HeuristicLab.Problems.DataAnalysis.Views {
|
---|
| 31 | [View("Feature Correlation View")]
|
---|
| 32 | [Content(typeof(DataAnalysisProblemData), false)]
|
---|
| 33 | public partial class FeatureCorrelationView : AbstractFeatureCorrelationView {
|
---|
| 34 |
|
---|
| 35 | private FeatureCorrelationCache correlationCache;
|
---|
[13938] | 36 | private new FeatureCorrelationCalculator CorrelationCalculator {
|
---|
| 37 | get { return (FeatureCorrelationCalculator)base.CorrelationCalculator; }
|
---|
| 38 | set { base.CorrelationCalculator = value; }
|
---|
| 39 | }
|
---|
[8578] | 40 |
|
---|
| 41 | public FeatureCorrelationView()
|
---|
| 42 | : base() {
|
---|
| 43 | InitializeComponent();
|
---|
[13938] | 44 | CorrelationCalculator = new FeatureCorrelationCalculator();
|
---|
[8578] | 45 | correlationCache = new FeatureCorrelationCache();
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | protected override void OnContentChanged() {
|
---|
[8833] | 49 | if (Content != null) {
|
---|
[8874] | 50 | dataView.ColumnVisibility = dataView.RowVisibility = SetInitialVariableVisibility();
|
---|
[8833] | 51 | }
|
---|
[8578] | 52 | correlationCache.Reset();
|
---|
| 53 | base.OnContentChanged();
|
---|
| 54 | }
|
---|
| 55 |
|
---|
[13938] | 56 | private void ignoreMissingValuesCheckbox_CheckedChanged(object sender, EventArgs e) {
|
---|
| 57 | CalculateCorrelation();
|
---|
| 58 | }
|
---|
| 59 |
|
---|
[8578] | 60 | protected override void CalculateCorrelation() {
|
---|
[8880] | 61 | if (correlationCalcComboBox.SelectedItem == null) return;
|
---|
| 62 | if (partitionComboBox.SelectedItem == null) return;
|
---|
[8874] | 63 |
|
---|
[8880] | 64 | IDependencyCalculator calc = (IDependencyCalculator)correlationCalcComboBox.SelectedValue;
|
---|
| 65 | string partition = (string)partitionComboBox.SelectedValue;
|
---|
[8874] | 66 | dataView.Enabled = false;
|
---|
[13938] | 67 | double[,] corr = correlationCache.GetCorrelation(calc, partition, ignoreMissingValuesCheckbox.Checked);
|
---|
[8874] | 68 | if (corr == null) {
|
---|
[13938] | 69 | CorrelationCalculator.CalculateElements(Content, calc, partition, ignoreMissingValuesCheckbox.Checked);
|
---|
[8874] | 70 | } else {
|
---|
[13938] | 71 | CorrelationCalculator.TryCancelCalculation();
|
---|
[8874] | 72 | var correlation = new DoubleMatrix(corr, Content.Dataset.DoubleVariables, Content.Dataset.DoubleVariables);
|
---|
| 73 | UpdateDataView(correlation);
|
---|
[8578] | 74 | }
|
---|
| 75 | }
|
---|
| 76 |
|
---|
[13938] | 77 | protected override void FeatureCorrelation_CalculationFinished(object sender, AbstractFeatureCorrelationCalculator.CorrelationCalculationFinishedArgs e) {
|
---|
[8578] | 78 | if (InvokeRequired) {
|
---|
[13938] | 79 | Invoke(new AbstractFeatureCorrelationCalculator.CorrelationCalculationFinishedHandler(FeatureCorrelation_CalculationFinished), sender, e);
|
---|
[8874] | 80 | return;
|
---|
[8578] | 81 | }
|
---|
[13938] | 82 | correlationCache.SetCorrelation(e.Calculcator, e.Partition, e.IgnoreMissingValues, e.Correlation);
|
---|
| 83 |
|
---|
[8874] | 84 | var correlation = new DoubleMatrix(e.Correlation, Content.Dataset.DoubleVariables, Content.Dataset.DoubleVariables);
|
---|
| 85 | UpdateDataView(correlation);
|
---|
[8578] | 86 | }
|
---|
[8689] | 87 |
|
---|
[8833] | 88 | [NonDiscoverableType]
|
---|
| 89 | private class FeatureCorrelationCache : Object {
|
---|
[13938] | 90 | private Dictionary<Tuple<IDependencyCalculator, string, bool>, double[,]> correlationsCache;
|
---|
[8833] | 91 |
|
---|
| 92 | public FeatureCorrelationCache()
|
---|
| 93 | : base() {
|
---|
| 94 | InitializeCaches();
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | private void InitializeCaches() {
|
---|
[13938] | 98 | correlationsCache = new Dictionary<Tuple<IDependencyCalculator, string, bool>, double[,]>();
|
---|
[8833] | 99 | }
|
---|
| 100 |
|
---|
| 101 | public void Reset() {
|
---|
| 102 | InitializeCaches();
|
---|
| 103 | }
|
---|
| 104 |
|
---|
[13938] | 105 | public double[,] GetCorrelation(IDependencyCalculator calc, string partition, bool ignoreMissingValues) {
|
---|
[8833] | 106 | double[,] corr;
|
---|
[13938] | 107 | var key = Tuple.Create(calc, partition, ignoreMissingValues);
|
---|
[8833] | 108 | correlationsCache.TryGetValue(key, out corr);
|
---|
| 109 | return corr;
|
---|
| 110 | }
|
---|
| 111 |
|
---|
[13938] | 112 | public void SetCorrelation(IDependencyCalculator calc, string partition, bool ignoreMissingValues, double[,] correlation) {
|
---|
| 113 | var key = Tuple.Create(calc, partition, ignoreMissingValues);
|
---|
[8833] | 114 | correlationsCache[key] = correlation;
|
---|
| 115 | }
|
---|
[8689] | 116 | }
|
---|
[8578] | 117 | }
|
---|
| 118 | } |
---|