Changeset 15727 for trunk/HeuristicLab.Problems.DataAnalysis.Views/3.4
- Timestamp:
- 02/07/18 12:47:26 (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
r15673 r15727 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(); 57 58 this.SuspendLayout(); 58 59 // … … 169 170 this.variableImactsArrayView.Size = new System.Drawing.Size(706, 278); 170 171 this.variableImactsArrayView.TabIndex = 2; 172 // 173 // backgroundWorker 174 // 175 this.backgroundWorker.DoWork += new System.ComponentModel.DoWorkEventHandler(this.BackgroundWorker_DoWork); 176 this.backgroundWorker.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(this.BackgroundWorker_RunWorkerCompleted); 171 177 // 172 178 // RegressionSolutionVariableImpactsView … … 203 209 private System.Windows.Forms.ComboBox sortByComboBox; 204 210 private System.Windows.Forms.CheckBox ascendingCheckBox; 211 private System.ComponentModel.BackgroundWorker backgroundWorker; 205 212 } 206 213 } -
trunk/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionVariableImpactsView.cs
r15673 r15727 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(IRegressionSolution))] 33 32 public partial class RegressionSolutionVariableImpactsView : DataAnalysisSolutionEvaluationView { 33 #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 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 IRegressionSolution Content { 43 54 get { return (IRegressionSolution)base.Content; } … … 46 57 } 47 58 } 48 59 #endregion 60 61 #region Ctor 49 62 public RegressionSolutionVariableImpactsView() 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 } 125 #endregion 126 127 #region Helper Methods 128 private void UpdateVariableImpacts() { 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 = 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 #endregion 169 170 #region Helper Methods 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 = (RegressionSolutionVariableImpactsCalculator.ReplacementMethodEnum)replacementComboBox.Items[replacementComboBox.SelectedIndex]; 138 181 var factorReplMethod = (RegressionSolutionVariableImpactsCalculator.FactorReplacementMethodEnum)factorVarReplComboBox.Items[factorVarReplComboBox.SelectedIndex]; 139 182 var dataPartition = (RegressionSolutionVariableImpactsCalculator.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 = RegressionSolutionVariableImpactsCalculator.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(); 231 232 //Could be, if the View was closed during the BackgroundWorker-run 233 if (!variableImactsArrayView.IsDisposed) { 234 variableImactsArrayView.Content = (DoubleArray)impactArray.AsReadOnly(); 235 } 196 236 } 197 237 #endregion
Note: See TracChangeset
for help on using the changeset viewer.