Changeset 15729
- Timestamp:
- 02/07/18 13:29:06 (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
r15667 r15729 54 54 this.sortByLabel = new System.Windows.Forms.Label(); 55 55 this.sortByComboBox = new System.Windows.Forms.ComboBox(); 56 this.backgroundWorker = new System.ComponentModel.BackgroundWorker(); 56 57 this.SuspendLayout(); 57 58 // … … 168 169 this.sortByComboBox.TabIndex = 9; 169 170 this.sortByComboBox.SelectedIndexChanged += new System.EventHandler(this.sortByComboBox_SelectedIndexChanged); 171 // 172 // backgroundWorker 173 // 174 this.backgroundWorker.DoWork += new System.ComponentModel.DoWorkEventHandler(this.backgroundWorker_DoWork); 175 this.backgroundWorker.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(this.backgroundWorker_RunWorkerCompleted); 170 176 // 171 177 // ClassificationSolutionVariableImpactsView … … 202 208 private System.Windows.Forms.Label sortByLabel; 203 209 private System.Windows.Forms.ComboBox sortByComboBox; 210 private System.ComponentModel.BackgroundWorker backgroundWorker; 204 211 } 205 212 } -
trunk/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/ClassificationSolutionVariableImpactsView.cs
r15674 r15729 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using System.Threading.Tasks;26 25 using HeuristicLab.Common; 27 26 using HeuristicLab.Data; … … 32 31 [Content(typeof(IClassificationSolution))] 33 32 public partial class ClassificationSolutionVariableImpactsView : DataAnalysisSolutionEvaluationView { 33 #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 34 41 private enum SortingCriteria { 35 42 ImpactValue, … … 37 44 VariableName 38 45 } 39 46 #endregion 47 48 #region Fields 40 49 private Dictionary<string, double> rawVariableImpacts = new Dictionary<string, double>(); 41 50 #endregion 51 52 #region Getter/Setter 42 53 public new IClassificationSolution Content { 43 54 get { return (IClassificationSolution)base.Content; } … … 46 57 } 47 58 } 48 59 #endregion 60 61 #region Ctor 49 62 public ClassificationSolutionVariableImpactsView() 50 63 : base() { … … 55 68 this.sortByComboBox.SelectedItem = SortingCriteria.ImpactValue; 56 69 70 //Set the default values 57 71 this.dataPartitionComboBox.SelectedIndex = 0; 58 72 this.replacementComboBox.SelectedIndex = 0; 59 73 this.factorVarReplComboBox.SelectedIndex = 0; 60 74 } 61 62 #region events 75 #endregion 76 77 #region Events 63 78 protected override void RegisterContentEvents() { 64 79 base.RegisterContentEvents(); … … 86 101 variableImactsArrayView.Content = null; 87 102 } else { 88 UpdateVariableImpacts();103 StartBackgroundWorker(); 89 104 } 90 105 } … … 92 107 93 108 private void dataPartitionComboBox_SelectedIndexChanged(object sender, EventArgs e) { 94 UpdateVariableImpacts();109 StartBackgroundWorker(); 95 110 } 96 111 97 112 private void replacementComboBox_SelectedIndexChanged(object sender, EventArgs e) { 98 UpdateVariableImpacts();113 StartBackgroundWorker(); 99 114 } 100 115 … … 123 138 UpdateDataOrdering(); 124 139 } 140 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 } 125 168 #endregion 126 169 127 170 #region Helper Methods 128 private void UpdateVariableImpacts() { 171 private void StartBackgroundWorker() { 172 //Check if the selection is valid 129 173 if (Content == null) { return; } 130 174 if (replacementComboBox.SelectedIndex < 0) { return; } … … 132 176 if (factorVarReplComboBox.SelectedIndex < 0) { return; } 133 177 134 variableImactsArrayView.Caption = Content.Name + " Variable Impacts"; 135 178 //Prepare arguments 136 179 var mainForm = (MainForm.WindowsForms.MainForm)MainFormManager.MainForm; 137 180 var replMethod = (ClassificationSolutionVariableImpactsCalculator.ReplacementMethodEnum)replacementComboBox.Items[replacementComboBox.SelectedIndex]; 138 181 var factorReplMethod = (ClassificationSolutionVariableImpactsCalculator.FactorReplacementMethodEnum)factorVarReplComboBox.Items[factorVarReplComboBox.SelectedIndex]; 139 182 var dataPartition = (ClassificationSolutionVariableImpactsCalculator.DataPartitionEnum)dataPartitionComboBox.SelectedItem; 140 141 Task.Factory.StartNew(() => { 142 try { 143 mainForm.AddOperationProgressToView(this, "Calculating variable impacts for " + Content.Name); 144 145 //Remember the original ordering of the variables 146 var impacts = ClassificationSolutionVariableImpactsCalculator.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 mainForm.RemoveOperationProgressFromView(this); 155 } 156 }); 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); } 157 193 } 158 194 … … 193 229 ElementNames = orderedEntries.Select(i => i.Key) 194 230 }; 195 variableImactsArrayView.Content = (DoubleArray)impactArray.AsReadOnly(); 196 } 197 #endregion 231 232 //Could be, if the View was closed during the BackgroundWorker-run 233 if (!variableImactsArrayView.IsDisposed) { 234 variableImactsArrayView.Content = (DoubleArray)impactArray.AsReadOnly(); 235 } 236 } 237 #endregion 198 238 } 199 239 }
Note: See TracChangeset
for help on using the changeset viewer.