Changeset 16141 for branches/2817-BinPackingSpeedup/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification
- Timestamp:
- 09/14/18 11:47:37 (6 years ago)
- Location:
- branches/2817-BinPackingSpeedup
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2817-BinPackingSpeedup
- Property svn:mergeinfo changed
-
branches/2817-BinPackingSpeedup/HeuristicLab.Problems.DataAnalysis.Views
- Property svn:mergeinfo changed
-
branches/2817-BinPackingSpeedup/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/ClassificationSolutionVariableImpactsView.Designer.cs
r16140 r16141 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 // … … 185 186 this.Name = "ClassificationSolutionVariableImpactsView"; 186 187 this.Size = new System.Drawing.Size(668, 365); 188 this.VisibleChanged += new System.EventHandler(this.ClassificationSolutionVariableImpactsView_VisibleChanged); 187 189 this.ResumeLayout(false); 188 190 this.PerformLayout(); … … 202 204 private System.Windows.Forms.Label sortByLabel; 203 205 private System.Windows.Forms.ComboBox sortByComboBox; 206 private System.ComponentModel.BackgroundWorker backgroundWorker; 204 207 } 205 208 } -
branches/2817-BinPackingSpeedup/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/ClassificationSolutionVariableImpactsView.cs
r16140 r16141 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using System.Threading; 25 26 using System.Threading.Tasks; 26 27 using HeuristicLab.Common; … … 32 33 [Content(typeof(IClassificationSolution))] 33 34 public partial class ClassificationSolutionVariableImpactsView : DataAnalysisSolutionEvaluationView { 35 #region Nested Types 34 36 private enum SortingCriteria { 35 37 ImpactValue, … … 37 39 VariableName 38 40 } 39 41 #endregion 42 43 #region Fields 40 44 private Dictionary<string, double> rawVariableImpacts = new Dictionary<string, double>(); 41 45 private Thread thread; 46 #endregion 47 48 #region Getter/Setter 42 49 public new IClassificationSolution Content { 43 50 get { return (IClassificationSolution)base.Content; } … … 46 53 } 47 54 } 48 55 #endregion 56 57 #region Ctor 49 58 public ClassificationSolutionVariableImpactsView() 50 59 : base() { … … 55 64 this.sortByComboBox.SelectedItem = SortingCriteria.ImpactValue; 56 65 66 //Set the default values 57 67 this.dataPartitionComboBox.SelectedIndex = 0; 58 68 this.replacementComboBox.SelectedIndex = 0; 59 69 this.factorVarReplComboBox.SelectedIndex = 0; 60 70 } 61 62 #region events 71 #endregion 72 73 #region Events 63 74 protected override void RegisterContentEvents() { 64 75 base.RegisterContentEvents(); … … 86 97 variableImactsArrayView.Content = null; 87 98 } else { 88 UpdateVariableImpacts(); 89 } 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; 90 108 } 91 109 92 110 93 111 private void dataPartitionComboBox_SelectedIndexChanged(object sender, EventArgs e) { 94 UpdateVariableImpact s();112 UpdateVariableImpact(); 95 113 } 96 114 97 115 private void replacementComboBox_SelectedIndexChanged(object sender, EventArgs e) { 98 UpdateVariableImpact s();116 UpdateVariableImpact(); 99 117 } 100 118 … … 123 141 UpdateDataOrdering(); 124 142 } 125 #endregion 126 127 #region Helper Methods 128 private void UpdateVariableImpacts() { 143 144 #endregion 145 146 #region Helper Methods 147 private void UpdateVariableImpact() { 148 //Check if the selection is valid 129 149 if (Content == null) { return; } 130 150 if (replacementComboBox.SelectedIndex < 0) { return; } … … 132 152 if (factorVarReplComboBox.SelectedIndex < 0) { return; } 133 153 134 variableImactsArrayView.Caption = Content.Name + " Variable Impacts"; 135 154 //Prepare arguments 136 155 var mainForm = (MainForm.WindowsForms.MainForm)MainFormManager.MainForm; 137 156 var replMethod = (ClassificationSolutionVariableImpactsCalculator.ReplacementMethodEnum)replacementComboBox.Items[replacementComboBox.SelectedIndex]; … … 139 158 var dataPartition = (ClassificationSolutionVariableImpactsCalculator.DataPartitionEnum)dataPartitionComboBox.SelectedItem; 140 159 160 variableImactsArrayView.Caption = Content.Name + " Variable Impacts"; 161 162 mainForm.AddOperationProgressToView(this, "Calculating variable impacts for " + Content.Name); 163 141 164 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 }); 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()); 157 179 } 158 180 … … 193 215 ElementNames = orderedEntries.Select(i => i.Key) 194 216 }; 195 variableImactsArrayView.Content = (DoubleArray)impactArray.AsReadOnly(); 196 } 197 #endregion 217 218 //Could be, if the View was closed 219 if (!variableImactsArrayView.IsDisposed) { 220 variableImactsArrayView.Content = (DoubleArray)impactArray.AsReadOnly(); 221 } 222 } 223 #endregion 198 224 } 199 225 }
Note: See TracChangeset
for help on using the changeset viewer.