- Timestamp:
- 11/07/12 13:44:33 (12 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/FeatureCorrelation
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/FeatureCorrelation/AbstractFeatureCorrelationView.cs
r8861 r8874 33 33 public abstract partial class AbstractFeatureCorrelationView : AsynchronousContentView { 34 34 protected FeatureCorrelationCalculator fcc; 35 protected DoubleMatrix currentCorrelation;36 35 37 36 public new DataAnalysisProblemData Content { … … 99 98 protected abstract void Content_CorrelationCalculationFinished(object sender, FeatureCorrelationCalculator.CorrelationCalculationFinishedArgs e); 100 99 101 protected void UpdateDataView( ) {100 protected void UpdateDataView(DoubleMatrix correlation) { 102 101 IDependencyCalculator calc = (IDependencyCalculator)CorrelationCalcComboBox.SelectedValue; 103 102 maximumLabel.Text = calc.Maximum.ToString(); 104 103 minimumLabel.Text = calc.Minimum.ToString(); 105 104 106 c urrentCorrelation.SortableView = true;105 correlation.SortableView = true; 107 106 dataView.Maximum = calc.Maximum; 108 107 dataView.Minimum = calc.Minimum; 109 dataView.Content = c urrentCorrelation;108 dataView.Content = correlation; 110 109 dataView.Enabled = true; 111 110 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/FeatureCorrelation/EnhancedStringConvertibleMatrixView.cs
r8870 r8874 31 31 namespace HeuristicLab.Problems.DataAnalysis.Views { 32 32 public partial class EnhancedStringConvertibleMatrixView : StringConvertibleMatrixView { 33 34 protected IEnumerable<bool> columnVisibility, rowVisibility; 33 private bool[] columnVisibility, rowVisibility; 35 34 36 35 // sets the visibility of its columns for the next time it is updated 37 public IEnumerable<bool> ColumnVisibility { set { columnVisibility = value; } } 36 public IEnumerable<bool> ColumnVisibility { 37 get { return columnVisibility; } 38 set { columnVisibility = value.ToArray(); } 39 } 38 40 // sets the visibility of its rows for the next time it is updated 39 public IEnumerable<bool> RowVisibility { set { rowVisibility = value; } } 41 public IEnumerable<bool> RowVisibility { 42 get { return rowVisibility; } 43 set { rowVisibility = value.ToArray(); } 44 } 40 45 41 46 public double Maximum { get; set; } … … 82 87 var dialog = new StringConvertibleMatrixRowVisibilityDialog(this.dataGridView.Rows.Cast<DataGridViewRow>()); 83 88 dialog.ShowDialog(); 84 rowVisibility = dialog.Visibility;89 RowVisibility = dialog.Visibility; 85 90 } 86 91 … … 88 93 var dialog = new StringConvertibleMatrixColumnVisibilityDialog(this.dataGridView.Columns.Cast<DataGridViewColumn>()); 89 94 dialog.ShowDialog(); 90 columnVisibility = dialog.Visibility;95 ColumnVisibility = dialog.Visibility; 91 96 } 92 97 -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/FeatureCorrelation/FeatureCorrelationCalculator.cs
r8833 r8874 70 70 bw.CancelAsync(); 71 71 } 72 }73 74 private double[,] GetElementsOfCorrelation(double[,] corr, int frames) {75 double[,] elements = new double[corr.GetLength(0), frames + 1];76 for (int i = 0; i < corr.GetLength(0); i++) {77 for (int j = 0; j <= frames; j++) {78 elements[i, j] = corr[i, j];79 }80 }81 return elements;82 72 } 83 73 … … 204 194 205 195 private IEnumerable<double> GetRelevantValues(IDataAnalysisProblemData problemData, string partition, string variable) { 206 IEnumerable<double> var = problemData.Dataset.GetDoubleValues(variable);207 if (partition.Equals(FeatureCorrelationPartitions.TRAININGSAMPLES)) {208 var = var.Skip(problemData.TrainingPartition.Start).Take(problemData.TrainingPartition.End - problemData.TrainingPartition.Start);209 } else if (partition.Equals(FeatureCorrelationPartitions.TESTSAMPLES)) {210 var = var.Skip(problemData.TestPartition.Start).Take(problemData.TestPartition.End - problemData.TestPartition.Start);211 }196 IEnumerable<double> var; 197 if (partition.Equals(FeatureCorrelationPartitions.TRAININGSAMPLES)) 198 var = problemData.Dataset.GetDoubleValues(variable, problemData.TrainingIndices); 199 else if (partition.Equals(FeatureCorrelationPartitions.TESTSAMPLES)) 200 var = problemData.Dataset.GetDoubleValues(variable, problemData.TestIndices); 201 else var = problemData.Dataset.GetDoubleValues(variable); 212 202 return var; 213 203 } … … 216 206 BackgroundWorker worker = sender as BackgroundWorker; 217 207 if (!e.Cancelled && !worker.CancellationPending) { 218 if ( !(e.Error == null)) {208 if (e.Error != null) { 219 209 ErrorHandling.ShowErrorDialog(e.Error); 220 210 } else { -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/FeatureCorrelation/FeatureCorrelationView.cs
r8861 r8874 43 43 protected override void OnContentChanged() { 44 44 if (Content != null) { 45 dataView.RowVisibility = SetInitialVariableVisibility(); 46 dataView.ColumnVisibility = SetInitialVariableVisibility(); 45 dataView.ColumnVisibility = dataView.RowVisibility = SetInitialVariableVisibility(); 47 46 } 48 47 correlationCache.Reset(); … … 51 50 52 51 protected override void CalculateCorrelation() { 53 if (CorrelationCalcComboBox.SelectedItem != null && PartitionComboBox.SelectedItem != null) { 54 IDependencyCalculator calc = (IDependencyCalculator)CorrelationCalcComboBox.SelectedValue; 55 string partition = (string)PartitionComboBox.SelectedValue; 56 dataView.Enabled = false; 57 double[,] corr = correlationCache.GetCorrelation(calc, partition); 58 if (corr == null) { 59 fcc.CalculateElements(calc, partition); 60 } else { 61 fcc.TryCancelCalculation(); 62 SetNewCorrelation(corr); 63 UpdateDataView(); 64 } 52 if (CorrelationCalcComboBox.SelectedItem == null) return; 53 if (PartitionComboBox.SelectedItem == null) return; 54 55 IDependencyCalculator calc = (IDependencyCalculator)CorrelationCalcComboBox.SelectedValue; 56 string partition = (string)PartitionComboBox.SelectedValue; 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); 65 65 } 66 66 } 67 67 68 private void SetNewCorrelation(double[,] elements) { 69 currentCorrelation = new DoubleMatrix(elements, 70 Content.Dataset.DoubleVariables, 71 Content.Dataset.DoubleVariables); 72 } 68 73 69 74 70 protected override void Content_CorrelationCalculationFinished(object sender, FeatureCorrelationCalculator.CorrelationCalculationFinishedArgs e) { 75 71 if (InvokeRequired) { 76 72 Invoke(new FeatureCorrelationCalculator.CorrelationCalculationFinishedHandler(Content_CorrelationCalculationFinished), sender, e); 77 } else { 78 correlationCache.SetCorrelation(e.Calculcator, e.Partition, e.Correlation); 79 SetNewCorrelation(e.Correlation); 80 UpdateDataView(); 73 return; 81 74 } 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); 82 78 } 83 79 -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/FeatureCorrelation/TimeframeFeatureCorrelationView.cs
r8861 r8874 49 49 } 50 50 51 pr otectedvoid VariableSelectionComboBox_SelectedChangeCommitted(object sender, EventArgs e) {51 private void VariableSelectionComboBox_SelectedChangeCommitted(object sender, EventArgs e) { 52 52 CalculateCorrelation(); 53 53 } 54 protected void TimeframeTextbox_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) { 54 55 private void TimeframeTextbox_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) { 55 56 if (e.KeyCode == Keys.Enter) { 56 57 CalculateCorrelation(); … … 74 75 } else { 75 76 fcc.TryCancelCalculation(); 76 SetNewCorrelation(corr, calc, frames); 77 UpdateDataView(); 77 var columnNames = Enumerable.Range(0, corr.GetLength(1)).Select(x => x.ToString()); 78 var correlation = new DoubleMatrix(corr, columnNames, Content.Dataset.DoubleVariables); 79 ((IStringConvertibleMatrix)correlation).Columns = frames + 1; 80 UpdateDataView(correlation); 78 81 } 79 82 } 80 83 } 81 84 82 pr otectedbool ValidateTimeframeTextbox() {85 private bool ValidateTimeframeTextbox() { 83 86 int help; 84 87 if (!int.TryParse(TimeframeTextbox.Text, out help)) { … … 95 98 } 96 99 97 private void SetNewCorrelation(double[,] elements, IDependencyCalculator calc, int frames) {98 double[,] neededValues = new double[elements.GetLength(0), frames + 1];99 for (int i = 0; i < elements.GetLength(0); i++) {100 Array.Copy(elements, i * elements.GetLength(1), neededValues, i * neededValues.GetLength(1), frames + 1);101 }102 SetNewCorrelation(neededValues);103 }104 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);109 }110 100 111 101 protected override void Content_CorrelationCalculationFinished(object sender, FeatureCorrelationCalculator.CorrelationCalculationFinishedArgs e) { … … 114 104 } else { 115 105 correlationTimeframCache.SetTimeframeCorrelation(e.Calculcator, e.Partition, e.Variable, e.Correlation); 116 SetNewCorrelation(e.Correlation); 117 UpdateDataView(); 106 var columnNames = Enumerable.Range(0, e.Correlation.GetLength(1)).Select(x => x.ToString()); 107 var correlation = new DoubleMatrix(e.Correlation, columnNames, Content.Dataset.DoubleVariables); 108 UpdateDataView(correlation); 118 109 } 119 110 }
Note: See TracChangeset
for help on using the changeset viewer.