Changeset 15753
- Timestamp:
- 02/12/18 09:58:33 (7 years ago)
- Location:
- trunk/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/ClassificationSolutionVariableImpactsView.Designer.cs
r15729 r15753 170 170 this.sortByComboBox.SelectedIndexChanged += new System.EventHandler(this.sortByComboBox_SelectedIndexChanged); 171 171 // 172 // backgroundWorker173 //174 this.backgroundWorker.DoWork += new System.ComponentModel.DoWorkEventHandler(this.backgroundWorker_DoWork);175 this.backgroundWorker.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(this.backgroundWorker_RunWorkerCompleted);176 //177 172 // ClassificationSolutionVariableImpactsView 178 173 // … … 191 186 this.Name = "ClassificationSolutionVariableImpactsView"; 192 187 this.Size = new System.Drawing.Size(668, 365); 188 this.VisibleChanged += new System.EventHandler(this.ClassificationSolutionVariableImpactsView_VisibleChanged); 193 189 this.ResumeLayout(false); 194 190 this.PerformLayout(); -
trunk/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/ClassificationSolutionVariableImpactsView.cs
r15729 r15753 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 … … 101 97 variableImactsArrayView.Content = null; 102 98 } else { 103 StartBackgroundWorker(); 104 } 99 UpdateVariableImpact(); 100 } 101 } 102 103 private void ClassificationSolutionVariableImpactsView_VisibleChanged(object sender, EventArgs e) { 104 if (thread == null) { return; } 105 106 if (thread.IsAlive) { thread.Abort(); } 107 thread = null; 105 108 } 106 109 107 110 108 111 private void dataPartitionComboBox_SelectedIndexChanged(object sender, EventArgs e) { 109 StartBackgroundWorker();112 UpdateVariableImpact(); 110 113 } 111 114 112 115 private void replacementComboBox_SelectedIndexChanged(object sender, EventArgs e) { 113 StartBackgroundWorker();116 UpdateVariableImpact(); 114 117 } 115 118 … … 139 142 } 140 143 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() { 144 #endregion 145 146 #region Helper Methods 147 private void UpdateVariableImpact() { 172 148 //Check if the selection is valid 173 149 if (Content == null) { return; } … … 181 157 var factorReplMethod = (ClassificationSolutionVariableImpactsCalculator.FactorReplacementMethodEnum)factorVarReplComboBox.Items[factorVarReplComboBox.SelectedIndex]; 182 158 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); } 159 160 variableImactsArrayView.Caption = Content.Name + " Variable Impacts"; 161 162 mainForm.AddOperationProgressToView(this, "Calculating variable impacts for " + Content.Name); 163 164 Task.Factory.StartNew(() => { 165 thread = Thread.CurrentThread; 166 //Remember the original ordering of the variables 167 var impacts = ClassificationSolutionVariableImpactsCalculator.CalculateImpacts(Content, dataPartition, replMethod, factorReplMethod); 168 var problemData = Content.ProblemData; 169 var inputvariables = new HashSet<string>(problemData.AllowedInputVariables.Union(Content.Model.VariablesUsedForPrediction)); 170 var originalVariableOrdering = problemData.Dataset.VariableNames.Where(v => inputvariables.Contains(v)).Where(problemData.Dataset.VariableHasType<double>).ToList(); 171 172 rawVariableImpacts.Clear(); 173 originalVariableOrdering.ForEach(v => rawVariableImpacts.Add(v, impacts.First(vv => vv.Item1 == v).Item2)); 174 }).ContinueWith((o) => { 175 UpdateDataOrdering(); 176 mainForm.RemoveOperationProgressFromView(this); 177 thread = null; 178 }, TaskScheduler.FromCurrentSynchronizationContext()); 193 179 } 194 180 … … 230 216 }; 231 217 232 //Could be, if the View was closed during the BackgroundWorker-run218 //Could be, if the View was closed 233 219 if (!variableImactsArrayView.IsDisposed) { 234 220 variableImactsArrayView.Content = (DoubleArray)impactArray.AsReadOnly(); 235 221 } 236 222 } 237 #endregion 223 #endregion 238 224 } 239 225 }
Note: See TracChangeset
for help on using the changeset viewer.