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