Changeset 16308 for branches/2845_EnhancedProgress/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionVariableImpactsView.cs
- Timestamp:
- 11/20/18 13:52:40 (6 years ago)
- Location:
- branches/2845_EnhancedProgress
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2845_EnhancedProgress
- Property svn:mergeinfo changed
/stable reverse-merged: 15587-15588 /trunk/sources removed
- Property svn:mergeinfo changed
-
branches/2845_EnhancedProgress/HeuristicLab.Problems.DataAnalysis.Views
- Property svn:mergeinfo changed
/stable/HeuristicLab.Problems.DataAnalysis.Views reverse-merged: 15587 /trunk/sources/HeuristicLab.Problems.DataAnalysis.Views removed
- Property svn:mergeinfo changed
-
branches/2845_EnhancedProgress/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionVariableImpactsView.cs
r16307 r16308 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 8Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 19 19 */ 20 20 #endregion 21 22 21 using System; 23 using System.Collections.Generic;24 22 using System.Linq; 25 23 using System.Threading.Tasks; 26 using HeuristicLab.Common;27 24 using HeuristicLab.Data; 28 25 using HeuristicLab.MainForm; … … 32 29 [Content(typeof(IRegressionSolution))] 33 30 public partial class RegressionSolutionVariableImpactsView : DataAnalysisSolutionEvaluationView { 34 private enum SortingCriteria {35 ImpactValue,36 Occurrence,37 VariableName38 }39 40 private Dictionary<string, double> rawVariableImpacts = new Dictionary<string, double>();41 31 42 32 public new IRegressionSolution Content { … … 50 40 : base() { 51 41 InitializeComponent(); 52 53 //Little workaround. If you fill the ComboBox-Items in the other partial class, the UI-Designer will moan.54 this.sortByComboBox.Items.AddRange(Enum.GetValues(typeof(SortingCriteria)).Cast<object>().ToArray());55 this.sortByComboBox.SelectedItem = SortingCriteria.ImpactValue;56 57 42 this.dataPartitionComboBox.SelectedIndex = 0; 58 43 this.replacementComboBox.SelectedIndex = 0; … … 90 75 } 91 76 77 private void UpdateVariableImpacts() { 78 if (Content == null || replacementComboBox.SelectedIndex < 0 79 || factorVarReplComboBox.SelectedIndex < 0 80 || dataPartitionComboBox.SelectedIndex < 0) return; 81 variableImactsArrayView.Caption = Content.Name + " Variable Impacts"; 82 var replMethod = 83 (RegressionSolutionVariableImpactsCalculator.ReplacementMethodEnum) 84 replacementComboBox.Items[replacementComboBox.SelectedIndex]; 85 var factorReplMethod = 86 (RegressionSolutionVariableImpactsCalculator.FactorReplacementMethodEnum) 87 factorVarReplComboBox.Items[factorVarReplComboBox.SelectedIndex]; 88 var dataPartition = 89 (RegressionSolutionVariableImpactsCalculator.DataPartitionEnum)dataPartitionComboBox.SelectedItem; 90 91 Task.Factory.StartNew(() => { 92 try { 93 Progress.ShowMarquee(this, "Calculating variable impacts for " + Content.Name); 94 95 var impacts = RegressionSolutionVariableImpactsCalculator.CalculateImpacts(Content, dataPartition, replMethod, factorReplMethod); 96 var impactArray = new DoubleArray(impacts.Select(i => i.Item2).ToArray()); 97 impactArray.ElementNames = impacts.Select(i => i.Item1); 98 variableImactsArrayView.Content = (DoubleArray)impactArray.AsReadOnly(); 99 } finally { 100 Progress.Hide(this); 101 } 102 }); 103 } 104 105 #endregion 92 106 93 107 private void dataPartitionComboBox_SelectedIndexChanged(object sender, EventArgs e) { … … 98 112 UpdateVariableImpacts(); 99 113 } 100 101 private void sortByComboBox_SelectedIndexChanged(object sender, EventArgs e) {102 //Update the default ordering (asc,desc), but remove the eventHandler beforehand (otherwise the data would be ordered twice)103 ascendingCheckBox.CheckedChanged -= ascendingCheckBox_CheckedChanged;104 switch ((SortingCriteria)sortByComboBox.SelectedItem) {105 case SortingCriteria.ImpactValue:106 ascendingCheckBox.Checked = false;107 break;108 case SortingCriteria.Occurrence:109 ascendingCheckBox.Checked = true;110 break;111 case SortingCriteria.VariableName:112 ascendingCheckBox.Checked = true;113 break;114 default:115 throw new NotImplementedException("Ordering for selected SortingCriteria not implemented");116 }117 ascendingCheckBox.CheckedChanged += ascendingCheckBox_CheckedChanged;118 119 UpdateDataOrdering();120 }121 122 private void ascendingCheckBox_CheckedChanged(object sender, EventArgs e) {123 UpdateDataOrdering();124 }125 #endregion126 127 #region Helper Methods128 private void UpdateVariableImpacts() {129 if (Content == null) { return; }130 if (replacementComboBox.SelectedIndex < 0) { return; }131 if (dataPartitionComboBox.SelectedIndex < 0) { return; }132 if (factorVarReplComboBox.SelectedIndex < 0) { return; }133 134 variableImactsArrayView.Caption = Content.Name + " Variable Impacts";135 136 var mainForm = (MainForm.WindowsForms.MainForm)MainFormManager.MainForm;137 var replMethod = (RegressionSolutionVariableImpactsCalculator.ReplacementMethodEnum)replacementComboBox.Items[replacementComboBox.SelectedIndex];138 var factorReplMethod = (RegressionSolutionVariableImpactsCalculator.FactorReplacementMethodEnum)factorVarReplComboBox.Items[factorVarReplComboBox.SelectedIndex];139 var dataPartition = (RegressionSolutionVariableImpactsCalculator.DataPartitionEnum)dataPartitionComboBox.SelectedItem;140 141 Task.Factory.StartNew(() => {142 try {143 Progress.ShowMarquee(this, "Calculating variable impacts for " + Content.Name);144 145 //Remember the original ordering of the variables146 var impacts = RegressionSolutionVariableImpactsCalculator.CalculateImpacts(Content, dataPartition, replMethod, factorReplMethod);147 var problemData = Content.ProblemData;148 var inputvariables = new HashSet<string>(problemData.AllowedInputVariables.Union(Content.Model.VariablesUsedForPrediction));149 var originalVariableOrdering = problemData.Dataset.VariableNames.Where(v => inputvariables.Contains(v)).Where(problemData.Dataset.VariableHasType<double>).ToList();150 rawVariableImpacts.Clear();151 originalVariableOrdering.ForEach(v => rawVariableImpacts.Add(v, impacts.First(vv => vv.Item1 == v).Item2));152 UpdateDataOrdering();153 } finally {154 Progress.Hide(this);155 }156 });157 }158 159 /// <summary>160 /// Updates the <see cref="variableImactsArrayView"/> according to the selected ordering <see cref="ascendingCheckBox"/> of the selected Column <see cref="sortByComboBox"/>161 /// The default is "Descending" by "VariableImpact" (as in previous versions)162 /// </summary>163 private void UpdateDataOrdering() {164 //Check if valid sortingCriteria is selected and data exists165 if (sortByComboBox.SelectedIndex == -1) { return; }166 if (rawVariableImpacts == null) { return; }167 if (!rawVariableImpacts.Any()) { return; }168 169 var selectedItem = (SortingCriteria)sortByComboBox.SelectedItem;170 bool ascending = ascendingCheckBox.Checked;171 172 IEnumerable<KeyValuePair<string, double>> orderedEntries = null;173 174 //Sort accordingly175 switch (selectedItem) {176 case SortingCriteria.ImpactValue:177 orderedEntries = rawVariableImpacts.OrderBy(v => v.Value);178 break;179 case SortingCriteria.Occurrence:180 orderedEntries = rawVariableImpacts;181 break;182 case SortingCriteria.VariableName:183 orderedEntries = rawVariableImpacts.OrderBy(v => v.Key, new NaturalStringComparer());184 break;185 default:186 throw new NotImplementedException("Ordering for selected SortingCriteria not implemented");187 }188 189 if (!ascending) { orderedEntries = orderedEntries.Reverse(); }190 191 //Write the data back192 var impactArray = new DoubleArray(orderedEntries.Select(i => i.Value).ToArray()) {193 ElementNames = orderedEntries.Select(i => i.Key)194 };195 variableImactsArrayView.Content = (DoubleArray)impactArray.AsReadOnly();196 }197 #endregion198 114 } 199 115 }
Note: See TracChangeset
for help on using the changeset viewer.