Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/30/12 16:22:04 (11 years ago)
Author:
sforsten
Message:

#1776:

  • merged r8810:8862 from trunk into branch
  • fixed exception in ClassificationEnsembleSolutionAccuracyToCoveredSamples, if no estimated values are in a partition, so nothing can be shown
Location:
branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis.Views
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis.Views

  • branches/ClassificationEnsembleVoting/HeuristicLab.Problems.DataAnalysis.Views/3.4/FeatureCorrelation/TimeframeFeatureCorrelationView.cs

    r8729 r8863  
    2121
    2222using System;
     23using System.Collections.Generic;
    2324using System.Linq;
    2425using System.Windows.Forms;
    25 using HeuristicLab.Analysis;
    2626using HeuristicLab.Data;
    2727using HeuristicLab.MainForm;
     28using HeuristicLab.PluginInfrastructure;
    2829
    2930namespace HeuristicLab.Problems.DataAnalysis.Views {
     
    3637    public TimeframeFeatureCorrelationView() {
    3738      InitializeComponent();
    38       TimeframeComboBox.DataSource = Enumerable.Range(0, 16).ToList<int>();
    3939      correlationTimeframCache = new FeatureCorrelationTimeframeCache();
    4040    }
     
    4343      correlationTimeframCache.Reset();
    4444      if (Content != null) {
     45        dataView.RowVisibility = SetInitialVariableVisibility();
    4546        VariableSelectionComboBox.DataSource = Content.Dataset.DoubleVariables.ToList();
    4647      }
     
    5152      CalculateCorrelation();
    5253    }
    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      }
    5558    }
    5659
    5760    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;
    6569        double[,] corr = correlationTimeframCache.GetTimeframeCorrelation(calc, partition, variable);
    6670        if (corr == null) {
     
    6973          fcc.CalculateTimeframeElements(calc, partition, variable, frames, corr);
    7074        } else {
     75          fcc.TryCancelCalculation();
    7176          SetNewCorrelation(corr, calc, frames);
    72           UpdateDataGrid();
     77          UpdateDataView();
    7378        }
    7479      }
    7580    }
    7681
    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) {
    7898      double[,] neededValues = new double[elements.GetLength(0), frames + 1];
    7999      for (int i = 0; i < elements.GetLength(0); i++) {
    80100        Array.Copy(elements, i * elements.GetLength(1), neededValues, i * neededValues.GetLength(1), frames + 1);
    81101      }
    82       SetNewCorrelation(neededValues, calc);
     102      SetNewCorrelation(neededValues);
    83103    }
    84104
    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);
    91109    }
    92110
     
    96114      } else {
    97115        correlationTimeframCache.SetTimeframeCorrelation(e.Calculcator, e.Partition, e.Variable, e.Correlation);
    98         SetNewCorrelation(e.Correlation, e.Calculcator);
    99         UpdateDataGrid();
     116        SetNewCorrelation(e.Correlation);
     117        UpdateDataView();
    100118      }
    101119    }
    102120
    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();
    106128      }
    107     }
    108129
    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      }
    111149    }
    112150  }
Note: See TracChangeset for help on using the changeset viewer.