Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis.Views/3.4/FeatureCorrelation/FeatureCorrelationView.cs @ 8863

Last change on this file since 8863 was 8863, checked in by sforsten, 12 years ago

#1776:

  • merged r8810:8862 from trunk into branch
  • fixed exception in ClassificationEnsembleSolutionAccuracyToCoveredSamples, if no estimated values are in a partition, so nothing can be shown
File size: 4.2 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 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
22using System;
23using System.Collections.Generic;
24using System.Windows.Forms;
25using HeuristicLab.Data;
26using HeuristicLab.MainForm;
27using HeuristicLab.MainForm.WindowsForms;
28using HeuristicLab.PluginInfrastructure;
29
30namespace 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.RowVisibility = SetInitialVariableVisibility();
46        dataView.ColumnVisibility = SetInitialVariableVisibility();
47      }
48      correlationCache.Reset();
49      base.OnContentChanged();
50    }
51
52    protected override void CalculateCorrelation() {
53      if (CorrelationCalcComboBox.SelectedItem != null && PartitionComboBox.SelectedItem != null) {
54        IDependencyCalculator calc = (IDependencyCalculator)CorrelationCalcComboBox.SelectedValue;
55        string partition = (string)PartitionComboBox.SelectedValue;
56        dataView.Enabled = false;
57        double[,] corr = correlationCache.GetCorrelation(calc, partition);
58        if (corr == null) {
59          fcc.CalculateElements(calc, partition);
60        } else {
61          fcc.TryCancelCalculation();
62          SetNewCorrelation(corr);
63          UpdateDataView();
64        }
65      }
66    }
67
68    private void SetNewCorrelation(double[,] elements) {
69      currentCorrelation = new DoubleMatrix(elements,
70                                            Content.Dataset.DoubleVariables,
71                                            Content.Dataset.DoubleVariables);
72    }
73
74    protected override void Content_CorrelationCalculationFinished(object sender, FeatureCorrelationCalculator.CorrelationCalculationFinishedArgs e) {
75      if (InvokeRequired) {
76        Invoke(new FeatureCorrelationCalculator.CorrelationCalculationFinishedHandler(Content_CorrelationCalculationFinished), sender, e);
77      } else {
78        correlationCache.SetCorrelation(e.Calculcator, e.Partition, e.Correlation);
79        SetNewCorrelation(e.Correlation);
80        UpdateDataView();
81      }
82    }
83
84    [NonDiscoverableType]
85    private class FeatureCorrelationCache : Object {
86      private Dictionary<Tuple<IDependencyCalculator, string>, double[,]> correlationsCache;
87
88      public FeatureCorrelationCache()
89        : base() {
90        InitializeCaches();
91      }
92
93      private void InitializeCaches() {
94        correlationsCache = new Dictionary<Tuple<IDependencyCalculator, string>, double[,]>();
95      }
96
97      public void Reset() {
98        InitializeCaches();
99      }
100
101      public double[,] GetCorrelation(IDependencyCalculator calc, string partition) {
102        double[,] corr;
103        var key = new Tuple<IDependencyCalculator, string>(calc, partition);
104        correlationsCache.TryGetValue(key, out corr);
105        return corr;
106      }
107
108      public void SetCorrelation(IDependencyCalculator calc, string partition, double[,] correlation) {
109        var key = new Tuple<IDependencyCalculator, string>(calc, partition);
110        correlationsCache[key] = correlation;
111      }
112    }
113  }
114}
Note: See TracBrowser for help on using the repository browser.