- Timestamp:
- 01/30/18 10:28:21 (7 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/ClassificationSolutionVariableImpactsView.Designer.cs
r15638 r15667 51 51 this.factorVarReplacementLabel = new System.Windows.Forms.Label(); 52 52 this.factorVarReplComboBox = new System.Windows.Forms.ComboBox(); 53 this.ascendingCheckBox = new System.Windows.Forms.CheckBox(); 54 this.sortByLabel = new System.Windows.Forms.Label(); 55 this.sortByComboBox = new System.Windows.Forms.ComboBox(); 53 56 this.SuspendLayout(); 54 57 // … … 63 66 this.variableImactsArrayView.Name = "variableImactsArrayView"; 64 67 this.variableImactsArrayView.ReadOnly = true; 65 this.variableImactsArrayView.Size = new System.Drawing.Size( 363, 278);68 this.variableImactsArrayView.Size = new System.Drawing.Size(662, 278); 66 69 this.variableImactsArrayView.TabIndex = 2; 67 70 // 68 71 // dataPartitionComboBox 69 72 // 73 this.dataPartitionComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; 70 74 this.dataPartitionComboBox.FormattingEnabled = true; 71 75 this.dataPartitionComboBox.Items.AddRange(new object[] { … … 99 103 // replacementComboBox 100 104 // 105 this.replacementComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; 101 106 this.replacementComboBox.FormattingEnabled = true; 102 107 this.replacementComboBox.Items.AddRange(new object[] { … … 122 127 // factorVarReplComboBox 123 128 // 129 this.factorVarReplComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; 124 130 this.factorVarReplComboBox.FormattingEnabled = true; 125 131 this.factorVarReplComboBox.Items.AddRange(new object[] { … … 133 139 this.factorVarReplComboBox.SelectedIndexChanged += new System.EventHandler(this.replacementComboBox_SelectedIndexChanged); 134 140 // 141 // ascendingCheckBox 142 // 143 this.ascendingCheckBox.AutoSize = true; 144 this.ascendingCheckBox.Location = new System.Drawing.Point(534, 6); 145 this.ascendingCheckBox.Name = "ascendingCheckBox"; 146 this.ascendingCheckBox.Size = new System.Drawing.Size(76, 17); 147 this.ascendingCheckBox.TabIndex = 10; 148 this.ascendingCheckBox.Text = "Ascending"; 149 this.ascendingCheckBox.UseVisualStyleBackColor = true; 150 this.ascendingCheckBox.CheckedChanged += new System.EventHandler(this.ascendingCheckBox_CheckedChanged); 151 // 152 // sortByLabel 153 // 154 this.sortByLabel.AutoSize = true; 155 this.sortByLabel.Location = new System.Drawing.Point(324, 6); 156 this.sortByLabel.Name = "sortByLabel"; 157 this.sortByLabel.Size = new System.Drawing.Size(77, 13); 158 this.sortByLabel.TabIndex = 8; 159 this.sortByLabel.Text = "Sorting criteria:"; 160 // 161 // sortByComboBox 162 // 163 this.sortByComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; 164 this.sortByComboBox.FormattingEnabled = true; 165 this.sortByComboBox.Location = new System.Drawing.Point(407, 3); 166 this.sortByComboBox.Name = "sortByComboBox"; 167 this.sortByComboBox.Size = new System.Drawing.Size(121, 21); 168 this.sortByComboBox.TabIndex = 9; 169 this.sortByComboBox.SelectedIndexChanged += new System.EventHandler(this.sortByComboBox_SelectedIndexChanged); 170 // 135 171 // ClassificationSolutionVariableImpactsView 136 172 // 137 173 this.AllowDrop = true; 138 174 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit; 175 this.Controls.Add(this.ascendingCheckBox); 176 this.Controls.Add(this.sortByLabel); 177 this.Controls.Add(this.sortByComboBox); 139 178 this.Controls.Add(this.factorVarReplComboBox); 140 179 this.Controls.Add(this.factorVarReplacementLabel); … … 145 184 this.Controls.Add(this.variableImactsArrayView); 146 185 this.Name = "ClassificationSolutionVariableImpactsView"; 147 this.Size = new System.Drawing.Size( 369, 365);186 this.Size = new System.Drawing.Size(668, 365); 148 187 this.ResumeLayout(false); 149 188 this.PerformLayout(); … … 160 199 private System.Windows.Forms.Label factorVarReplacementLabel; 161 200 private System.Windows.Forms.ComboBox factorVarReplComboBox; 201 private System.Windows.Forms.CheckBox ascendingCheckBox; 202 private System.Windows.Forms.Label sortByLabel; 203 private System.Windows.Forms.ComboBox sortByComboBox; 162 204 } 163 205 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/ClassificationSolutionVariableImpactsView.cs
r15638 r15667 19 19 */ 20 20 #endregion 21 21 22 using System; 23 using System.Collections.Generic; 22 24 using System.Linq; 23 25 using System.Threading.Tasks; 26 using HeuristicLab.Common; 24 27 using HeuristicLab.Data; 25 28 using HeuristicLab.MainForm; … … 29 32 [Content(typeof(IClassificationSolution))] 30 33 public partial class ClassificationSolutionVariableImpactsView : DataAnalysisSolutionEvaluationView { 34 private Dictionary<string, double> rawVariableImpacts = new Dictionary<string, double>(); 31 35 32 36 public new IClassificationSolution Content { … … 40 44 : base() { 41 45 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(ClassificationSolutionVariableImpactsCalculator.SortingCriteria)).Cast<object>().ToArray()); 49 this.sortByComboBox.SelectedItem = ClassificationSolutionVariableImpactsCalculator.SortingCriteria.ImpactValue; 50 42 51 this.dataPartitionComboBox.SelectedIndex = 0; 43 52 this.replacementComboBox.SelectedIndex = 0; … … 75 84 } 76 85 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 ((ClassificationSolutionVariableImpactsCalculator.SortingCriteria)sortByComboBox.SelectedItem) { 99 case ClassificationSolutionVariableImpactsCalculator.SortingCriteria.ImpactValue: 100 ascendingCheckBox.Checked = false; 101 break; 102 case ClassificationSolutionVariableImpactsCalculator.SortingCriteria.Occurrence: 103 ascendingCheckBox.Checked = true; 104 break; 105 case ClassificationSolutionVariableImpactsCalculator.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 77 122 private void UpdateVariableImpacts() { 78 123 if (Content == null || replacementComboBox.SelectedIndex < 0 … … 94 139 mainForm.AddOperationProgressToView(this, "Calculating variable impacts for " + Content.Name); 95 140 141 //Remember the original ordering of the variables 96 142 var impacts = ClassificationSolutionVariableImpactsCalculator.CalculateImpacts(Content, dataPartition, replMethod, factorReplMethod); 97 var impactArray = new DoubleArray(impacts.Select(i => i.Item2).ToArray()); 98 impactArray.ElementNames = impacts.Select(i => i.Item1); 99 variableImactsArrayView.Content = (DoubleArray)impactArray.AsReadOnly(); 143 var problemData = Content.ProblemData; 144 var inputvariables = new HashSet<string>(problemData.AllowedInputVariables.Union(Content.Model.VariablesUsedForPrediction)); 145 var originalVariableOrdering = problemData.Dataset.VariableNames.Where(v => inputvariables.Contains(v)).Where(problemData.Dataset.VariableHasType<double>).ToList(); 146 rawVariableImpacts.Clear(); 147 originalVariableOrdering.ForEach(v => rawVariableImpacts.Add(v, impacts.First(vv => vv.Item1 == v).Item2)); 100 148 } finally { 101 149 mainForm.RemoveOperationProgressFromView(this); 150 UpdateDataOrdering(); 102 151 } 103 152 }); 104 153 } 105 154 106 #endregion 155 /// <summary> 156 /// Updates the <see cref="variableImactsArrayView"/> according to the selected ordering <see cref="ascendingCheckBox"/> of the selected Column <see cref="sortByComboBox"/> 157 /// The default is "Descending" by "VariableImpact" (as in previous versions) 158 /// </summary> 159 private void UpdateDataOrdering() { 160 //Check if valid sortingCriteria is selected and data exists 161 if (sortByComboBox.SelectedIndex == -1 || rawVariableImpacts == null || !rawVariableImpacts.Any()) { return; } 107 162 108 private void dataPartitionComboBox_SelectedIndexChanged(object sender, EventArgs e) { 109 UpdateVariableImpacts(); 163 var selectedItem = (ClassificationSolutionVariableImpactsCalculator.SortingCriteria)sortByComboBox.SelectedItem; 164 bool ascending = ascendingCheckBox.Checked; 165 166 IEnumerable<KeyValuePair<string, double>> orderedEntries = null; 167 168 //Sort accordingly 169 switch (selectedItem) { 170 case ClassificationSolutionVariableImpactsCalculator.SortingCriteria.ImpactValue: 171 orderedEntries = ascending ? rawVariableImpacts.OrderBy(v => v.Value) : rawVariableImpacts.OrderByDescending(v => v.Value); 172 break; 173 case ClassificationSolutionVariableImpactsCalculator.SortingCriteria.Occurrence: 174 orderedEntries = ascending ? rawVariableImpacts : rawVariableImpacts.Reverse(); 175 break; 176 case ClassificationSolutionVariableImpactsCalculator.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 } 182 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(); 110 188 } 111 112 private void replacementComboBox_SelectedIndexChanged(object sender, EventArgs e) { 113 UpdateVariableImpacts(); 114 } 189 #endregion 115 190 } 116 191 }
Note: See TracChangeset
for help on using the changeset viewer.