Changeset 15626


Ignore:
Timestamp:
01/17/18 14:11:45 (13 months ago)
Author:
fholzing
Message:

#2871: Added three additional UI-Controls, a Label + ComboBox for ordering (VariableName or ImpactFactor) and a CheckBox for Ascending/Descending

Location:
trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression
Files:
2 edited

Legend:

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

    r15583 r15626  
    5151      this.factorVarReplacementLabel = new System.Windows.Forms.Label();
    5252      this.factorVarReplComboBox = new System.Windows.Forms.ComboBox();
     53      this.sortByLabel = new System.Windows.Forms.Label();
     54      this.sortByComboBox = new System.Windows.Forms.ComboBox();
     55      this.ascendingCheckBox = new System.Windows.Forms.CheckBox();
    5356      this.SuspendLayout();
    5457      //
    5558      // variableImactsArrayView
    5659      //
    57       this.variableImactsArrayView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
    58             | System.Windows.Forms.AnchorStyles.Left) 
     60      this.variableImactsArrayView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     61            | System.Windows.Forms.AnchorStyles.Left)
    5962            | System.Windows.Forms.AnchorStyles.Right)));
    6063      this.variableImactsArrayView.Caption = "StringConvertibleArray View";
     
    6366      this.variableImactsArrayView.Name = "variableImactsArrayView";
    6467      this.variableImactsArrayView.ReadOnly = true;
    65       this.variableImactsArrayView.Size = new System.Drawing.Size(363, 278);
     68      this.variableImactsArrayView.Size = new System.Drawing.Size(706, 278);
    6669      this.variableImactsArrayView.TabIndex = 2;
    6770      //
     
    133136      this.factorVarReplComboBox.SelectedIndexChanged += new System.EventHandler(this.replacementComboBox_SelectedIndexChanged);
    134137      //
     138      // sortByLabel
     139      //
     140      this.sortByLabel.AutoSize = true;
     141      this.sortByLabel.Location = new System.Drawing.Point(324, 6);
     142      this.sortByLabel.Name = "sortByLabel";
     143      this.sortByLabel.Size = new System.Drawing.Size(43, 13);
     144      this.sortByLabel.TabIndex = 4;
     145      this.sortByLabel.Text = "Sort by:";
     146      //
     147      // sortByComboBox
     148      //
     149      this.sortByComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
     150      this.sortByComboBox.FormattingEnabled = true;
     151      this.sortByComboBox.Items.AddRange(new object[] {
     152            "Variable",
     153            "Impact"});
     154      this.sortByComboBox.Location = new System.Drawing.Point(373, 3);
     155      this.sortByComboBox.Name = "sortByComboBox";
     156      this.sortByComboBox.Size = new System.Drawing.Size(121, 21);
     157      this.sortByComboBox.TabIndex = 5;
     158      this.sortByComboBox.SelectedIndexChanged += new System.EventHandler(this.sortByComboBox_SelectedIndexChanged);
     159      this.sortByComboBox.SelectedIndex = 1;
     160      //
     161      // ascendingCheckBox
     162      //
     163      this.ascendingCheckBox.AutoSize = true;
     164      this.ascendingCheckBox.Location = new System.Drawing.Point(500, 6);
     165      this.ascendingCheckBox.Name = "ascendingCheckBox";
     166      this.ascendingCheckBox.Size = new System.Drawing.Size(76, 17);
     167      this.ascendingCheckBox.TabIndex = 7;
     168      this.ascendingCheckBox.Text = "Ascending";
     169      this.ascendingCheckBox.UseVisualStyleBackColor = true;
     170      this.ascendingCheckBox.CheckedChanged += new System.EventHandler(this.ascendingCheckBox_CheckedChanged);
     171      //
    135172      // RegressionSolutionVariableImpactsView
    136173      //
    137174      this.AllowDrop = true;
    138175      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
     176      this.Controls.Add(this.ascendingCheckBox);
     177      this.Controls.Add(this.sortByLabel);
     178      this.Controls.Add(this.sortByComboBox);
    139179      this.Controls.Add(this.factorVarReplComboBox);
    140180      this.Controls.Add(this.factorVarReplacementLabel);
     
    145185      this.Controls.Add(this.variableImactsArrayView);
    146186      this.Name = "RegressionSolutionVariableImpactsView";
    147       this.Size = new System.Drawing.Size(369, 365);
     187      this.Size = new System.Drawing.Size(712, 365);
    148188      this.ResumeLayout(false);
    149189      this.PerformLayout();
     
    160200    private System.Windows.Forms.Label factorVarReplacementLabel;
    161201    private System.Windows.Forms.ComboBox factorVarReplComboBox;
     202    private System.Windows.Forms.Label sortByLabel;
     203    private System.Windows.Forms.ComboBox sortByComboBox;
     204    private System.Windows.Forms.CheckBox ascendingCheckBox;
    162205  }
    163206}
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionVariableImpactsView.cs

    r15583 r15626  
    2020#endregion
    2121using System;
     22using System.Collections.Generic;
    2223using System.Linq;
    2324using System.Threading.Tasks;
     
    3031  [Content(typeof(IRegressionSolution))]
    3132  public partial class RegressionSolutionVariableImpactsView : DataAnalysisSolutionEvaluationView {
     33
     34    private const int ORDER_BY_VARIABLE = 0;
     35    private const int ORDER_BY_IMPACT = 1;
     36
     37    private Dictionary<string, double> rawVariableImpacts = new Dictionary<string, double>();
    3238
    3339    public new IRegressionSolution Content {
     
    99105          impactArray.ElementNames = impacts.Select(i => i.Item1);
    100106          variableImactsArrayView.Content = (DoubleArray)impactArray.AsReadOnly();
     107
     108          //Remember the original ordering of the variables
     109          var problemData = Content.ProblemData;
     110          var inputvariables = new HashSet<string>(problemData.AllowedInputVariables.Union(Content.Model.VariablesUsedForPrediction));
     111          var originalVariableOrdering = problemData.Dataset.VariableNames.Where(v => inputvariables.Contains(v)).Where(problemData.Dataset.VariableHasType<double>).ToList();
     112          rawVariableImpacts.Clear();
     113          originalVariableOrdering.ForEach(v => rawVariableImpacts.Add(v, impacts.First(vv => vv.Item1 == v).Item2));
     114
    101115        } finally {
    102116          mainForm.RemoveOperationProgressFromView(this);
     
    105119    }
    106120
    107     #endregion
    108 
    109121    private void dataPartitionComboBox_SelectedIndexChanged(object sender, EventArgs e) {
     122      ResetOrdering();
    110123      UpdateVariableImpacts();
    111124    }
    112125
    113126    private void replacementComboBox_SelectedIndexChanged(object sender, EventArgs e) {
     127      ResetOrdering();
    114128      UpdateVariableImpacts();
    115129    }
     130
     131    private void sortByComboBox_SelectedIndexChanged(object sender, EventArgs e) {
     132      UpdateDataOrdering();
     133    }
     134
     135    private void ascendingCheckBox_CheckedChanged(object sender, EventArgs e) {
     136      UpdateDataOrdering();
     137    }
     138    #endregion
     139
     140    #region Helper Methods
     141    /// <summary>
     142    /// Updates the <see cref="variableImactsArrayView"/> according to the selected ordering <see cref="ascendingCheckBox"/> of the selected Column <see cref="sortByComboBox"/>
     143    /// The default is "Descending" by "VariableImpact" (as in previous versions)
     144    /// </summary>
     145    private void UpdateDataOrdering() {
     146      int orderIdx = sortByComboBox.SelectedIndex;
     147      bool ascending = ascendingCheckBox.Checked;
     148
     149      //Check if valid ordering is selected AND at if any VariableImpact exists
     150      if (orderIdx > -1 && rawVariableImpacts != null && rawVariableImpacts.Any()) {
     151        IEnumerable<KeyValuePair<string, double>> orderedEntries = null;
     152
     153        //Sort accordingly
     154        if (orderIdx == ORDER_BY_VARIABLE) {
     155          orderedEntries = ascending ? rawVariableImpacts : rawVariableImpacts.Reverse();
     156        } else if (orderIdx == ORDER_BY_IMPACT) {
     157          orderedEntries = ascending ? rawVariableImpacts.OrderBy(v => v.Value) : rawVariableImpacts.OrderByDescending(v => v.Value);
     158        }
     159
     160        //Write the data back
     161        var impactArray = new DoubleArray(orderedEntries.Select(i => i.Value).ToArray());
     162        impactArray.ElementNames = orderedEntries.Select(i => i.Key);
     163        variableImactsArrayView.Content = (DoubleArray)impactArray.AsReadOnly();
     164      }
     165    }
     166
     167    /// <summary>
     168    /// Resets the ordering to the default behaviour (descending by variableImpact), meaning <see cref="ascendingCheckBox"/> and <see cref="sortByComboBox"/> will be updated
     169    /// Note: this will NOT update the UI
     170    /// </summary>
     171    private void ResetOrdering() {
     172      //The events shouldn't fire everytime we reset the data
     173      ascendingCheckBox.CheckedChanged -= ascendingCheckBox_CheckedChanged;
     174      sortByComboBox.SelectedIndexChanged -= sortByComboBox_SelectedIndexChanged;
     175
     176      ascendingCheckBox.Checked = false;
     177      sortByComboBox.SelectedIndex = ORDER_BY_IMPACT;
     178
     179      ascendingCheckBox.CheckedChanged += ascendingCheckBox_CheckedChanged;
     180      sortByComboBox.SelectedIndexChanged += sortByComboBox_SelectedIndexChanged;
     181    }
     182    #endregion
    116183  }
    117184}
Note: See TracChangeset for help on using the changeset viewer.