Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/07/12 13:44:33 (12 years ago)
Author:
mkommend
Message:

#1292: Minor code cleanup in feature correlation classes.

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  
    3333  public abstract partial class AbstractFeatureCorrelationView : AsynchronousContentView {
    3434    protected FeatureCorrelationCalculator fcc;
    35     protected DoubleMatrix currentCorrelation;
    3635
    3736    public new DataAnalysisProblemData Content {
     
    9998    protected abstract void Content_CorrelationCalculationFinished(object sender, FeatureCorrelationCalculator.CorrelationCalculationFinishedArgs e);
    10099
    101     protected void UpdateDataView() {
     100    protected void UpdateDataView(DoubleMatrix correlation) {
    102101      IDependencyCalculator calc = (IDependencyCalculator)CorrelationCalcComboBox.SelectedValue;
    103102      maximumLabel.Text = calc.Maximum.ToString();
    104103      minimumLabel.Text = calc.Minimum.ToString();
    105104
    106       currentCorrelation.SortableView = true;
     105      correlation.SortableView = true;
    107106      dataView.Maximum = calc.Maximum;
    108107      dataView.Minimum = calc.Minimum;
    109       dataView.Content = currentCorrelation;
     108      dataView.Content = correlation;
    110109      dataView.Enabled = true;
    111110    }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/FeatureCorrelation/EnhancedStringConvertibleMatrixView.cs

    r8870 r8874  
    3131namespace HeuristicLab.Problems.DataAnalysis.Views {
    3232  public partial class EnhancedStringConvertibleMatrixView : StringConvertibleMatrixView {
    33 
    34     protected IEnumerable<bool> columnVisibility, rowVisibility;
     33    private bool[] columnVisibility, rowVisibility;
    3534
    3635    // 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    }
    3840    // 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    }
    4045
    4146    public double Maximum { get; set; }
     
    8287      var dialog = new StringConvertibleMatrixRowVisibilityDialog(this.dataGridView.Rows.Cast<DataGridViewRow>());
    8388      dialog.ShowDialog();
    84       rowVisibility = dialog.Visibility;
     89      RowVisibility = dialog.Visibility;
    8590    }
    8691
     
    8893      var dialog = new StringConvertibleMatrixColumnVisibilityDialog(this.dataGridView.Columns.Cast<DataGridViewColumn>());
    8994      dialog.ShowDialog();
    90       columnVisibility = dialog.Visibility;
     95      ColumnVisibility = dialog.Visibility;
    9196    }
    9297
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/FeatureCorrelation/FeatureCorrelationCalculator.cs

    r8833 r8874  
    7070        bw.CancelAsync();
    7171      }
    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;
    8272    }
    8373
     
    204194
    205195    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);
    212202      return var;
    213203    }
     
    216206      BackgroundWorker worker = sender as BackgroundWorker;
    217207      if (!e.Cancelled && !worker.CancellationPending) {
    218         if (!(e.Error == null)) {
     208        if (e.Error != null) {
    219209          ErrorHandling.ShowErrorDialog(e.Error);
    220210        } else {
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/FeatureCorrelation/FeatureCorrelationView.cs

    r8861 r8874  
    4343    protected override void OnContentChanged() {
    4444      if (Content != null) {
    45         dataView.RowVisibility = SetInitialVariableVisibility();
    46         dataView.ColumnVisibility = SetInitialVariableVisibility();
     45        dataView.ColumnVisibility = dataView.RowVisibility = SetInitialVariableVisibility();
    4746      }
    4847      correlationCache.Reset();
     
    5150
    5251    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);
    6565      }
    6666    }
    6767
    68     private void SetNewCorrelation(double[,] elements) {
    69       currentCorrelation = new DoubleMatrix(elements,
    70                                             Content.Dataset.DoubleVariables,
    71                                             Content.Dataset.DoubleVariables);
    72     }
     68
    7369
    7470    protected override void Content_CorrelationCalculationFinished(object sender, FeatureCorrelationCalculator.CorrelationCalculationFinishedArgs e) {
    7571      if (InvokeRequired) {
    7672        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;
    8174      }
     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);
    8278    }
    8379
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/FeatureCorrelation/TimeframeFeatureCorrelationView.cs

    r8861 r8874  
    4949    }
    5050
    51     protected void VariableSelectionComboBox_SelectedChangeCommitted(object sender, EventArgs e) {
     51    private void VariableSelectionComboBox_SelectedChangeCommitted(object sender, EventArgs e) {
    5252      CalculateCorrelation();
    5353    }
    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) {
    5556      if (e.KeyCode == Keys.Enter) {
    5657        CalculateCorrelation();
     
    7475        } else {
    7576          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);
    7881        }
    7982      }
    8083    }
    8184
    82     protected bool ValidateTimeframeTextbox() {
     85    private bool ValidateTimeframeTextbox() {
    8386      int help;
    8487      if (!int.TryParse(TimeframeTextbox.Text, out help)) {
     
    9598    }
    9699
    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     }
    110100
    111101    protected override void Content_CorrelationCalculationFinished(object sender, FeatureCorrelationCalculator.CorrelationCalculationFinishedArgs e) {
     
    114104      } else {
    115105        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);
    118109      }
    119110    }
Note: See TracChangeset for help on using the changeset viewer.