Free cookie consent management tool by TermsFeed Policy Generator

Changeset 15665


Ignore:
Timestamp:
01/29/18 17:19:06 (7 years ago)
Author:
fholzing
Message:

#2871: Implemented review-issues

Location:
trunk/sources
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionVariableImpactsView.Designer.cs

    r15637 r15665  
    1919 */
    2020#endregion
     21using System;
     22using System.Linq;
     23
    2124namespace HeuristicLab.Problems.DataAnalysis.Views {
    2225  partial class RegressionSolutionVariableImpactsView {
     
    8083      this.sortByComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
    8184      this.sortByComboBox.FormattingEnabled = true;
    82       this.sortByComboBox.Items.AddRange(new object[] {
    83             "Impact Value",
    84             "Occurrence",
    85             "Variable Name"});
    8685      this.sortByComboBox.Location = new System.Drawing.Point(407, 3);
    8786      this.sortByComboBox.Name = "sortByComboBox";
     
    9291      // factorVarReplComboBox
    9392      //
     93      this.factorVarReplComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
    9494      this.factorVarReplComboBox.FormattingEnabled = true;
    9595      this.factorVarReplComboBox.Items.AddRange(new object[] {
     
    114114      // replacementComboBox
    115115      //
     116      this.replacementComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
    116117      this.replacementComboBox.FormattingEnabled = true;
    117118      this.replacementComboBox.Items.AddRange(new object[] {
     
    146147      // dataPartitionComboBox
    147148      //
     149      this.dataPartitionComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
    148150      this.dataPartitionComboBox.FormattingEnabled = true;
    149151      this.dataPartitionComboBox.Items.AddRange(new object[] {
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionVariableImpactsView.cs

    r15637 r15665  
    1919 */
    2020#endregion
     21
    2122using System;
    2223using System.Collections.Generic;
     
    2627using HeuristicLab.Data;
    2728using HeuristicLab.MainForm;
    28 using HeuristicLab.Problems.DataAnalysis.Symbolic.Regression;
    2929
    3030namespace HeuristicLab.Problems.DataAnalysis.Views {
     
    3232  [Content(typeof(IRegressionSolution))]
    3333  public partial class RegressionSolutionVariableImpactsView : DataAnalysisSolutionEvaluationView {
    34 
    35     private const int ORDER_BY_IMPACT = 0;
    36     private const int ORDER_BY_OCCURRENCE = 1;
    37     private const int ORDER_BY_NAME = 2;
    38 
    3934    private Dictionary<string, double> rawVariableImpacts = new Dictionary<string, double>();
    4035
     
    4944      : base() {
    5045      InitializeComponent();
     46
     47      //Little workaround. If you fill the ComboBox-Items in the other partial class, the UI-Designer will moan.
     48      this.sortByComboBox.Items.AddRange(Enum.GetValues(typeof(RegressionSolutionVariableImpactsCalculator.SortingCriteria)).Cast<object>().ToArray());
     49      this.sortByComboBox.SelectedItem = RegressionSolutionVariableImpactsCalculator.SortingCriteria.ImpactValue;
     50
    5151      this.dataPartitionComboBox.SelectedIndex = 0;
    5252      this.replacementComboBox.SelectedIndex = 0;
     
    8484    }
    8585
     86
     87    private void dataPartitionComboBox_SelectedIndexChanged(object sender, EventArgs e) {
     88      UpdateVariableImpacts();
     89    }
     90
     91    private void replacementComboBox_SelectedIndexChanged(object sender, EventArgs e) {
     92      UpdateVariableImpacts();
     93    }
     94
     95    private void sortByComboBox_SelectedIndexChanged(object sender, EventArgs e) {
     96      //Update the default ordering (asc,desc), but remove the eventHandler beforehand (otherwise the data would be ordered twice)
     97      ascendingCheckBox.CheckedChanged -= ascendingCheckBox_CheckedChanged;
     98      switch ((RegressionSolutionVariableImpactsCalculator.SortingCriteria)sortByComboBox.SelectedItem) {
     99        case RegressionSolutionVariableImpactsCalculator.SortingCriteria.ImpactValue:
     100          ascendingCheckBox.Checked = false;
     101          break;
     102        case RegressionSolutionVariableImpactsCalculator.SortingCriteria.Occurrence:
     103          ascendingCheckBox.Checked = true;
     104          break;
     105        case RegressionSolutionVariableImpactsCalculator.SortingCriteria.VariableName:
     106          ascendingCheckBox.Checked = true;
     107          break;
     108        default:
     109          throw new Exception("Cannot interpret SortingCriteria");
     110      }
     111      ascendingCheckBox.CheckedChanged += ascendingCheckBox_CheckedChanged;
     112
     113      UpdateDataOrdering();
     114    }
     115
     116    private void ascendingCheckBox_CheckedChanged(object sender, EventArgs e) {
     117      UpdateDataOrdering();
     118    }
     119    #endregion
     120
     121    #region Helper Methods         
    86122    private void UpdateVariableImpacts() {
    87123      if (Content == null || replacementComboBox.SelectedIndex < 0
     
    103139          mainForm.AddOperationProgressToView(this, "Calculating variable impacts for " + Content.Name);
    104140
     141          //Remember the original ordering of the variables
    105142          var impacts = RegressionSolutionVariableImpactsCalculator.CalculateImpacts(Content, dataPartition, replMethod, factorReplMethod);
    106           var impactArray = new DoubleArray(impacts.Select(i => i.Item2).ToArray());
    107           impactArray.ElementNames = impacts.Select(i => i.Item1);
    108           variableImactsArrayView.Content = (DoubleArray)impactArray.AsReadOnly();
    109 
    110           //Remember the original ordering of the variables
    111143          var problemData = Content.ProblemData;
    112144          var inputvariables = new HashSet<string>(problemData.AllowedInputVariables.Union(Content.Model.VariablesUsedForPrediction));
     
    114146          rawVariableImpacts.Clear();
    115147          originalVariableOrdering.ForEach(v => rawVariableImpacts.Add(v, impacts.First(vv => vv.Item1 == v).Item2));
    116 
    117148        } finally {
    118149          mainForm.RemoveOperationProgressFromView(this);
     150          UpdateDataOrdering();
    119151        }
    120152      });
    121153    }
    122154
    123     private void dataPartitionComboBox_SelectedIndexChanged(object sender, EventArgs e) {
    124       ResetOrdering();
    125       UpdateVariableImpacts();
    126     }
    127 
    128     private void replacementComboBox_SelectedIndexChanged(object sender, EventArgs e) {
    129       ResetOrdering();
    130       UpdateVariableImpacts();
    131     }
    132 
    133     private void sortByComboBox_SelectedIndexChanged(object sender, EventArgs e) {
    134       //Update the default ordering (asc,desc), but remove the eventHandler beforehand (otherwise the data would be ordered twice)
    135       ascendingCheckBox.CheckedChanged -= ascendingCheckBox_CheckedChanged;
    136       switch (sortByComboBox.SelectedIndex) {
    137         case ORDER_BY_IMPACT: {
    138             ascendingCheckBox.Checked = false;
    139             break;
    140           }
    141         case ORDER_BY_OCCURRENCE: {
    142             ascendingCheckBox.Checked = true;
    143             break;
    144           }
    145         case ORDER_BY_NAME: {
    146             ascendingCheckBox.Checked = true;
    147             break;
    148           }
    149       }
    150       ascendingCheckBox.CheckedChanged += ascendingCheckBox_CheckedChanged;
    151 
    152       UpdateDataOrdering();
    153     }
    154 
    155     private void ascendingCheckBox_CheckedChanged(object sender, EventArgs e) {
    156       UpdateDataOrdering();
    157     }
    158     #endregion
    159 
    160     #region Helper Methods
    161155    /// <summary>
    162156    /// Updates the <see cref="variableImactsArrayView"/> according to the selected ordering <see cref="ascendingCheckBox"/> of the selected Column <see cref="sortByComboBox"/>
     
    164158    /// </summary>
    165159    private void UpdateDataOrdering() {
    166       int orderIdx = sortByComboBox.SelectedIndex;
     160      //Check if valid sortingCriteria is selected and data exists
     161      if (sortByComboBox.SelectedIndex == -1 || rawVariableImpacts == null || !rawVariableImpacts.Any()) { return; }
     162
     163      var selectedItem = (RegressionSolutionVariableImpactsCalculator.SortingCriteria)sortByComboBox.SelectedItem;
    167164      bool ascending = ascendingCheckBox.Checked;
    168165
    169       //Check if valid ordering is selected AND at if any VariableImpact exists
    170       if (orderIdx > -1 && rawVariableImpacts != null && rawVariableImpacts.Any()) {
    171         IEnumerable<KeyValuePair<string, double>> orderedEntries = null;
     166      IEnumerable<KeyValuePair<string, double>> orderedEntries = null;
    172167
    173         //Sort accordingly
    174         switch (orderIdx) {
    175           case ORDER_BY_IMPACT: {
    176               orderedEntries = ascending ? rawVariableImpacts.OrderBy(v => v.Value) : rawVariableImpacts.OrderByDescending(v => v.Value);
    177               break;
    178             }
    179           case ORDER_BY_OCCURRENCE: {
    180               orderedEntries = ascending ? rawVariableImpacts : rawVariableImpacts.Reverse();
    181               break;
    182             }
    183           case ORDER_BY_NAME: {
    184               orderedEntries = ascending ? rawVariableImpacts.OrderBy(v => v.Key, new NaturalStringComparer()) : rawVariableImpacts.OrderByDescending(v => v.Key, new NaturalStringComparer());
    185               break;
    186             }
    187         }
     168      //Sort accordingly
     169      switch (selectedItem) {
     170        case RegressionSolutionVariableImpactsCalculator.SortingCriteria.ImpactValue:
     171          orderedEntries = ascending ? rawVariableImpacts.OrderBy(v => v.Value) : rawVariableImpacts.OrderByDescending(v => v.Value);
     172          break;
     173        case RegressionSolutionVariableImpactsCalculator.SortingCriteria.Occurrence:
     174          orderedEntries = ascending ? rawVariableImpacts : rawVariableImpacts.Reverse();
     175          break;
     176        case RegressionSolutionVariableImpactsCalculator.SortingCriteria.VariableName:
     177          orderedEntries = ascending ? rawVariableImpacts.OrderBy(v => v.Key, new NaturalStringComparer()) : rawVariableImpacts.OrderByDescending(v => v.Key, new NaturalStringComparer());
     178          break;
     179        default:
     180          throw new Exception("Cannot interpret SortingCriteria");
     181      }
    188182
    189         //Write the data back
    190         var impactArray = new DoubleArray(orderedEntries.Select(i => i.Value).ToArray()) {
    191           ElementNames = orderedEntries.Select(i => i.Key)
    192         };
    193         variableImactsArrayView.Content = (DoubleArray)impactArray.AsReadOnly();
    194       }
    195     }
    196 
    197     /// <summary>
    198     /// Resets the ordering to the default behaviour (descending by variableImpact), meaning <see cref="ascendingCheckBox"/> and <see cref="sortByComboBox"/> will be updated
    199     /// Note: this will NOT update the UI
    200     /// </summary>
    201     private void ResetOrdering() {
    202       //The events shouldn't fire everytime we reset the data
    203       ascendingCheckBox.CheckedChanged -= ascendingCheckBox_CheckedChanged;
    204       sortByComboBox.SelectedIndexChanged -= sortByComboBox_SelectedIndexChanged;
    205 
    206       ascendingCheckBox.Checked = false;
    207       sortByComboBox.SelectedIndex = ORDER_BY_IMPACT;
    208 
    209       ascendingCheckBox.CheckedChanged += ascendingCheckBox_CheckedChanged;
    210       sortByComboBox.SelectedIndexChanged += sortByComboBox_SelectedIndexChanged;
     183      //Write the data back
     184      var impactArray = new DoubleArray(orderedEntries.Select(i => i.Value).ToArray()) {
     185        ElementNames = orderedEntries.Select(i => i.Key)
     186      };
     187      variableImactsArrayView.Content = (DoubleArray)impactArray.AsReadOnly();
    211188    }
    212189    #endregion
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionSolutionVariableImpactsCalculator.cs

    r15583 r15665  
    5151      Test,
    5252      All
     53    }
     54    public enum SortingCriteria {
     55      ImpactValue,
     56      Occurrence,
     57      VariableName
    5358    }
    5459
Note: See TracChangeset for help on using the changeset viewer.