Free cookie consent management tool by TermsFeed Policy Generator

Changeset 8833 for trunk


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.

Location:
trunk/sources
Files:
12 added
2 deleted
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Data.Views/3.3/HeuristicLab.Data.Views-3.3.csproj

    r8600 r8833  
    128128    </Compile>
    129129    <Compile Include="Plugin.cs" />
     130    <Compile Include="StringConvertibleMatrixColumnVisibilityDialog.cs">
     131      <SubType>Form</SubType>
     132    </Compile>
     133    <Compile Include="StringConvertibleMatrixColumnVisibilityDialog.Designer.cs">
     134      <DependentUpon>StringConvertibleMatrixColumnVisibilityDialog.cs</DependentUpon>
     135    </Compile>
     136    <Compile Include="StringConvertibleMatrixRowVisibilityDialog.cs">
     137      <SubType>Form</SubType>
     138    </Compile>
     139    <Compile Include="StringConvertibleMatrixRowVisibilityDialog.Designer.cs">
     140      <DependentUpon>StringConvertibleMatrixRowVisibilityDialog.cs</DependentUpon>
     141    </Compile>
    130142    <Compile Include="StringConvertibleValueTupleView.cs">
    131143      <SubType>UserControl</SubType>
     
    141153      <DependentUpon>BoolValueView.cs</DependentUpon>
    142154    </Compile>
    143     <Compile Include="ColumnsVisibilityDialog.cs">
     155    <Compile Include="StringConvertibleMatrixVisibilityDialog.cs">
    144156      <SubType>Form</SubType>
    145157    </Compile>
    146     <Compile Include="ColumnsVisibilityDialog.Designer.cs">
    147       <DependentUpon>ColumnsVisibilityDialog.cs</DependentUpon>
     158    <Compile Include="StringConvertibleMatrixVisibilityDialog.Designer.cs">
     159      <DependentUpon>StringConvertibleMatrixVisibilityDialog.cs</DependentUpon>
    148160    </Compile>
    149161    <Compile Include="ComparisonView.cs">
     
    240252  -->
    241253  <PropertyGroup>
    242    <PreBuildEvent Condition=" '$(OS)' == 'Windows_NT' ">set Path=%25Path%25;$(ProjectDir);$(SolutionDir)
     254    <PreBuildEvent Condition=" '$(OS)' == 'Windows_NT' ">set Path=%25Path%25;$(ProjectDir);$(SolutionDir)
    243255set ProjectDir=$(ProjectDir)
    244256set SolutionDir=$(SolutionDir)
     
    247259call PreBuildEvent.cmd
    248260</PreBuildEvent>
    249 <PreBuildEvent Condition=" '$(OS)' != 'Windows_NT' ">
     261    <PreBuildEvent Condition=" '$(OS)' != 'Windows_NT' ">
    250262export ProjectDir=$(ProjectDir)
    251263export SolutionDir=$(SolutionDir)
  • trunk/sources/HeuristicLab.Data.Views/3.3/StringConvertibleMatrixView.cs

    r8139 r8833  
    3535  [Content(typeof(IStringConvertibleMatrix), true)]
    3636  public partial class StringConvertibleMatrixView : AsynchronousContentView {
    37     private int[] virtualRowIndices;
     37    protected int[] virtualRowIndices;
    3838    private List<KeyValuePair<int, SortOrder>> sortedColumnIndices;
    3939    private RowComparer rowComparer;
     
    171171      }
    172172    }
    173     protected void UpdateRowHeaders() {
     173    protected virtual void UpdateRowHeaders() {
    174174      int index = dataGridView.FirstDisplayedScrollingRowIndex;
    175175      if (index == -1) index = 0;
     
    509509        contextMenu.Show(MousePosition);
    510510    }
    511     private void ShowHideColumns_Click(object sender, EventArgs e) {
    512       new ColumnsVisibilityDialog(this.dataGridView.Columns.Cast<DataGridViewColumn>()).ShowDialog();
     511    protected virtual void ShowHideColumns_Click(object sender, EventArgs e) {
     512      new StringConvertibleMatrixColumnVisibilityDialog(this.dataGridView.Columns.Cast<DataGridViewColumn>()).ShowDialog();
    513513    }
    514514
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/ClassificationFeatureCorrelationView.cs

    r8689 r8833  
    3737    }
    3838
    39     protected override bool[] SetInitialVisibilityOfColumns() {
     39    protected override bool[] SetInitialVariableVisibility() {
    4040      int i = Content.Dataset.DoubleVariables.ToList().FindIndex(x => x == Content.TargetVariable);
    41       var initialVisibility = base.SetInitialVisibilityOfColumns();
     41      var initialVisibility = base.SetInitialVariableVisibility();
    4242      initialVisibility[i] = true;
    4343      return initialVisibility;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/ClassificationTimeframeFeatureCorrelationView.cs

    r8689 r8833  
    3737    }
    3838
    39     protected override bool[] SetInitialVisibilityOfColumns() {
     39    protected override bool[] SetInitialVariableVisibility() {
    4040      int i = Content.Dataset.DoubleVariables.ToList().FindIndex(x => x == Content.TargetVariable);
    41       var initialVisibility = base.SetInitialVisibilityOfColumns();
     41      var initialVisibility = base.SetInitialVariableVisibility();
    4242      initialVisibility[i] = true;
    4343      return initialVisibility;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/FeatureCorrelation/AbstractFeatureCorrelationView.Designer.cs

    r8689 r8833  
    2121
    2222#endregion
     23
    2324namespace HeuristicLab.Problems.DataAnalysis.Views {
    2425  partial class AbstractFeatureCorrelationView {
     
    4849      this.components = new System.ComponentModel.Container();
    4950      System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(AbstractFeatureCorrelationView));
    50       this.DataGridView = new System.Windows.Forms.DataGridView();
    5151      this.HeatMapProgressBar = new System.Windows.Forms.ProgressBar();
    5252      this.PartitionComboBox = new System.Windows.Forms.ComboBox();
     
    6060      this.CalculatingPanel = new System.Windows.Forms.Panel();
    6161      this.CalculatingLabel = new System.Windows.Forms.Label();
    62       this.contextMenu = new System.Windows.Forms.ContextMenuStrip(this.components);
    63       this.ShowHideColumns = new System.Windows.Forms.ToolStripMenuItem();
    64       ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit();
     62      this.dataView = new HeuristicLab.Problems.DataAnalysis.Views.EnhancedStringConvertibleMatrixView();
    6563      ((System.ComponentModel.ISupportInitialize)(this.PictureBox)).BeginInit();
    6664      ((System.ComponentModel.ISupportInitialize)(this.SplitContainer)).BeginInit();
     
    6967      this.SplitContainer.SuspendLayout();
    7068      this.CalculatingPanel.SuspendLayout();
    71       this.contextMenu.SuspendLayout();
    7269      this.SuspendLayout();
    73       //
    74       // DataGridView
    75       //
    76       this.DataGridView.AllowUserToAddRows = false;
    77       this.DataGridView.AllowUserToDeleteRows = false;
    78       this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
    79       this.DataGridView.Dock = System.Windows.Forms.DockStyle.Fill;
    80       this.DataGridView.Location = new System.Drawing.Point(0, 0);
    81       this.DataGridView.Name = "DataGridView";
    82       this.DataGridView.ReadOnly = true;
    83       this.DataGridView.Size = new System.Drawing.Size(475, 301);
    84       this.DataGridView.TabIndex = 0;
    85       this.DataGridView.VirtualMode = true;
    86       this.DataGridView.CellPainting += new System.Windows.Forms.DataGridViewCellPaintingEventHandler(this.DataGridView_CellPainting);
    87       this.DataGridView.CellValueNeeded += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.DataGridView_CellValueNeeded);
    88       this.DataGridView.ColumnHeaderMouseClick += new System.Windows.Forms.DataGridViewCellMouseEventHandler(this.DataGridView_ColumnHeaderMouseClick);
    89       this.DataGridView.KeyDown += new System.Windows.Forms.KeyEventHandler(this.DataGridView_KeyDown);
    90       this.DataGridView.MouseClick += new System.Windows.Forms.MouseEventHandler(this.DataGridView_MouseClick);
    9170      //
    9271      // HeatMapProgressBar
     
    162141      //
    163142      this.PictureBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    164                   | System.Windows.Forms.AnchorStyles.Right)));
     143            | System.Windows.Forms.AnchorStyles.Right)));
    165144      this.PictureBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
    166145      this.PictureBox.Image = ((System.Drawing.Image)(resources.GetObject("PictureBox.Image")));
     
    175154      //
    176155      this.SplitContainer.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    177                   | System.Windows.Forms.AnchorStyles.Left)
    178                   | System.Windows.Forms.AnchorStyles.Right)));
     156            | System.Windows.Forms.AnchorStyles.Left)
     157            | System.Windows.Forms.AnchorStyles.Right)));
    179158      this.SplitContainer.FixedPanel = System.Windows.Forms.FixedPanel.Panel1;
    180159      this.SplitContainer.IsSplitterFixed = true;
     
    193172      //
    194173      this.SplitContainer.Panel2.Controls.Add(this.CalculatingPanel);
    195       this.SplitContainer.Panel2.Controls.Add(this.DataGridView);
     174      this.SplitContainer.Panel2.Controls.Add(this.dataView);
    196175      this.SplitContainer.Size = new System.Drawing.Size(475, 330);
    197176      this.SplitContainer.SplitterDistance = 25;
     
    217196      this.CalculatingLabel.Text = "Calculating correlation...";
    218197      //
    219       // contextMenu
    220       //
    221       this.contextMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
    222             this.ShowHideColumns});
    223       this.contextMenu.Name = "contextMenu";
    224       this.contextMenu.Size = new System.Drawing.Size(191, 26);
    225       //
    226       // ShowHideColumns
    227       //
    228       this.ShowHideColumns.Name = "ShowHideColumns";
    229       this.ShowHideColumns.Size = new System.Drawing.Size(190, 22);
    230       this.ShowHideColumns.Text = "Show / Hide Columns";
    231       this.ShowHideColumns.Click += new System.EventHandler(this.ShowHideColumns_Click);
     198      // DataGridView
     199      //
     200      this.dataView.Dock = System.Windows.Forms.DockStyle.Fill;
     201      this.dataView.Location = new System.Drawing.Point(0, 0);
     202      this.dataView.Name = "DataView";
     203      this.dataView.ReadOnly = true;
     204      this.dataView.Size = new System.Drawing.Size(475, 301);
     205      this.dataView.TabIndex = 0;
    232206      //
    233207      // AbstractFeatureCorrelationView
     
    241215      this.Name = "AbstractFeatureCorrelationView";
    242216      this.Size = new System.Drawing.Size(569, 336);
    243       ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit();
    244217      ((System.ComponentModel.ISupportInitialize)(this.PictureBox)).EndInit();
    245218      this.SplitContainer.Panel1.ResumeLayout(false);
     
    250223      this.CalculatingPanel.ResumeLayout(false);
    251224      this.CalculatingPanel.PerformLayout();
    252       this.contextMenu.ResumeLayout(false);
    253225      this.ResumeLayout(false);
    254226
     
    257229    #endregion
    258230
    259     protected System.Windows.Forms.DataGridView DataGridView;
    260231    protected System.Windows.Forms.ProgressBar HeatMapProgressBar;
    261232    protected System.Windows.Forms.ComboBox PartitionComboBox;
     
    269240    protected System.Windows.Forms.Panel CalculatingPanel;
    270241    protected System.Windows.Forms.Label CalculatingLabel;
    271     protected System.Windows.Forms.ContextMenuStrip contextMenu;
    272     protected System.Windows.Forms.ToolStripMenuItem ShowHideColumns;
     242    protected HeuristicLab.Problems.DataAnalysis.Views.EnhancedStringConvertibleMatrixView dataView;
    273243
    274244  }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/FeatureCorrelation/AbstractFeatureCorrelationView.cs

    r8729 r8833  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    2422using System.ComponentModel;
    25 using System.Drawing;
    2623using System.Linq;
    27 using System.Text;
    2824using System.Windows.Forms;
    2925using HeuristicLab.Analysis;
    30 using HeuristicLab.Common;
    31 using HeuristicLab.Data.Views;
    32 using HeuristicLab.DataAnalysis.Views;
    3326using HeuristicLab.MainForm;
    3427using HeuristicLab.MainForm.WindowsForms;
     28using HeuristicLab.PluginInfrastructure;
    3529
    3630namespace HeuristicLab.Problems.DataAnalysis.Views {
     
    3832  [Content(typeof(DataAnalysisProblemData), false)]
    3933  public abstract partial class AbstractFeatureCorrelationView : AsynchronousContentView {
    40 
    41     private int[] virtualRowIndices;
    42     private VariableVisibilityDialog variableVisibility;
    43     private List<KeyValuePair<int, SortOrder>> sortedColumnIndices;
    44     private StringConvertibleMatrixView.RowComparer rowComparer;
    45 
    4634    protected FeatureCorrelationCalculator fcc;
    4735    protected HeatMap currentCorrelation;
     
    5442    protected AbstractFeatureCorrelationView() {
    5543      InitializeComponent();
    56       sortedColumnIndices = new List<KeyValuePair<int, SortOrder>>();
    57       rowComparer = new StringConvertibleMatrixView.RowComparer();
    5844      fcc = new FeatureCorrelationCalculator();
    59       var calculatorList = FeatureCorrelationEnums.EnumToList<FeatureCorrelationEnums.CorrelationCalculators>().Select(x => new KeyValuePair<FeatureCorrelationEnums.CorrelationCalculators, string>(x, FeatureCorrelationEnums.GetEnumDescription(x))).ToList();
    60       CorrelationCalcComboBox.ValueMember = "Key";
    61       CorrelationCalcComboBox.DisplayMember = "Value";
    62       CorrelationCalcComboBox.DataSource = new BindingList<KeyValuePair<FeatureCorrelationEnums.CorrelationCalculators, string>>(calculatorList);
    63       var partitionList = FeatureCorrelationEnums.EnumToList<FeatureCorrelationEnums.Partitions>().Select(x => new KeyValuePair<FeatureCorrelationEnums.Partitions, string>(x, FeatureCorrelationEnums.GetEnumDescription(x))).ToList();
    64       PartitionComboBox.ValueMember = "Key";
    65       PartitionComboBox.DisplayMember = "Value";
    66       PartitionComboBox.DataSource = new BindingList<KeyValuePair<FeatureCorrelationEnums.Partitions, string>>(partitionList);
     45      var calculators = ApplicationManager.Manager.GetInstances<IDependencyCalculator>();
     46      var calcList = calculators.OrderBy(c => c.Name).Select(c => new { Name = c.Name, Calculator = c }).ToList();
     47      CorrelationCalcComboBox.ValueMember = "Calculator";
     48      CorrelationCalcComboBox.DisplayMember = "Name";
     49      CorrelationCalcComboBox.DataSource = calcList;
     50      CorrelationCalcComboBox.SelectedItem = calcList.First(c => c.Calculator.GetType().Equals(typeof(PearsonsRDependenceCalculator)));
     51      PartitionComboBox.DataSource = FeatureCorrelationPartitions.Partitions;
     52      PartitionComboBox.SelectedItem = FeatureCorrelationPartitions.TRAININGSAMPLES;
    6753    }
    6854
     
    8167    protected override void OnContentChanged() {
    8268      base.OnContentChanged();
     69      fcc.TryCancelCalculation();
    8370      if (Content != null) {
    8471        fcc.ProblemData = Content;
    85         bool[] initialVisibility = SetInitialVisibilityOfColumns();
    86 
    87         variableVisibility = new VariableVisibilityDialog(Content.Dataset.DoubleVariables, initialVisibility);
    88         variableVisibility.VariableVisibilityChanged += new ItemCheckEventHandler(variableVisibility_VariableVisibilityChanged);
    8972        CalculateCorrelation();
    9073      } else {
    91         DataGridView.Columns.Clear();
    92         DataGridView.Rows.Clear();
     74        dataView.Content = null;
     75        dataView.ResetVisibility();
    9376      }
    9477    }
    9578
    96     protected virtual bool[] SetInitialVisibilityOfColumns() {
     79    protected virtual bool[] SetInitialVariableVisibility() {
    9780      bool[] initialVisibility = new bool[Content.Dataset.DoubleVariables.Count()];
    9881      int i = 0;
     
    10386      return initialVisibility;
    10487    }
    105 
    106     protected abstract void variableVisibility_VariableVisibilityChanged(object sender, ItemCheckEventArgs e);
    10788
    10889    protected void CorrelationMeasureComboBox_SelectedChangeCommitted(object sender, System.EventArgs e) {
     
    11697    protected abstract void Content_CorrelationCalculationFinished(object sender, FeatureCorrelationCalculator.CorrelationCalculationFinishedArgs e);
    11798
    118     protected void UpdateDataGrid() {
    119       virtualRowIndices = Enumerable.Range(0, currentCorrelation.Rows).ToArray();
    120       DataGridViewColumn[] columns = new DataGridViewColumn[currentCorrelation.Columns];
    121       for (int i = 0; i < columns.Length; ++i) {
    122         var column = new DataGridViewTextBoxColumn();
    123         column.FillWeight = 1;
    124         columns[i] = column;
    125       }
    126 
    127       DataGridView.Columns.Clear();
    128       DataGridView.Columns.AddRange(columns);
    129 
    130       DataGridView.RowCount = currentCorrelation.Rows;
    131 
    132       ClearSorting();
    133       UpdateColumnHeaders();
    134       UpdateRowHeaders();
    135 
     99    protected void UpdateDataView() {
    136100      maximumLabel.Text = currentCorrelation.Maximum.ToString();
    137101      minimumLabel.Text = currentCorrelation.Minimum.ToString();
    138102
    139       DataGridView.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.ColumnHeader);
    140       DataGridView.AutoResizeRowHeadersWidth(DataGridViewRowHeadersWidthSizeMode.AutoSizeToDisplayedHeaders);
    141       DataGridView.Enabled = true;
    142     }
    143 
    144     protected virtual void UpdateColumnHeaders() {
    145       for (int i = 0; i < DataGridView.ColumnCount; i++) {
    146         DataGridView.Columns[i].HeaderText = currentCorrelation.ColumnNames.ElementAt(i);
    147         DataGridView.Columns[i].Visible = variableVisibility.Visibility[i];
    148       }
    149     }
    150     protected virtual void UpdateRowHeaders() {
    151       for (int i = 0; i < DataGridView.RowCount; i++) {
    152         DataGridView.Rows[i].HeaderCell.Value = currentCorrelation.RowNames.ElementAt(virtualRowIndices[i]);
    153         DataGridView.Rows[i].Visible = variableVisibility.Visibility[virtualRowIndices[i]];
    154       }
     103      currentCorrelation.SortableView = true;
     104      dataView.Content = currentCorrelation;
     105      dataView.Enabled = true;
    155106    }
    156107
     
    163114      HeatMapProgressBar.Value = e.ProgressPercentage;
    164115    }
    165 
    166     protected void DataGridView_CellValueNeeded(object sender, DataGridViewCellValueEventArgs e) {
    167       if (Content == null) return;
    168       int rowIndex = virtualRowIndices[e.RowIndex];
    169       e.Value = currentCorrelation[rowIndex, e.ColumnIndex];
    170     }
    171 
    172     protected void DataGridView_CellPainting(object sender, DataGridViewCellPaintingEventArgs e) {
    173       if (Content == null) return;
    174       if (e.RowIndex < 0) return;
    175       if (e.ColumnIndex < 0) return;
    176       if (e.State.HasFlag(DataGridViewElementStates.Selected)) return;
    177       if (!e.PaintParts.HasFlag(DataGridViewPaintParts.Background)) return;
    178 
    179       int rowIndex = virtualRowIndices[e.RowIndex];
    180       Color backColor = GetDataPointColor(currentCorrelation[rowIndex, e.ColumnIndex], currentCorrelation.Minimum, currentCorrelation.Maximum);
    181       using (Brush backColorBrush = new SolidBrush(backColor)) {
    182         e.Graphics.FillRectangle(backColorBrush, e.CellBounds);
    183       }
    184       e.PaintContent(e.CellBounds);
    185       e.Handled = true;
    186     }
    187 
    188     protected virtual Color GetDataPointColor(double value, double min, double max) {
    189       if (double.IsNaN(value)) {
    190         return Color.DarkGray;
    191       }
    192       IList<Color> colors = ColorGradient.Colors;
    193       int index = (int)((colors.Count - 1) * (value - min) / (max - min));
    194       if (index >= colors.Count) index = colors.Count - 1;
    195       if (index < 0) index = 0;
    196       return colors[index];
    197     }
    198 
    199     #region sort
    200     protected void DataGridView_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e) {
    201       if (Content != null) {
    202         if (e.Button == MouseButtons.Left) {
    203           bool addToSortedIndices = (Control.ModifierKeys & Keys.Control) == Keys.Control;
    204           SortOrder newSortOrder = SortOrder.Ascending;
    205           if (sortedColumnIndices.Any(x => x.Key == e.ColumnIndex)) {
    206             SortOrder oldSortOrder = sortedColumnIndices.Where(x => x.Key == e.ColumnIndex).First().Value;
    207             int enumLength = Enum.GetValues(typeof(SortOrder)).Length;
    208             newSortOrder = oldSortOrder = (SortOrder)Enum.Parse(typeof(SortOrder), ((((int)oldSortOrder) + 1) % enumLength).ToString());
    209           }
    210 
    211           if (!addToSortedIndices)
    212             sortedColumnIndices.Clear();
    213 
    214           if (sortedColumnIndices.Any(x => x.Key == e.ColumnIndex)) {
    215             int sortedIndex = sortedColumnIndices.FindIndex(x => x.Key == e.ColumnIndex);
    216             if (newSortOrder != SortOrder.None)
    217               sortedColumnIndices[sortedIndex] = new KeyValuePair<int, SortOrder>(e.ColumnIndex, newSortOrder);
    218             else
    219               sortedColumnIndices.RemoveAt(sortedIndex);
    220           } else
    221             if (newSortOrder != SortOrder.None)
    222               sortedColumnIndices.Add(new KeyValuePair<int, SortOrder>(e.ColumnIndex, newSortOrder));
    223           Sort();
    224         }
    225       }
    226     }
    227 
    228     protected virtual void ClearSorting() {
    229       virtualRowIndices = Enumerable.Range(0, currentCorrelation.Rows).ToArray();
    230       sortedColumnIndices.Clear();
    231       UpdateSortGlyph();
    232     }
    233 
    234     private void Sort() {
    235       virtualRowIndices = Sort(sortedColumnIndices);
    236       UpdateSortGlyph();
    237       UpdateRowHeaders();
    238       DataGridView.Invalidate();
    239     }
    240 
    241     protected virtual int[] Sort(IEnumerable<KeyValuePair<int, SortOrder>> sortedColumns) {
    242       int[] newSortedIndex = Enumerable.Range(0, currentCorrelation.Rows).ToArray();
    243       if (sortedColumns.Count() != 0) {
    244         rowComparer.SortedIndices = sortedColumns;
    245         rowComparer.Matrix = currentCorrelation;
    246         Array.Sort(newSortedIndex, rowComparer);
    247       }
    248       return newSortedIndex;
    249     }
    250     private void UpdateSortGlyph() {
    251       foreach (DataGridViewColumn col in this.DataGridView.Columns)
    252         col.HeaderCell.SortGlyphDirection = SortOrder.None;
    253       foreach (KeyValuePair<int, SortOrder> p in sortedColumnIndices)
    254         this.DataGridView.Columns[p.Key].HeaderCell.SortGlyphDirection = p.Value;
    255     }
    256     #endregion
    257 
    258     #region copy
    259     protected void DataGridView_KeyDown(object sender, KeyEventArgs e) {
    260       if (e.Control && e.KeyCode == Keys.C)
    261         CopyValuesFromDataGridView();
    262     }
    263 
    264     private void CopyValuesFromDataGridView() {
    265       if (DataGridView.SelectedCells.Count == 0) return;
    266       StringBuilder s = new StringBuilder();
    267       int minRowIndex = DataGridView.SelectedCells[0].RowIndex;
    268       int maxRowIndex = DataGridView.SelectedCells[DataGridView.SelectedCells.Count - 1].RowIndex;
    269       int minColIndex = DataGridView.SelectedCells[0].ColumnIndex;
    270       int maxColIndex = DataGridView.SelectedCells[DataGridView.SelectedCells.Count - 1].ColumnIndex;
    271 
    272       if (minRowIndex > maxRowIndex) {
    273         int temp = minRowIndex;
    274         minRowIndex = maxRowIndex;
    275         maxRowIndex = temp;
    276       }
    277       if (minColIndex > maxColIndex) {
    278         int temp = minColIndex;
    279         minColIndex = maxColIndex;
    280         maxColIndex = temp;
    281       }
    282 
    283       bool addRowNames = DataGridView.AreAllCellsSelected(false) && currentCorrelation.RowNames.Count() > 0;
    284       bool addColumnNames = DataGridView.AreAllCellsSelected(false) && currentCorrelation.ColumnNames.Count() > 0;
    285 
    286       //add colum names
    287       if (addColumnNames) {
    288         if (addRowNames)
    289           s.Append('\t');
    290 
    291         DataGridViewColumn column = DataGridView.Columns.GetFirstColumn(DataGridViewElementStates.Visible);
    292         while (column != null) {
    293           s.Append(column.HeaderText);
    294           s.Append('\t');
    295           column = DataGridView.Columns.GetNextColumn(column, DataGridViewElementStates.Visible, DataGridViewElementStates.None);
    296         }
    297         s.Remove(s.Length - 1, 1); //remove last tab
    298         s.Append(Environment.NewLine);
    299       }
    300 
    301       for (int i = minRowIndex; i <= maxRowIndex; i++) {
    302         int rowIndex = this.virtualRowIndices[i];
    303         if (addRowNames) {
    304           s.Append(currentCorrelation.RowNames.ElementAt(rowIndex));
    305           s.Append('\t');
    306         }
    307 
    308         DataGridViewColumn column = DataGridView.Columns.GetFirstColumn(DataGridViewElementStates.Visible);
    309         while (column != null) {
    310           DataGridViewCell cell = DataGridView[column.Index, i];
    311           if (cell.Selected) {
    312             s.Append(currentCorrelation[rowIndex, column.Index]);
    313             s.Append('\t');
    314           }
    315 
    316           column = DataGridView.Columns.GetNextColumn(column, DataGridViewElementStates.Visible, DataGridViewElementStates.None);
    317         }
    318         s.Remove(s.Length - 1, 1); //remove last tab
    319         s.Append(Environment.NewLine);
    320       }
    321       Clipboard.SetText(s.ToString());
    322     }
    323     #endregion
    324 
    325     protected void ShowHideColumns_Click(object sender, EventArgs e) {
    326       variableVisibility.ShowDialog();
    327     }
    328 
    329     protected void DataGridView_MouseClick(object sender, MouseEventArgs e) {
    330       if (Content == null) return;
    331       if (e.Button == MouseButtons.Right && DataGridView.Columns.Count != 0)
    332         contextMenu.Show(MousePosition);
    333     }
    334 
    335     protected int GetRowIndexOfVirtualindex(int virtualIndex) {
    336       if (virtualIndex < 0 || virtualIndex >= virtualRowIndices.Length) {
    337         throw new ArgumentException("Virtual index is out of bounds");
    338       }
    339 
    340       for (int i = 0; i < virtualRowIndices.Length; i++) {
    341         if (virtualRowIndices[i] == virtualIndex) {
    342           return i;
    343         }
    344       }
    345       throw new ArgumentException("Virtual index was not found!");
    346     }
    347116  }
    348117}
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/FeatureCorrelation/FeatureCorrelationCalculator.cs

    r8729 r8833  
    5151    }
    5252
    53     public void CalculateElements(FeatureCorrelationEnums.CorrelationCalculators calc, FeatureCorrelationEnums.Partitions partition) {
     53    public void CalculateElements(IDependencyCalculator calc, string partition) {
    5454      CalculateElements(problemData.Dataset, calc, partition);
    5555    }
    5656
    57     // returns if any calculation takes place
    58     public bool CalculateTimeframeElements(FeatureCorrelationEnums.CorrelationCalculators calc, FeatureCorrelationEnums.Partitions partition, string variable, int frames, double[,] correlation = null) {
     57    // returns true if any calculation takes place
     58    public bool CalculateTimeframeElements(IDependencyCalculator calc, string partition, string variable, int frames, double[,] correlation = null) {
    5959      if (correlation == null || correlation.GetLength(1) <= frames) {
    6060        CalculateElements(problemData.Dataset, calc, partition, variable, frames, correlation);
     
    6565    }
    6666
     67    public void TryCancelCalculation() {
     68      if (bw != null && bw.IsBusy) {
     69        bwInfo = null;
     70        bw.CancelAsync();
     71      }
     72    }
     73
    6774    private double[,] GetElementsOfCorrelation(double[,] corr, int frames) {
    6875      double[,] elements = new double[corr.GetLength(0), frames + 1];
     
    7582    }
    7683
    77     private void CalculateElements(Dataset dataset, FeatureCorrelationEnums.CorrelationCalculators calc, FeatureCorrelationEnums.Partitions partition, string variable = null, int frames = 0, double[,] alreadyCalculated = null) {
     84    private void CalculateElements(Dataset dataset, IDependencyCalculator calc, string partition, string variable = null, int frames = 0, double[,] alreadyCalculated = null) {
    7885      bwInfo = new BackgroundWorkerInfo { Dataset = dataset, Calculator = calc, Partition = partition, Variable = variable, Frames = frames, AlreadyCalculated = alreadyCalculated };
    7986      if (bw == null) {
     
    107114      BackgroundWorkerInfo bwInfo = (BackgroundWorkerInfo)e.Argument;
    108115      Dataset dataset = bwInfo.Dataset;
    109       FeatureCorrelationEnums.Partitions partition = bwInfo.Partition;
    110       FeatureCorrelationEnums.CorrelationCalculators calc = bwInfo.Calculator;
     116      string partition = bwInfo.Partition;
     117      IDependencyCalculator calc = bwInfo.Calculator;
    111118
    112119      IList<string> doubleVariableNames = dataset.DoubleVariables.ToList();
     
    121128        for (int j = 0; j < i + 1; j++) {
    122129          if (worker.CancellationPending) {
     130            worker.ReportProgress(100);
    123131            e.Cancel = true;
    124132            return;
     
    127135          IEnumerable<double> var2 = GetRelevantValues(problemData, partition, doubleVariableNames[j]);
    128136
    129           elements[i, j] = CalculateElementWithCalculator(calc, var1, var2, out error);
     137          elements[i, j] = calc.Calculate(var1, var2, out error);
    130138
    131139          if (!error.Equals(OnlineCalculatorError.None)) {
     
    137145      }
    138146      e.Result = elements;
     147      worker.ReportProgress(100);
    139148    }
    140149
     
    144153      BackgroundWorkerInfo bwInfo = (BackgroundWorkerInfo)e.Argument;
    145154      Dataset dataset = bwInfo.Dataset;
    146       FeatureCorrelationEnums.Partitions partition = bwInfo.Partition;
    147       FeatureCorrelationEnums.CorrelationCalculators calc = bwInfo.Calculator;
     155      string partition = bwInfo.Partition;
     156      IDependencyCalculator calc = bwInfo.Calculator;
    148157      string variable = bwInfo.Variable;
    149158      int frames = bwInfo.Frames;
     
    169178        for (int j = start; j <= frames; j++) {
    170179          if (worker.CancellationPending) {
     180            worker.ReportProgress(100);
    171181            e.Cancel = true;
    172182            return;
     
    181191          var1 = help;
    182192
    183           elements[i, j] = CalculateElementWithCalculator(calc, var1, var2, out error);
     193          elements[i, j] = calc.Calculate(var1, var2, out error);
    184194
    185195          if (!error.Equals(OnlineCalculatorError.None)) {
     
    190200      }
    191201      e.Result = elements;
    192     }
    193 
    194     private IEnumerable<double> GetRelevantValues(IDataAnalysisProblemData problemData, FeatureCorrelationEnums.Partitions partition, string variable) {
     202      worker.ReportProgress(100);
     203    }
     204
     205    private IEnumerable<double> GetRelevantValues(IDataAnalysisProblemData problemData, string partition, string variable) {
    195206      IEnumerable<double> var = problemData.Dataset.GetDoubleValues(variable);
    196       if (partition.Equals(FeatureCorrelationEnums.Partitions.TrainingSamples)) {
     207      if (partition.Equals(FeatureCorrelationPartitions.TRAININGSAMPLES)) {
    197208        var = var.Skip(problemData.TrainingPartition.Start).Take(problemData.TrainingPartition.End - problemData.TrainingPartition.Start);
    198       } else if (partition.Equals(FeatureCorrelationEnums.Partitions.TestSamples)) {
     209      } else if (partition.Equals(FeatureCorrelationPartitions.TESTSAMPLES)) {
    199210        var = var.Skip(problemData.TestPartition.Start).Take(problemData.TestPartition.End - problemData.TestPartition.Start);
    200211      }
    201212      return var;
    202     }
    203 
    204     private double CalculateElementWithCalculator(FeatureCorrelationEnums.CorrelationCalculators calc, IEnumerable<double> var1, IEnumerable<double> var2, out OnlineCalculatorError error) {
    205       if (calc.Equals(FeatureCorrelationEnums.CorrelationCalculators.HoeffdingsDependence)) {
    206         return HoeffdingsDependenceCalculator.Calculate(var1, var2, out error);
    207       } else if (calc.Equals(FeatureCorrelationEnums.CorrelationCalculators.SpearmansRank)) {
    208         return SpearmansRankCorrelationCoefficientCalculator.Calculate(var1, var2, out error);
    209       } else if (calc.Equals(FeatureCorrelationEnums.CorrelationCalculators.PearsonsRSquared)) {
    210         return OnlinePearsonsRSquaredCalculator.Calculate(var1, var2, out error);
    211       } else {
    212         return Math.Sqrt(OnlinePearsonsRSquaredCalculator.Calculate(var1, var2, out error));
    213       }
    214213    }
    215214
     
    222221          OnCorrelationCalculationFinished((double[,])e.Result, bwInfo.Calculator, bwInfo.Partition, bwInfo.Variable);
    223222        }
    224       } else {
     223      } else if (bwInfo != null) {
    225224        bw.RunWorkerAsync(bwInfo);
    226225      }
     
    231230    public class CorrelationCalculationFinishedArgs : EventArgs {
    232231      public double[,] Correlation { get; private set; }
    233       public FeatureCorrelationEnums.CorrelationCalculators Calculcator { get; private set; }
    234       public FeatureCorrelationEnums.Partitions Partition { get; private set; }
     232      public IDependencyCalculator Calculcator { get; private set; }
     233      public string Partition { get; private set; }
    235234      public string Variable { get; private set; }
    236235
    237       public CorrelationCalculationFinishedArgs(double[,] correlation, FeatureCorrelationEnums.CorrelationCalculators calculator, FeatureCorrelationEnums.Partitions partition, string variable = null) {
     236      public CorrelationCalculationFinishedArgs(double[,] correlation, IDependencyCalculator calculator, string partition, string variable = null) {
    238237        this.Correlation = correlation;
    239238        this.Calculcator = calculator;
     
    245244    public delegate void CorrelationCalculationFinishedHandler(object sender, CorrelationCalculationFinishedArgs e);
    246245    public event CorrelationCalculationFinishedHandler CorrelationCalculationFinished;
    247     protected virtual void OnCorrelationCalculationFinished(double[,] correlation, FeatureCorrelationEnums.CorrelationCalculators calculator, FeatureCorrelationEnums.Partitions partition, string variable = null) {
     246    protected virtual void OnCorrelationCalculationFinished(double[,] correlation, IDependencyCalculator calculator, string partition, string variable = null) {
    248247      var handler = CorrelationCalculationFinished;
    249248      if (handler != null)
     
    255254    protected void BwProgressChanged(object sender, ProgressChangedEventArgs e) {
    256255      BackgroundWorker worker = sender as BackgroundWorker;
    257       if (!worker.CancellationPending && ProgressCalculation != null) {
     256      if (ProgressCalculation != null) {
    258257        ProgressCalculation(sender, e);
    259258      }
     
    263262    private class BackgroundWorkerInfo {
    264263      public Dataset Dataset { get; set; }
    265       public FeatureCorrelationEnums.CorrelationCalculators Calculator { get; set; }
    266       public FeatureCorrelationEnums.Partitions Partition { get; set; }
     264      public IDependencyCalculator Calculator { get; set; }
     265      public string Partition { get; set; }
    267266      public string Variable { get; set; }
    268267      public int Frames { get; set; }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/FeatureCorrelation/FeatureCorrelationView.cs

    r8729 r8833  
    2020#endregion
    2121
     22using System;
     23using System.Collections.Generic;
    2224using System.Windows.Forms;
    2325using HeuristicLab.Analysis;
     
    2527using HeuristicLab.MainForm;
    2628using HeuristicLab.MainForm.WindowsForms;
     29using HeuristicLab.PluginInfrastructure;
    2730
    2831namespace HeuristicLab.Problems.DataAnalysis.Views {
     
    4043
    4144    protected override void OnContentChanged() {
     45      if (Content != null) {
     46        dataView.RowVisibility = SetInitialVariableVisibility();
     47        dataView.ColumnVisibility = SetInitialVariableVisibility();
     48      }
    4249      correlationCache.Reset();
    4350      base.OnContentChanged();
     
    4653    protected override void CalculateCorrelation() {
    4754      if (CorrelationCalcComboBox.SelectedItem != null && PartitionComboBox.SelectedItem != null) {
    48         FeatureCorrelationEnums.CorrelationCalculators calc = (FeatureCorrelationEnums.CorrelationCalculators)CorrelationCalcComboBox.SelectedValue;
    49         FeatureCorrelationEnums.Partitions partition = (FeatureCorrelationEnums.Partitions)PartitionComboBox.SelectedValue;
    50         DataGridView.Columns.Clear();
    51         DataGridView.Enabled = false;
     55        IDependencyCalculator calc = (IDependencyCalculator)CorrelationCalcComboBox.SelectedValue;
     56        string partition = (string)PartitionComboBox.SelectedValue;
     57        dataView.Enabled = false;
    5258        double[,] corr = correlationCache.GetCorrelation(calc, partition);
    5359        if (corr == null) {
    5460          fcc.CalculateElements(calc, partition);
    5561        } else {
     62          fcc.TryCancelCalculation();
    5663          SetNewCorrelation(corr, calc);
    57           UpdateDataGrid();
     64          UpdateDataView();
    5865        }
    5966      }
    6067    }
    6168
    62     private void SetNewCorrelation(double[,] elements, FeatureCorrelationEnums.CorrelationCalculators calc) {
    63       DoubleRange range = FeatureCorrelationEnums.calculatorInterval[calc];
     69    private void SetNewCorrelation(double[,] elements, IDependencyCalculator calc) {
     70      DoubleRange range = calc.Interval;
    6471      HeatMap hm = new HeatMap(elements, "", range.End, range.Start);
    6572      hm.RowNames = Content.Dataset.DoubleVariables;
     
    7481        correlationCache.SetCorrelation(e.Calculcator, e.Partition, e.Correlation);
    7582        SetNewCorrelation(e.Correlation, e.Calculcator);
    76         UpdateDataGrid();
     83        UpdateDataView();
    7784      }
    7885    }
    7986
    80     protected override void variableVisibility_VariableVisibilityChanged(object sender, ItemCheckEventArgs e) {
    81       DataGridView.Columns[e.Index].Visible = e.NewValue == CheckState.Checked;
    82       DataGridView.Rows[GetRowIndexOfVirtualindex(e.Index)].Visible = e.NewValue == CheckState.Checked;
     87    [NonDiscoverableType]
     88    private class FeatureCorrelationCache : Object {
     89      private Dictionary<Tuple<IDependencyCalculator, string>, double[,]> correlationsCache;
     90
     91      public FeatureCorrelationCache()
     92        : base() {
     93        InitializeCaches();
     94      }
     95
     96      private void InitializeCaches() {
     97        correlationsCache = new Dictionary<Tuple<IDependencyCalculator, string>, double[,]>();
     98      }
     99
     100      public void Reset() {
     101        InitializeCaches();
     102      }
     103
     104      public double[,] GetCorrelation(IDependencyCalculator calc, string partition) {
     105        double[,] corr;
     106        var key = new Tuple<IDependencyCalculator, string>(calc, partition);
     107        correlationsCache.TryGetValue(key, out corr);
     108        return corr;
     109      }
     110
     111      public void SetCorrelation(IDependencyCalculator calc, string partition, double[,] correlation) {
     112        var key = new Tuple<IDependencyCalculator, string>(calc, partition);
     113        correlationsCache[key] = correlation;
     114      }
    83115    }
    84116  }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/FeatureCorrelation/TimeframeFeatureCorrelationView.Designer.cs

    r8578 r8833  
    4949      this.VariableSelectionComboBox = new System.Windows.Forms.ComboBox();
    5050      this.TimeFrameLabel = new System.Windows.Forms.Label();
    51       this.TimeframeComboBox = new System.Windows.Forms.ComboBox();
     51      this.TimeframeTextbox = new System.Windows.Forms.TextBox();
    5252      ((System.ComponentModel.ISupportInitialize)(this.PictureBox)).BeginInit();
    5353      ((System.ComponentModel.ISupportInitialize)(this.SplitContainer)).BeginInit();
     
    7878      //
    7979      this.SplitContainer.Panel1.Controls.Add(this.VariableSelectionComboBox);
    80       this.SplitContainer.Panel1.Controls.Add(this.TimeframeComboBox);
     80      this.SplitContainer.Panel1.Controls.Add(this.TimeframeTextbox);
    8181      this.SplitContainer.Panel1.Controls.Add(this.TimeFrameLabel);
    8282      this.SplitContainer.Panel1.Controls.Add(this.VariableSelectionLabel);
     
    117117      // TimeframeComboBox
    118118      //
    119       this.TimeframeComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
    120       this.TimeframeComboBox.FormattingEnabled = true;
    121       this.TimeframeComboBox.Location = new System.Drawing.Point(344, 30);
    122       this.TimeframeComboBox.Name = "TimeframeComboBox";
    123       this.TimeframeComboBox.Size = new System.Drawing.Size(131, 21);
    124       this.TimeframeComboBox.TabIndex = 19;
    125       this.TimeframeComboBox.SelectionChangeCommitted += new System.EventHandler(this.TimeframeComboBox_SelectedChangeCommitted);
     119      this.TimeframeTextbox.Location = new System.Drawing.Point(344, 30);
     120      this.TimeframeTextbox.Name = "TimeframeTextbox";
     121      this.TimeframeTextbox.Size = new System.Drawing.Size(131, 21);
     122      this.TimeframeTextbox.TabIndex = 19;
     123      this.TimeframeTextbox.Text = "5";
     124      this.TimeframeTextbox.KeyDown += new System.Windows.Forms.KeyEventHandler(TimeframeTextbox_KeyDown);
    126125      //
    127126      // TimeframeFeatureCorrelationView
     
    146145    protected System.Windows.Forms.ComboBox VariableSelectionComboBox;
    147146    protected System.Windows.Forms.Label TimeFrameLabel;
    148     protected System.Windows.Forms.ComboBox TimeframeComboBox;
     147    protected System.Windows.Forms.TextBox TimeframeTextbox;
    149148  }
    150149}
  • 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  }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/HeuristicLab.Problems.DataAnalysis.Views-3.4.csproj

    r8798 r8833  
    162162      <DependentUpon>DataAnalysisSolutionEvaluationView.cs</DependentUpon>
    163163    </Compile>
     164    <Compile Include="FeatureCorrelation\EnhancedStringConvertibleMatrixView.cs">
     165      <SubType>UserControl</SubType>
     166    </Compile>
     167    <Compile Include="FeatureCorrelation\EnhancedStringConvertibleMatrixView.Designer.cs">
     168      <DependentUpon>EnhancedStringConvertibleMatrixView.cs</DependentUpon>
     169    </Compile>
    164170    <Compile Include="FeatureCorrelation\FeatureCorrelationCalculator.cs" />
    165     <Compile Include="FeatureCorrelation\FeatureCorrelationEnums.cs" />
    166     <Compile Include="FeatureCorrelation\VariableVisibilityDialog.cs">
    167       <SubType>Form</SubType>
    168     </Compile>
    169     <Compile Include="FeatureCorrelation\VariableVisibilityDialog.Designer.cs">
    170       <DependentUpon>VariableVisibilityDialog.cs</DependentUpon>
    171     </Compile>
     171    <Compile Include="FeatureCorrelation\FeatureCorrelationHelpers.cs" />
    172172    <Compile Include="FeatureCorrelation\FeatureCorrelationView.cs">
    173173      <SubType>UserControl</SubType>
     
    176176      <DependentUpon>FeatureCorrelationView.cs</DependentUpon>
    177177    </Compile>
    178     <Compile Include="FeatureCorrelation\FeatureCorrelationCache.cs" />
    179     <Compile Include="FeatureCorrelation\FeatureCorrelationTimeframeCache.cs" />
    180178    <Compile Include="Plugin.cs" />
    181179    <Compile Include="ProblemDataView.cs">
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/ProblemDataView.cs

    r8689 r8833  
    4545
    4646    protected void FeatureCorrelationButton_Click(object sender, System.EventArgs e) {
    47       Type viewType = MainFormManager.GetViewTypes(this.Content.GetType(), true).FirstOrDefault(t => typeof(AbstractFeatureCorrelationView).IsAssignableFrom(t));
     47      Type viewType = MainFormManager.GetViewTypes(this.Content.GetType(), true).FirstOrDefault(t => typeof(FeatureCorrelationView).IsAssignableFrom(t));
    4848      MainFormManager.MainForm.ShowContent(Content, viewType);
    4949    }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionFeatureCorrelationView.cs

    r8689 r8833  
    3737    }
    3838
    39     protected override bool[] SetInitialVisibilityOfColumns() {
     39    protected override bool[] SetInitialVariableVisibility() {
    4040      int i = Content.Dataset.DoubleVariables.ToList().FindIndex(x => x == Content.TargetVariable);
    41       var initialVisibility = base.SetInitialVisibilityOfColumns();
     41      var initialVisibility = base.SetInitialVariableVisibility();
    4242      initialVisibility[i] = true;
    4343      return initialVisibility;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionTimeframeFeatureCorrelationView.cs

    r8689 r8833  
    3737    }
    3838
    39     protected override bool[] SetInitialVisibilityOfColumns() {
     39    protected override bool[] SetInitialVariableVisibility() {
    4040      int i = Content.Dataset.DoubleVariables.ToList().FindIndex(x => x == Content.TargetVariable);
    41       var initialVisibility = base.SetInitialVisibilityOfColumns();
     41      var initialVisibility = base.SetInitialVariableVisibility();
    4242      initialVisibility[i] = true;
    4343      return initialVisibility;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/HeuristicLab.Problems.DataAnalysis-3.4.csproj

    r8798 r8833  
    152152    </Compile>
    153153    <Compile Include="Interfaces\Classification\IDiscriminantFunctionThresholdCalculator.cs" />
     154    <Compile Include="Interfaces\IDependencyCalculator.cs" />
    154155    <Compile Include="Interfaces\Regression\IRegressionEnsembleModel.cs">
    155156      <SubType>Code</SubType>
     
    206207    <Compile Include="OnlineCalculators\OnlineTheilsUStatisticCalculator.cs" />
    207208    <Compile Include="OnlineCalculators\OnlineWeightedDirectionalSymmetryCalculator.cs" />
     209    <Compile Include="OnlineCalculators\PearsonsRDependenceCalculator.cs" />
     210    <Compile Include="OnlineCalculators\PearsonsRSquaredDependenceCalculator.cs" />
    208211    <Compile Include="OnlineCalculators\SpearmansRankCorrelationCoefficientCalculator.cs" />
    209212    <Compile Include="Plugin.cs" />
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/HoeffdingsDependenceCalculator.cs

    r8542 r8833  
    2323using System.Collections.Generic;
    2424using System.Linq;
     25using HeuristicLab.Data;
    2526
    2627namespace HeuristicLab.Problems.DataAnalysis {
    27   public class HoeffdingsDependenceCalculator {
     28  public class HoeffdingsDependenceCalculator : IDependencyCalculator {
    2829
    29     public static double Calculate(IEnumerable<double> originalValues, IEnumerable<double> estimatedValues, out OnlineCalculatorError errorState) {
     30    public DoubleRange Interval { get { return new DoubleRange(1.0, -0.5); } }
     31
     32    public string Name { get { return "Hoeffdings Dependence"; } }
     33
     34    public double Calculate(IEnumerable<double> originalValues, IEnumerable<double> estimatedValues, out OnlineCalculatorError errorState) {
     35      return HoeffdingsDependenceCalculator.CalculateHoeffdings(originalValues, estimatedValues, out errorState);
     36    }
     37
     38    public static double CalculateHoeffdings(IEnumerable<double> originalValues, IEnumerable<double> estimatedValues, out OnlineCalculatorError errorState) {
    3039      double d = HoeffD(originalValues, estimatedValues, out errorState);
    3140      if (errorState != OnlineCalculatorError.None) return double.NaN;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/SpearmansRankCorrelationCoefficientCalculator.cs

    r8728 r8833  
    2222using System.Collections.Generic;
    2323using System.Linq;
     24using HeuristicLab.Data;
    2425
    2526namespace HeuristicLab.Problems.DataAnalysis {
    26   public class SpearmansRankCorrelationCoefficientCalculator {
     27  public class SpearmansRankCorrelationCoefficientCalculator : IDependencyCalculator {
    2728
    28     public static double Calculate(IEnumerable<double> originalValues, IEnumerable<double> estimatedValues, out OnlineCalculatorError errorState) {
     29    public DoubleRange Interval { get { return new DoubleRange(1.0, -1.0); } }
     30
     31    public string Name { get { return "Spearmans Rank"; } }
     32
     33    public double Calculate(IEnumerable<double> originalValues, IEnumerable<double> estimatedValues, out OnlineCalculatorError errorState) {
     34      return SpearmansRankCorrelationCoefficientCalculator.CalculateSpearmansRank(originalValues, estimatedValues, out errorState);
     35    }
     36
     37    public static double CalculateSpearmansRank(IEnumerable<double> originalValues, IEnumerable<double> estimatedValues, out OnlineCalculatorError errorState) {
    2938      double rs = double.NaN;
    3039      try {
Note: See TracChangeset for help on using the changeset viewer.