Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/FeatureCorrelation/FeatureCorrelationView.cs @ 12012

Last change on this file since 12012 was 12012, checked in by ascheibe, 9 years ago

#2212 merged r12008, r12009, r12010 back into trunk

File size: 4.1 KB
RevLine 
[8578]1#region License Information
2/* HeuristicLab
[12012]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
[8833]22using System;
23using System.Collections.Generic;
[8578]24using System.Windows.Forms;
25using HeuristicLab.Data;
26using HeuristicLab.MainForm;
27using HeuristicLab.MainForm.WindowsForms;
[8833]28using HeuristicLab.PluginInfrastructure;
[8578]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() {
[8833]44      if (Content != null) {
[8874]45        dataView.ColumnVisibility = dataView.RowVisibility = SetInitialVariableVisibility();
[8833]46      }
[8578]47      correlationCache.Reset();
48      base.OnContentChanged();
49    }
50
51    protected override void CalculateCorrelation() {
[8880]52      if (correlationCalcComboBox.SelectedItem == null) return;
53      if (partitionComboBox.SelectedItem == null) return;
[8874]54
[8880]55      IDependencyCalculator calc = (IDependencyCalculator)correlationCalcComboBox.SelectedValue;
56      string partition = (string)partitionComboBox.SelectedValue;
[8874]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);
[8578]65      }
66    }
67
68
[8874]69
[8578]70    protected override void Content_CorrelationCalculationFinished(object sender, FeatureCorrelationCalculator.CorrelationCalculationFinishedArgs e) {
71      if (InvokeRequired) {
72        Invoke(new FeatureCorrelationCalculator.CorrelationCalculationFinishedHandler(Content_CorrelationCalculationFinished), sender, e);
[8874]73        return;
[8578]74      }
[8874]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);
[8578]78    }
[8689]79
[8833]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      }
[8689]108    }
[8578]109  }
110}
Note: See TracBrowser for help on using the repository browser.