1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2015 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;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.Windows.Forms;
|
---|
25 | using HeuristicLab.Data;
|
---|
26 | using HeuristicLab.MainForm;
|
---|
27 | using HeuristicLab.MainForm.WindowsForms;
|
---|
28 | using HeuristicLab.PluginInfrastructure;
|
---|
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;
|
---|
36 |
|
---|
37 | public FeatureCorrelationView()
|
---|
38 | : base() {
|
---|
39 | InitializeComponent();
|
---|
40 | correlationCache = new FeatureCorrelationCache();
|
---|
41 | }
|
---|
42 |
|
---|
43 | protected override void OnContentChanged() {
|
---|
44 | if (Content != null) {
|
---|
45 | dataView.ColumnVisibility = dataView.RowVisibility = SetInitialVariableVisibility();
|
---|
46 | }
|
---|
47 | correlationCache.Reset();
|
---|
48 | base.OnContentChanged();
|
---|
49 | }
|
---|
50 |
|
---|
51 | protected override void CalculateCorrelation() {
|
---|
52 | if (correlationCalcComboBox.SelectedItem == null) return;
|
---|
53 | if (partitionComboBox.SelectedItem == null) return;
|
---|
54 |
|
---|
55 | IDependencyCalculator calc = (IDependencyCalculator)correlationCalcComboBox.SelectedValue;
|
---|
56 | string partition = (string)partitionComboBox.SelectedValue;
|
---|
57 | dataView.Enabled = false;
|
---|
58 | double[,] corr = correlationCache.GetCorrelation(calc, partition);
|
---|
59 | if (corr == null) {
|
---|
60 | fcc.CalculateElements(calc, partition);
|
---|
61 | } else {
|
---|
62 | fcc.TryCancelCalculation();
|
---|
63 | var correlation = new DoubleMatrix(corr, Content.Dataset.DoubleVariables, Content.Dataset.DoubleVariables);
|
---|
64 | UpdateDataView(correlation);
|
---|
65 | }
|
---|
66 | }
|
---|
67 |
|
---|
68 |
|
---|
69 |
|
---|
70 | protected override void Content_CorrelationCalculationFinished(object sender, FeatureCorrelationCalculator.CorrelationCalculationFinishedArgs e) {
|
---|
71 | if (InvokeRequired) {
|
---|
72 | Invoke(new FeatureCorrelationCalculator.CorrelationCalculationFinishedHandler(Content_CorrelationCalculationFinished), sender, e);
|
---|
73 | return;
|
---|
74 | }
|
---|
75 | correlationCache.SetCorrelation(e.Calculcator, e.Partition, e.Correlation);
|
---|
76 | var correlation = new DoubleMatrix(e.Correlation, Content.Dataset.DoubleVariables, Content.Dataset.DoubleVariables);
|
---|
77 | UpdateDataView(correlation);
|
---|
78 | }
|
---|
79 |
|
---|
80 | [NonDiscoverableType]
|
---|
81 | private class FeatureCorrelationCache : Object {
|
---|
82 | private Dictionary<Tuple<IDependencyCalculator, string>, double[,]> correlationsCache;
|
---|
83 |
|
---|
84 | public FeatureCorrelationCache()
|
---|
85 | : base() {
|
---|
86 | InitializeCaches();
|
---|
87 | }
|
---|
88 |
|
---|
89 | private void InitializeCaches() {
|
---|
90 | correlationsCache = new Dictionary<Tuple<IDependencyCalculator, string>, double[,]>();
|
---|
91 | }
|
---|
92 |
|
---|
93 | public void Reset() {
|
---|
94 | InitializeCaches();
|
---|
95 | }
|
---|
96 |
|
---|
97 | public double[,] GetCorrelation(IDependencyCalculator calc, string partition) {
|
---|
98 | double[,] corr;
|
---|
99 | var key = new Tuple<IDependencyCalculator, string>(calc, partition);
|
---|
100 | correlationsCache.TryGetValue(key, out corr);
|
---|
101 | return corr;
|
---|
102 | }
|
---|
103 |
|
---|
104 | public void SetCorrelation(IDependencyCalculator calc, string partition, double[,] correlation) {
|
---|
105 | var key = new Tuple<IDependencyCalculator, string>(calc, partition);
|
---|
106 | correlationsCache[key] = correlation;
|
---|
107 | }
|
---|
108 | }
|
---|
109 | }
|
---|
110 | }
|
---|