Changeset 16388 for branches/2892_LR-prediction-intervals/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/ClassificationSolutionVariableImpactsView.cs
- Timestamp:
- 12/15/18 12:36:08 (5 years ago)
- Location:
- branches/2892_LR-prediction-intervals
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2892_LR-prediction-intervals
- Property svn:ignore
-
old new 1 *.docstates 2 *.psess 3 *.resharper 4 *.suo 5 *.user 6 *.vsp 7 Doxygen 8 FxCopResults.txt 9 Google.ProtocolBuffers-0.9.1.dll 10 Google.ProtocolBuffers-2.4.1.473.dll 11 HeuristicLab 3.3.5.1.ReSharper.user 12 HeuristicLab 3.3.6.0.ReSharper.user 13 HeuristicLab.4.5.resharper.user 14 HeuristicLab.ExtLibs.6.0.ReSharper.user 15 HeuristicLab.Scripting.Development 16 HeuristicLab.resharper.user 17 ProtoGen.exe 1 18 TestResults 19 _ReSharper.HeuristicLab 20 _ReSharper.HeuristicLab 3.3 21 _ReSharper.HeuristicLab 3.3 Tests 22 _ReSharper.HeuristicLab.ExtLibs 23 bin 24 protoc.exe 25 obj 26 .vs
-
- Property svn:mergeinfo changed
-
Property
svn:global-ignores
set to
*.nuget
packages
- Property svn:ignore
-
branches/2892_LR-prediction-intervals/HeuristicLab.Problems.DataAnalysis.Views
- Property svn:mergeinfo changed
-
branches/2892_LR-prediction-intervals/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/ClassificationSolutionVariableImpactsView.cs
r15729 r16388 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using System.Threading; 26 using System.Threading.Tasks; 25 27 using HeuristicLab.Common; 26 28 using HeuristicLab.Data; … … 32 34 public partial class ClassificationSolutionVariableImpactsView : DataAnalysisSolutionEvaluationView { 33 35 #region Nested Types 34 private class BackgroundWorkerArguments {35 internal MainForm.WindowsForms.MainForm mainForm;36 internal ClassificationSolutionVariableImpactsCalculator.ReplacementMethodEnum replMethod;37 internal ClassificationSolutionVariableImpactsCalculator.FactorReplacementMethodEnum factorReplMethod;38 internal ClassificationSolutionVariableImpactsCalculator.DataPartitionEnum dataPartition;39 }40 41 36 private enum SortingCriteria { 42 37 ImpactValue, … … 48 43 #region Fields 49 44 private Dictionary<string, double> rawVariableImpacts = new Dictionary<string, double>(); 45 private Thread thread; 50 46 #endregion 51 47 … … 64 60 InitializeComponent(); 65 61 66 //Little workaround. If you fill the ComboBox-Items in the other partial class, the UI-Designer will moan.67 62 this.sortByComboBox.Items.AddRange(Enum.GetValues(typeof(SortingCriteria)).Cast<object>().ToArray()); 68 63 this.sortByComboBox.SelectedItem = SortingCriteria.ImpactValue; … … 101 96 variableImactsArrayView.Content = null; 102 97 } else { 103 StartBackgroundWorker(); 104 } 98 UpdateVariableImpact(); 99 } 100 } 101 102 private void ClassificationSolutionVariableImpactsView_VisibleChanged(object sender, EventArgs e) { 103 if (thread == null) { return; } 104 105 if (thread.IsAlive) { thread.Abort(); } 106 thread = null; 105 107 } 106 108 107 109 108 110 private void dataPartitionComboBox_SelectedIndexChanged(object sender, EventArgs e) { 109 StartBackgroundWorker();111 UpdateVariableImpact(); 110 112 } 111 113 112 114 private void replacementComboBox_SelectedIndexChanged(object sender, EventArgs e) { 113 StartBackgroundWorker();115 UpdateVariableImpact(); 114 116 } 115 117 … … 139 141 } 140 142 141 142 private void backgroundWorker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) { 143 variableImactsArrayView.Caption = Content.Name + " Variable Impacts"; 144 145 var argument = e.Argument as BackgroundWorkerArguments; 146 if (!(argument is BackgroundWorkerArguments)) { 147 throw new ArgumentException("Argument for Backgroundworker must be of type BackgroundworkerArguments"); 148 } 149 150 argument.mainForm.AddOperationProgressToView(this, "Calculating variable impacts for " + Content.Name); 151 try { 152 //Remember the original ordering of the variables 153 var impacts = ClassificationSolutionVariableImpactsCalculator.CalculateImpacts(Content, argument.dataPartition, argument.replMethod, argument.factorReplMethod); 154 var problemData = Content.ProblemData; 155 var inputvariables = new HashSet<string>(problemData.AllowedInputVariables.Union(Content.Model.VariablesUsedForPrediction)); 156 var originalVariableOrdering = problemData.Dataset.VariableNames.Where(v => inputvariables.Contains(v)).Where(problemData.Dataset.VariableHasType<double>).ToList(); 157 158 rawVariableImpacts.Clear(); 159 originalVariableOrdering.ForEach(v => rawVariableImpacts.Add(v, impacts.First(vv => vv.Item1 == v).Item2)); 160 } finally { 161 argument.mainForm.RemoveOperationProgressFromView(this); 162 } 163 } 164 165 private void backgroundWorker_RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e) { 166 UpdateDataOrdering(); 167 } 168 #endregion 169 170 #region Helper Methods 171 private void StartBackgroundWorker() { 143 #endregion 144 145 #region Helper Methods 146 private void UpdateVariableImpact() { 172 147 //Check if the selection is valid 173 148 if (Content == null) { return; } … … 181 156 var factorReplMethod = (ClassificationSolutionVariableImpactsCalculator.FactorReplacementMethodEnum)factorVarReplComboBox.Items[factorVarReplComboBox.SelectedIndex]; 182 157 var dataPartition = (ClassificationSolutionVariableImpactsCalculator.DataPartitionEnum)dataPartitionComboBox.SelectedItem; 183 var args = new BackgroundWorkerArguments() { 184 mainForm = mainForm, 185 replMethod = replMethod, 186 factorReplMethod = factorReplMethod, 187 dataPartition = dataPartition 188 }; 189 190 //Let the backgroundWorker do his job (unless he's already running) 191 //fholzing: Possible bug -> A ContentChanged won't update the data if the backgroundworker is already running 192 if (!backgroundWorker.IsBusy) { backgroundWorker.RunWorkerAsync(args); } 158 159 variableImactsArrayView.Caption = Content.Name + " Variable Impacts"; 160 161 mainForm.AddOperationProgressToView(this, "Calculating variable impacts for " + Content.Name); 162 163 Task.Factory.StartNew(() => { 164 thread = Thread.CurrentThread; 165 //Remember the original ordering of the variables 166 var impacts = ClassificationSolutionVariableImpactsCalculator.CalculateImpacts(Content, dataPartition, replMethod, factorReplMethod); 167 var problemData = Content.ProblemData; 168 var inputvariables = new HashSet<string>(problemData.AllowedInputVariables.Union(Content.Model.VariablesUsedForPrediction)); 169 var originalVariableOrdering = problemData.Dataset.VariableNames.Where(v => inputvariables.Contains(v)).Where(problemData.Dataset.VariableHasType<double>).ToList(); 170 171 rawVariableImpacts.Clear(); 172 originalVariableOrdering.ForEach(v => rawVariableImpacts.Add(v, impacts.First(vv => vv.Item1 == v).Item2)); 173 }).ContinueWith((o) => { 174 UpdateDataOrdering(); 175 mainForm.RemoveOperationProgressFromView(this); 176 thread = null; 177 }, TaskScheduler.FromCurrentSynchronizationContext()); 193 178 } 194 179 … … 230 215 }; 231 216 232 //Could be, if the View was closed during the BackgroundWorker-run217 //Could be, if the View was closed 233 218 if (!variableImactsArrayView.IsDisposed) { 234 219 variableImactsArrayView.Content = (DoubleArray)impactArray.AsReadOnly(); 235 220 } 236 221 } 237 #endregion 222 #endregion 238 223 } 239 224 }
Note: See TracChangeset
for help on using the changeset viewer.