Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/23/12 10:07:48 (12 years ago)
Author:
sforsten
Message:

#1292:

  • removed combo box in TimeframeCorrelationView and added a textbox instead
  • caches are directly in (Timeframe-)FeatureCorrelationView
  • caches use Tuple<> instead of nested dictionaries
  • a control EnhancedStringConvertibleMatrix inherits from StringConvertibleMatrixView to reduce code duplication
  • add interface IDependencyCalculator to several calculators
  • fixed bug: a previous started calculation is cancelled, if a new calculation shall be started and the values are already in the cache
  • fixed bug: if the content is changed, the calculation is cancelled

HeatMap is still used for the dependency representation, because a class is needed which implements IStringConvertibleMatrix and it has a maximum and minimum value.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/FeatureCorrelation/TimeframeFeatureCorrelationView.cs

    r8729 r8833  
    2121
    2222using System;
     23using System.Collections.Generic;
    2324using System.Linq;
    2425using System.Windows.Forms;
     
    2627using HeuristicLab.Data;
    2728using HeuristicLab.MainForm;
     29using HeuristicLab.PluginInfrastructure;
    2830
    2931namespace HeuristicLab.Problems.DataAnalysis.Views {
     
    3638    public TimeframeFeatureCorrelationView() {
    3739      InitializeComponent();
    38       TimeframeComboBox.DataSource = Enumerable.Range(0, 16).ToList<int>();
    3940      correlationTimeframCache = new FeatureCorrelationTimeframeCache();
    4041    }
     
    4344      correlationTimeframCache.Reset();
    4445      if (Content != null) {
     46        dataView.RowVisibility = SetInitialVariableVisibility();
    4547        VariableSelectionComboBox.DataSource = Content.Dataset.DoubleVariables.ToList();
    4648      }
     
    5153      CalculateCorrelation();
    5254    }
    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      }
    5559    }
    5660
    5761    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;
    6570        double[,] corr = correlationTimeframCache.GetTimeframeCorrelation(calc, partition, variable);
    6671        if (corr == null) {
     
    6974          fcc.CalculateTimeframeElements(calc, partition, variable, frames, corr);
    7075        } else {
     76          fcc.TryCancelCalculation();
    7177          SetNewCorrelation(corr, calc, frames);
    72           UpdateDataGrid();
     78          UpdateDataView();
    7379        }
    7480      }
    7581    }
    7682
    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) {
    7899      double[,] neededValues = new double[elements.GetLength(0), frames + 1];
    79100      for (int i = 0; i < elements.GetLength(0); i++) {
     
    83104    }
    84105
    85     private void SetNewCorrelation(double[,] elements, FeatureCorrelationEnums.CorrelationCalculators calc) {
    86       DoubleRange range = FeatureCorrelationEnums.calculatorInterval[calc];
     106    private void SetNewCorrelation(double[,] elements, IDependencyCalculator calc) {
     107      DoubleRange range = calc.Interval;
    87108      HeatMap hm = new HeatMap(elements, "", range.End, range.Start);
    88109      hm.RowNames = Content.Dataset.DoubleVariables;
     
    97118        correlationTimeframCache.SetTimeframeCorrelation(e.Calculcator, e.Partition, e.Variable, e.Correlation);
    98119        SetNewCorrelation(e.Correlation, e.Calculcator);
    99         UpdateDataGrid();
     120        UpdateDataView();
    100121      }
    101122    }
    102123
    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();
    106131      }
    107     }
    108132
    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      }
    111152    }
    112153  }
Note: See TracChangeset for help on using the changeset viewer.