Changeset 15665
- Timestamp:
- 01/29/18 17:19:06 (7 years ago)
- Location:
- trunk/sources
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionVariableImpactsView.Designer.cs
r15637 r15665 19 19 */ 20 20 #endregion 21 using System; 22 using System.Linq; 23 21 24 namespace HeuristicLab.Problems.DataAnalysis.Views { 22 25 partial class RegressionSolutionVariableImpactsView { … … 80 83 this.sortByComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; 81 84 this.sortByComboBox.FormattingEnabled = true; 82 this.sortByComboBox.Items.AddRange(new object[] {83 "Impact Value",84 "Occurrence",85 "Variable Name"});86 85 this.sortByComboBox.Location = new System.Drawing.Point(407, 3); 87 86 this.sortByComboBox.Name = "sortByComboBox"; … … 92 91 // factorVarReplComboBox 93 92 // 93 this.factorVarReplComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; 94 94 this.factorVarReplComboBox.FormattingEnabled = true; 95 95 this.factorVarReplComboBox.Items.AddRange(new object[] { … … 114 114 // replacementComboBox 115 115 // 116 this.replacementComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; 116 117 this.replacementComboBox.FormattingEnabled = true; 117 118 this.replacementComboBox.Items.AddRange(new object[] { … … 146 147 // dataPartitionComboBox 147 148 // 149 this.dataPartitionComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; 148 150 this.dataPartitionComboBox.FormattingEnabled = true; 149 151 this.dataPartitionComboBox.Items.AddRange(new object[] { -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionVariableImpactsView.cs
r15637 r15665 19 19 */ 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; … … 26 27 using HeuristicLab.Data; 27 28 using HeuristicLab.MainForm; 28 using HeuristicLab.Problems.DataAnalysis.Symbolic.Regression;29 29 30 30 namespace HeuristicLab.Problems.DataAnalysis.Views { … … 32 32 [Content(typeof(IRegressionSolution))] 33 33 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 39 34 private Dictionary<string, double> rawVariableImpacts = new Dictionary<string, double>(); 40 35 … … 49 44 : base() { 50 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(RegressionSolutionVariableImpactsCalculator.SortingCriteria)).Cast<object>().ToArray()); 49 this.sortByComboBox.SelectedItem = RegressionSolutionVariableImpactsCalculator.SortingCriteria.ImpactValue; 50 51 51 this.dataPartitionComboBox.SelectedIndex = 0; 52 52 this.replacementComboBox.SelectedIndex = 0; … … 84 84 } 85 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 ((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 86 122 private void UpdateVariableImpacts() { 87 123 if (Content == null || replacementComboBox.SelectedIndex < 0 … … 103 139 mainForm.AddOperationProgressToView(this, "Calculating variable impacts for " + Content.Name); 104 140 141 //Remember the original ordering of the variables 105 142 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 variables111 143 var problemData = Content.ProblemData; 112 144 var inputvariables = new HashSet<string>(problemData.AllowedInputVariables.Union(Content.Model.VariablesUsedForPrediction)); … … 114 146 rawVariableImpacts.Clear(); 115 147 originalVariableOrdering.ForEach(v => rawVariableImpacts.Add(v, impacts.First(vv => vv.Item1 == v).Item2)); 116 117 148 } finally { 118 149 mainForm.RemoveOperationProgressFromView(this); 150 UpdateDataOrdering(); 119 151 } 120 152 }); 121 153 } 122 154 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 #endregion159 160 #region Helper Methods161 155 /// <summary> 162 156 /// Updates the <see cref="variableImactsArrayView"/> according to the selected ordering <see cref="ascendingCheckBox"/> of the selected Column <see cref="sortByComboBox"/> … … 164 158 /// </summary> 165 159 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; 167 164 bool ascending = ascendingCheckBox.Checked; 168 165 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; 172 167 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 } 188 182 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(); 211 188 } 212 189 #endregion -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionSolutionVariableImpactsCalculator.cs
r15583 r15665 51 51 Test, 52 52 All 53 } 54 public enum SortingCriteria { 55 ImpactValue, 56 Occurrence, 57 VariableName 53 58 } 54 59
Note: See TracChangeset
for help on using the changeset viewer.