Changeset 8863 for branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis.Views/3.4/FeatureCorrelation/TimeframeFeatureCorrelationView.cs
- Timestamp:
- 10/30/12 16:22:04 (11 years ago)
- Location:
- branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis.Views
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis.Views
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Problems.DataAnalysis.Views merged: 8831,8833,8840,8859,8861
- Property svn:mergeinfo changed
-
branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis.Views/3.4/FeatureCorrelation/TimeframeFeatureCorrelationView.cs
r8729 r8863 21 21 22 22 using System; 23 using System.Collections.Generic; 23 24 using System.Linq; 24 25 using System.Windows.Forms; 25 using HeuristicLab.Analysis;26 26 using HeuristicLab.Data; 27 27 using HeuristicLab.MainForm; 28 using HeuristicLab.PluginInfrastructure; 28 29 29 30 namespace HeuristicLab.Problems.DataAnalysis.Views { … … 36 37 public TimeframeFeatureCorrelationView() { 37 38 InitializeComponent(); 38 TimeframeComboBox.DataSource = Enumerable.Range(0, 16).ToList<int>();39 39 correlationTimeframCache = new FeatureCorrelationTimeframeCache(); 40 40 } … … 43 43 correlationTimeframCache.Reset(); 44 44 if (Content != null) { 45 dataView.RowVisibility = SetInitialVariableVisibility(); 45 46 VariableSelectionComboBox.DataSource = Content.Dataset.DoubleVariables.ToList(); 46 47 } … … 51 52 CalculateCorrelation(); 52 53 } 53 protected void TimeframeComboBox_SelectedChangeCommitted(object sender, EventArgs e) { 54 CalculateCorrelation(); 54 protected void TimeframeTextbox_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) { 55 if (e.KeyCode == Keys.Enter) { 56 CalculateCorrelation(); 57 } 55 58 } 56 59 57 60 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; 61 if (CorrelationCalcComboBox.SelectedItem != null && PartitionComboBox.SelectedItem != null 62 && VariableSelectionComboBox.SelectedItem != null && ValidateTimeframeTextbox()) { 63 string variable = (string)VariableSelectionComboBox.SelectedItem; 64 IDependencyCalculator calc = (IDependencyCalculator)CorrelationCalcComboBox.SelectedValue; 65 string partition = (string)PartitionComboBox.SelectedValue; 66 int frames; 67 int.TryParse(TimeframeTextbox.Text, out frames); 68 dataView.Enabled = false; 65 69 double[,] corr = correlationTimeframCache.GetTimeframeCorrelation(calc, partition, variable); 66 70 if (corr == null) { … … 69 73 fcc.CalculateTimeframeElements(calc, partition, variable, frames, corr); 70 74 } else { 75 fcc.TryCancelCalculation(); 71 76 SetNewCorrelation(corr, calc, frames); 72 UpdateData Grid();77 UpdateDataView(); 73 78 } 74 79 } 75 80 } 76 81 77 private void SetNewCorrelation(double[,] elements, FeatureCorrelationEnums.CorrelationCalculators calc, int frames) { 82 protected bool ValidateTimeframeTextbox() { 83 int help; 84 if (!int.TryParse(TimeframeTextbox.Text, out help)) { 85 MessageBox.Show("Timeframe couldn't be parsed. Enter a valid integer value.", "Parse Error", MessageBoxButtons.OK); 86 return false; 87 } else { 88 if (help > 50) { 89 DialogResult dr = MessageBox.Show("The entered value is bigger than 50. Are you sure you want to calculate? " + 90 "The calculation could take some time.", "Huge Value Warning", MessageBoxButtons.YesNo); 91 return dr.Equals(DialogResult.Yes); 92 } 93 } 94 return true; 95 } 96 97 private void SetNewCorrelation(double[,] elements, IDependencyCalculator calc, int frames) { 78 98 double[,] neededValues = new double[elements.GetLength(0), frames + 1]; 79 99 for (int i = 0; i < elements.GetLength(0); i++) { 80 100 Array.Copy(elements, i * elements.GetLength(1), neededValues, i * neededValues.GetLength(1), frames + 1); 81 101 } 82 SetNewCorrelation(neededValues , calc);102 SetNewCorrelation(neededValues); 83 103 } 84 104 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; 105 private void SetNewCorrelation(double[,] elements) { 106 currentCorrelation = new DoubleMatrix(elements, 107 Enumerable.Range(0, elements.GetLength(1)).Select(x => x.ToString()), 108 Content.Dataset.DoubleVariables); 91 109 } 92 110 … … 96 114 } else { 97 115 correlationTimeframCache.SetTimeframeCorrelation(e.Calculcator, e.Partition, e.Variable, e.Correlation); 98 SetNewCorrelation(e.Correlation , e.Calculcator);99 UpdateData Grid();116 SetNewCorrelation(e.Correlation); 117 UpdateDataView(); 100 118 } 101 119 } 102 120 103 protected override void UpdateColumnHeaders() { 104 for (int i = 0; i < DataGridView.ColumnCount; i++) { 105 DataGridView.Columns[i].HeaderText = i.ToString(); 121 [NonDiscoverableType] 122 private class FeatureCorrelationTimeframeCache : Object { 123 private Dictionary<Tuple<IDependencyCalculator, string, string>, double[,]> timeFrameCorrelationsCache; 124 125 public FeatureCorrelationTimeframeCache() 126 : base() { 127 InitializeCaches(); 106 128 } 107 }108 129 109 protected override void variableVisibility_VariableVisibilityChanged(object sender, ItemCheckEventArgs e) { 110 DataGridView.Rows[GetRowIndexOfVirtualindex(e.Index)].Visible = e.NewValue == CheckState.Checked; 130 private void InitializeCaches() { 131 timeFrameCorrelationsCache = new Dictionary<Tuple<IDependencyCalculator, string, string>, double[,]>(); 132 } 133 134 public void Reset() { 135 InitializeCaches(); 136 } 137 138 public double[,] GetTimeframeCorrelation(IDependencyCalculator calc, string partition, string variable) { 139 double[,] corr; 140 var key = new Tuple<IDependencyCalculator, string, string>(calc, partition, variable); 141 timeFrameCorrelationsCache.TryGetValue(key, out corr); 142 return corr; 143 } 144 145 public void SetTimeframeCorrelation(IDependencyCalculator calc, string partition, string variable, double[,] correlation) { 146 var key = new Tuple<IDependencyCalculator, string, string>(calc, partition, variable); 147 timeFrameCorrelationsCache[key] = correlation; 148 } 111 149 } 112 150 }
Note: See TracChangeset
for help on using the changeset viewer.