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 |
|
---|
22 | using System;
|
---|
23 | using System.Linq;
|
---|
24 | using System.Windows.Forms;
|
---|
25 | using HeuristicLab.Analysis;
|
---|
26 | using HeuristicLab.Data;
|
---|
27 | using HeuristicLab.MainForm;
|
---|
28 | using FCE = HeuristicLab.Problems.DataAnalysis.FeatureCorrelationEnums;
|
---|
29 |
|
---|
30 | namespace HeuristicLab.Problems.DataAnalysis.Views {
|
---|
31 | [View("Timeframe Feature Correlation View")]
|
---|
32 | [Content(typeof(DataAnalysisProblemData), false)]
|
---|
33 | public partial class TimeframeFeatureCorrelationView : AbstractFeatureCorrelationView {
|
---|
34 |
|
---|
35 | private FeatureCorrelationTimeframeCache correlationTimeframCache;
|
---|
36 |
|
---|
37 | public TimeframeFeatureCorrelationView() {
|
---|
38 | InitializeComponent();
|
---|
39 | TimeframeComboBox.DataSource = Enumerable.Range(0, 16).ToList<int>();
|
---|
40 | correlationTimeframCache = new FeatureCorrelationTimeframeCache();
|
---|
41 | }
|
---|
42 |
|
---|
43 | protected override void OnContentChanged() {
|
---|
44 | correlationTimeframCache.Reset();
|
---|
45 | if (Content != null) {
|
---|
46 | VariableSelectionComboBox.DataSource = Content.Dataset.DoubleVariables.ToList();
|
---|
47 | }
|
---|
48 | base.OnContentChanged();
|
---|
49 | }
|
---|
50 |
|
---|
51 | protected void VariableSelectionComboBox_SelectedChangeCommitted(object sender, EventArgs e) {
|
---|
52 | CalculateCorrelation();
|
---|
53 | }
|
---|
54 | protected void TimeframeComboBox_SelectedChangeCommitted(object sender, EventArgs e) {
|
---|
55 | CalculateCorrelation();
|
---|
56 | }
|
---|
57 |
|
---|
58 | protected override void CalculateCorrelation() {
|
---|
59 | string variable = (string)VariableSelectionComboBox.SelectedItem;
|
---|
60 | if (CorrelationCalcComboBox.SelectedItem != null && PartitionComboBox.SelectedItem != null && variable != null) {
|
---|
61 | FCE.CorrelationCalculators calc = (FCE.CorrelationCalculators)CorrelationCalcComboBox.SelectedValue;
|
---|
62 | FCE.Partitions partition = (FCE.Partitions)PartitionComboBox.SelectedValue;
|
---|
63 | DataGridView.Columns.Clear();
|
---|
64 | DataGridView.Enabled = false;
|
---|
65 | int frames = (int)TimeframeComboBox.SelectedItem;
|
---|
66 | double[,] corr = correlationTimeframCache.GetTimeframeCorrelation(calc, partition, variable);
|
---|
67 | if (corr == null) {
|
---|
68 | fcc.CalculateTimeframeElements(calc, partition, variable, frames);
|
---|
69 | } else if (corr.GetLength(1) <= frames) {
|
---|
70 | fcc.CalculateTimeframeElements(calc, partition, variable, frames, corr);
|
---|
71 | } else {
|
---|
72 | SetNewCorrelation(corr, calc, frames);
|
---|
73 | UpdateDataGrid();
|
---|
74 | }
|
---|
75 | }
|
---|
76 | }
|
---|
77 |
|
---|
78 | private void SetNewCorrelation(double[,] elements, FCE.CorrelationCalculators calc, int frames) {
|
---|
79 | double[,] neededValues = new double[elements.GetLength(0), frames + 1];
|
---|
80 | for (int i = 0; i < elements.GetLength(0); i++) {
|
---|
81 | Array.Copy(elements, i * elements.GetLength(1), neededValues, i * neededValues.GetLength(1), frames + 1);
|
---|
82 | }
|
---|
83 | SetNewCorrelation(neededValues, calc);
|
---|
84 | }
|
---|
85 |
|
---|
86 | private void SetNewCorrelation(double[,] elements, FCE.CorrelationCalculators calc) {
|
---|
87 | DoubleRange range = FCE.calculatorInterval[calc];
|
---|
88 | HeatMap hm = new HeatMap(elements, "", range.End, range.Start);
|
---|
89 | hm.RowNames = Content.Dataset.DoubleVariables;
|
---|
90 | hm.ColumnNames = Enumerable.Range(0, elements.GetLength(1)).Select(x => x.ToString());
|
---|
91 | currentCorrelation = hm;
|
---|
92 | }
|
---|
93 |
|
---|
94 | protected override void Content_CorrelationCalculationFinished(object sender, FeatureCorrelationCalculator.CorrelationCalculationFinishedArgs e) {
|
---|
95 | if (InvokeRequired) {
|
---|
96 | Invoke(new FeatureCorrelationCalculator.CorrelationCalculationFinishedHandler(Content_CorrelationCalculationFinished), sender, e);
|
---|
97 | } else {
|
---|
98 | correlationTimeframCache.SetTimeframeCorrelation(e.Calculcator, e.Partition, e.Variable, e.Correlation);
|
---|
99 | SetNewCorrelation(e.Correlation, e.Calculcator);
|
---|
100 | UpdateDataGrid();
|
---|
101 | }
|
---|
102 | }
|
---|
103 |
|
---|
104 | protected override void UpdateColumnHeaders() {
|
---|
105 | for (int i = 0; i < DataGridView.ColumnCount; i++) {
|
---|
106 | DataGridView.Columns[i].HeaderText = i.ToString();
|
---|
107 | }
|
---|
108 | }
|
---|
109 | }
|
---|
110 | } |
---|