Free cookie consent management tool by TermsFeed Policy Generator

Changeset 8689


Ignore:
Timestamp:
09/24/12 18:48:16 (12 years ago)
Author:
sforsten
Message:

#1292:

  • NaN values are used, if the calculation is invalid (e.g. missing values, infinity etc.)
  • Variables can now be filtered. Initially allowed input variables and target variable are shown, but with a right click a dialog can be opened to select variables, which shall be shown
Location:
trunk/sources
Files:
10 added
9 edited

Legend:

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

    r8578 r8689  
    4646    /// </summary>
    4747    private void InitializeComponent() {
     48      this.components = new System.ComponentModel.Container();
    4849      System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(AbstractFeatureCorrelationView));
    4950      this.DataGridView = new System.Windows.Forms.DataGridView();
     
    5960      this.CalculatingPanel = new System.Windows.Forms.Panel();
    6061      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();
    6164      ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit();
    6265      ((System.ComponentModel.ISupportInitialize)(this.PictureBox)).BeginInit();
     
    6669      this.SplitContainer.SuspendLayout();
    6770      this.CalculatingPanel.SuspendLayout();
     71      this.contextMenu.SuspendLayout();
    6872      this.SuspendLayout();
    6973      //
     
    8488      this.DataGridView.ColumnHeaderMouseClick += new System.Windows.Forms.DataGridViewCellMouseEventHandler(this.DataGridView_ColumnHeaderMouseClick);
    8589      this.DataGridView.KeyDown += new System.Windows.Forms.KeyEventHandler(this.DataGridView_KeyDown);
     90      this.DataGridView.MouseClick += new System.Windows.Forms.MouseEventHandler(this.DataGridView_MouseClick);
    8691      //
    8792      // HeatMapProgressBar
     
    211216      this.CalculatingLabel.TabIndex = 10;
    212217      this.CalculatingLabel.Text = "Calculating correlation...";
     218      //
     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);
    213232      //
    214233      // AbstractFeatureCorrelationView
     
    231250      this.CalculatingPanel.ResumeLayout(false);
    232251      this.CalculatingPanel.PerformLayout();
     252      this.contextMenu.ResumeLayout(false);
    233253      this.ResumeLayout(false);
    234254
     
    249269    protected System.Windows.Forms.Panel CalculatingPanel;
    250270    protected System.Windows.Forms.Label CalculatingLabel;
     271    protected System.Windows.Forms.ContextMenuStrip contextMenu;
     272    protected System.Windows.Forms.ToolStripMenuItem ShowHideColumns;
    251273
    252274  }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/FeatureCorrelation/AbstractFeatureCorrelationView.cs

    r8578 r8689  
    3030using HeuristicLab.Common;
    3131using HeuristicLab.Data.Views;
     32using HeuristicLab.DataAnalysis.Views;
    3233using HeuristicLab.MainForm;
    3334using HeuristicLab.MainForm.WindowsForms;
     
    4041
    4142    private int[] virtualRowIndices;
     43    private VariableVisibilityDialog variableVisibility;
    4244    private List<KeyValuePair<int, SortOrder>> sortedColumnIndices;
    4345    private StringConvertibleMatrixView.RowComparer rowComparer;
     
    8284      if (Content != null) {
    8385        fcc.ProblemData = Content;
     86        bool[] initialVisibility = SetInitialVisibilityOfColumns();
     87
     88        variableVisibility = new VariableVisibilityDialog(Content.Dataset.DoubleVariables, initialVisibility);
     89        variableVisibility.VariableVisibilityChanged += new ItemCheckEventHandler(variableVisibility_VariableVisibilityChanged);
    8490        CalculateCorrelation();
    8591      } else {
     
    8894      }
    8995    }
     96
     97    protected virtual bool[] SetInitialVisibilityOfColumns() {
     98      bool[] initialVisibility = new bool[Content.Dataset.DoubleVariables.Count()];
     99      int i = 0;
     100      foreach (var variable in Content.Dataset.DoubleVariables) {
     101        initialVisibility[i] = Content.AllowedInputVariables.Contains(variable);
     102        i++;
     103      }
     104      return initialVisibility;
     105    }
     106
     107    protected abstract void variableVisibility_VariableVisibilityChanged(object sender, ItemCheckEventArgs e);
    90108
    91109    protected void CorrelationMeasureComboBox_SelectedChangeCommitted(object sender, System.EventArgs e) {
     
    127145      for (int i = 0; i < DataGridView.ColumnCount; i++) {
    128146        DataGridView.Columns[i].HeaderText = currentCorrelation.ColumnNames.ElementAt(i);
     147        DataGridView.Columns[i].Visible = variableVisibility.Visibility[i];
    129148      }
    130149    }
     
    132151      for (int i = 0; i < DataGridView.RowCount; i++) {
    133152        DataGridView.Rows[i].HeaderCell.Value = currentCorrelation.RowNames.ElementAt(virtualRowIndices[i]);
     153        DataGridView.Rows[i].Visible = variableVisibility.Visibility[virtualRowIndices[i]];
    134154      }
    135155    }
     
    169189
    170190    protected virtual Color GetDataPointColor(double value, double min, double max) {
     191      if (double.IsNaN(value)) {
     192        return Color.DarkGray;
     193      }
    171194      IList<Color> colors = ColorGradient.Colors;
    172195      int index = (int)((colors.Count - 1) * (value - min) / (max - min));
     
    301324    }
    302325    #endregion
     326
     327    protected void ShowHideColumns_Click(object sender, EventArgs e) {
     328      variableVisibility.ShowDialog();
     329    }
     330
     331    protected void DataGridView_MouseClick(object sender, MouseEventArgs e) {
     332      if (Content == null) return;
     333      if (e.Button == MouseButtons.Right && DataGridView.Columns.Count != 0)
     334        contextMenu.Show(MousePosition);
     335    }
     336
     337    protected int GetRowIndexOfVirtualindex(int virtualIndex) {
     338      if (virtualIndex < 0 || virtualIndex >= virtualRowIndices.Length) {
     339        throw new ArgumentException("Virtual index is out of bounds");
     340      }
     341
     342      for (int i = 0; i < virtualRowIndices.Length; i++) {
     343        if (virtualRowIndices[i] == virtualIndex) {
     344          return i;
     345        }
     346      }
     347      throw new ArgumentException("Virtual index was not found!");
     348    }
    303349  }
    304350}
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/FeatureCorrelation/AbstractFeatureCorrelationView.resx

    r8578 r8689  
    10201020</value>
    10211021  </data>
     1022  <metadata name="contextMenu.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
     1023    <value>17, 17</value>
     1024  </metadata>
    10221025</root>
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/FeatureCorrelation/FeatureCorrelationView.cs

    r8578 r8689  
    7878      }
    7979    }
     80
     81    protected override void variableVisibility_VariableVisibilityChanged(object sender, ItemCheckEventArgs e) {
     82      DataGridView.Columns[e.Index].Visible = e.NewValue == CheckState.Checked;
     83      DataGridView.Rows[GetRowIndexOfVirtualindex(e.Index)].Visible = e.NewValue == CheckState.Checked;
     84    }
    8085  }
    8186}
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/FeatureCorrelation/TimeframeFeatureCorrelationView.cs

    r8578 r8689  
    107107      }
    108108    }
     109
     110    protected override void variableVisibility_VariableVisibilityChanged(object sender, ItemCheckEventArgs e) {
     111      DataGridView.Rows[GetRowIndexOfVirtualindex(e.Index)].Visible = e.NewValue == CheckState.Checked;
     112    }
    109113  }
    110114}
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/HeuristicLab.Problems.DataAnalysis.Views-3.4.csproj

    r8679 r8689  
    126126      <DependentUpon>ClassificationEnsembleSolutionModelView.cs</DependentUpon>
    127127    </Compile>
     128    <Compile Include="Classification\ClassificationFeatureCorrelationView.cs">
     129      <SubType>UserControl</SubType>
     130    </Compile>
     131    <Compile Include="Classification\ClassificationFeatureCorrelationView.Designer.cs">
     132      <DependentUpon>ClassificationFeatureCorrelationView.cs</DependentUpon>
     133    </Compile>
     134    <Compile Include="Classification\ClassificationTimeframeFeatureCorrelationView.cs">
     135      <SubType>UserControl</SubType>
     136    </Compile>
     137    <Compile Include="Classification\ClassificationTimeframeFeatureCorrelationView.Designer.cs">
     138      <DependentUpon>ClassificationTimeframeFeatureCorrelationView.cs</DependentUpon>
     139    </Compile>
    128140    <Compile Include="Classification\DiscriminantFunctionClassificationModelView.cs">
    129141      <SubType>UserControl</SubType>
     
    149161    <Compile Include="DataAnalysisSolutionEvaluationView.Designer.cs">
    150162      <DependentUpon>DataAnalysisSolutionEvaluationView.cs</DependentUpon>
     163    </Compile>
     164    <Compile Include="FeatureCorrelation\VariableVisibilityDialog.cs">
     165      <SubType>Form</SubType>
     166    </Compile>
     167    <Compile Include="FeatureCorrelation\VariableVisibilityDialog.Designer.cs">
     168      <DependentUpon>VariableVisibilityDialog.cs</DependentUpon>
    151169    </Compile>
    152170    <Compile Include="FeatureCorrelation\FeatureCorrelationView.cs">
     
    164182    <Compile Include="ProblemDataView.Designer.cs">
    165183      <DependentUpon>ProblemDataView.cs</DependentUpon>
     184    </Compile>
     185    <Compile Include="Regression\RegressionFeatureCorrelationView.cs">
     186      <SubType>UserControl</SubType>
     187    </Compile>
     188    <Compile Include="Regression\RegressionFeatureCorrelationView.Designer.cs">
     189      <DependentUpon>RegressionFeatureCorrelationView.cs</DependentUpon>
     190    </Compile>
     191    <Compile Include="Regression\RegressionTimeframeFeatureCorrelationView.cs">
     192      <SubType>UserControl</SubType>
     193    </Compile>
     194    <Compile Include="Regression\RegressionTimeframeFeatureCorrelationView.Designer.cs">
     195      <DependentUpon>RegressionTimeframeFeatureCorrelationView.cs</DependentUpon>
    166196    </Compile>
    167197    <Compile Include="Regression\RegressionEnsembleSolutionModelView.cs">
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/ProblemDataView.cs

    r8593 r8689  
    4545
    4646    protected void FeatureCorrelationButton_Click(object sender, System.EventArgs e) {
    47       ViewHost viewHost = new ViewHost();
    48       viewHost.Content = (DataAnalysisProblemData)this.Content.Clone();
    49       viewHost.ViewType = typeof(FeatureCorrelationView);
    50       viewHost.Show();
     47      Type viewType = MainFormManager.GetViewTypes(this.Content.GetType(), true).FirstOrDefault(t => typeof(AbstractFeatureCorrelationView).IsAssignableFrom(t));
     48      MainFormManager.MainForm.ShowContent(Content, viewType);
    5149    }
    5250
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/FeatureCorrelation/FeatureCorrelationCalculator.cs

    r8578 r8689  
    111111
    112112      IList<string> doubleVariableNames = dataset.DoubleVariables.ToList();
    113       OnlineCalculatorError error;
     113      OnlineCalculatorError error = OnlineCalculatorError.None;
    114114      int length = doubleVariableNames.Count;
    115115      double[,] elements = new double[length, length];
     
    124124            return;
    125125          }
    126 
    127126          IEnumerable<double> var1 = GetRelevantValues(problemData, partition, doubleVariableNames[i]);
    128127          IEnumerable<double> var2 = GetRelevantValues(problemData, partition, doubleVariableNames[j]);
     
    130129          elements[i, j] = CalculateElementWithCalculator(calc, var1, var2, out error);
    131130
     131          if (!error.Equals(OnlineCalculatorError.None)) {
     132            elements[i, j] = double.NaN;
     133          }
    132134          elements[j, i] = elements[i, j];
    133           if (!error.Equals(OnlineCalculatorError.None)) {
    134             worker.ReportProgress(100);
    135             throw new ArgumentException("Calculator returned " + error + Environment.NewLine + "Maybe try another calculator.");
    136           }
    137135          worker.ReportProgress((int)Math.Round((((Math.Pow(i, 2) + i) / 2 + j + 1.0) / calculations) * 100));
    138136        }
     
    153151
    154152      IList<string> doubleVariableNames = dataset.DoubleVariables.ToList();
    155       OnlineCalculatorError error;
     153      OnlineCalculatorError error = OnlineCalculatorError.None;
    156154      int length = doubleVariableNames.Count;
    157155      double[,] elements = new double[length, frames + 1];
     
    186184
    187185          if (!error.Equals(OnlineCalculatorError.None)) {
    188             worker.ReportProgress(100);
    189             throw new ArgumentException("Calculator returned " + error + Environment.NewLine + "Maybe try another calculator.");
     186            elements[i, j] = double.NaN;
    190187          }
    191188          worker.ReportProgress((int)((100.0 / calculations) * (i * (frames + 1) + j + 1)));
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/SpearmansRankCorrelationCoefficientCalculator.cs

    r8542 r8689  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    2324using System.Linq;
     
    2728
    2829    public static double Calculate(IEnumerable<double> originalValues, IEnumerable<double> estimatedValues, out OnlineCalculatorError errorState) {
    29       double rs = alglib.basestat.spearmancorr2(originalValues.ToArray(), estimatedValues.ToArray(), originalValues.Count());
    30       errorState = OnlineCalculatorError.None;
     30      double rs = double.NaN;
     31      try {
     32        rs = alglib.basestat.spearmancorr2(originalValues.ToArray(), estimatedValues.ToArray(), originalValues.Count());
     33        errorState = OnlineCalculatorError.None;
     34      }
     35      catch (Exception ex) {
     36        errorState = OnlineCalculatorError.InvalidValueAdded;
     37      }
     38
    3139      return rs;
    3240    }
Note: See TracChangeset for help on using the changeset viewer.