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