Changeset 15752
- Timestamp:
- 02/12/18 09:52:29 (7 years ago)
- Location:
- trunk/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionVariableImpactsView.Designer.cs
r15728 r15752 55 55 this.dataPartitionComboBox = new System.Windows.Forms.ComboBox(); 56 56 this.variableImactsArrayView = new HeuristicLab.Data.Views.StringConvertibleArrayView(); 57 this.backgroundWorker = new System.ComponentModel.BackgroundWorker();58 57 this.SuspendLayout(); 59 58 // … … 170 169 this.variableImactsArrayView.Size = new System.Drawing.Size(706, 278); 171 170 this.variableImactsArrayView.TabIndex = 2; 172 //173 // backgroundWorker174 //175 this.backgroundWorker.DoWork += new System.ComponentModel.DoWorkEventHandler(this.backgroundWorker_DoWork);176 this.backgroundWorker.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(this.backgroundWorker_RunWorkerCompleted);177 171 // 178 172 // RegressionSolutionVariableImpactsView … … 192 186 this.Name = "RegressionSolutionVariableImpactsView"; 193 187 this.Size = new System.Drawing.Size(712, 365); 188 this.VisibleChanged += new System.EventHandler(this.RegressionSolutionVariableImpactsView_VisibleChanged); 194 189 this.ResumeLayout(false); 195 190 this.PerformLayout(); … … 209 204 private System.Windows.Forms.ComboBox sortByComboBox; 210 205 private System.Windows.Forms.CheckBox ascendingCheckBox; 211 private System.ComponentModel.BackgroundWorker backgroundWorker;212 206 } 213 207 } -
trunk/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionVariableImpactsView.cs
r15728 r15752 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 RegressionSolutionVariableImpactsView : DataAnalysisSolutionEvaluationView { 33 35 #region Nested Types 34 private class BackgroundWorkerArguments {35 internal MainForm.WindowsForms.MainForm mainForm;36 internal RegressionSolutionVariableImpactsCalculator.ReplacementMethodEnum replMethod;37 internal RegressionSolutionVariableImpactsCalculator.FactorReplacementMethodEnum factorReplMethod;38 internal RegressionSolutionVariableImpactsCalculator.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 RegressionSolutionVariableImpactsView_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 variables153 var impacts = RegressionSolutionVariableImpactsCalculator.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 144 #endregion 169 145 170 146 #region Helper Methods 171 private void StartBackgroundWorker() {147 private void UpdateVariableImpact() { 172 148 //Check if the selection is valid 173 149 if (Content == null) { return; } … … 181 157 var factorReplMethod = (RegressionSolutionVariableImpactsCalculator.FactorReplacementMethodEnum)factorVarReplComboBox.Items[factorVarReplComboBox.SelectedIndex]; 182 158 var dataPartition = (RegressionSolutionVariableImpactsCalculator.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 = RegressionSolutionVariableImpactsCalculator.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();
Note: See TracChangeset
for help on using the changeset viewer.