Changeset 17426 for trunk/HeuristicLab.Problems.DataAnalysis.Views
- Timestamp:
- 02/06/20 16:54:29 (5 years ago)
- Location:
- trunk/HeuristicLab.Problems.DataAnalysis.Views/3.4
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/ClassificationSolutionVariableImpactsView.cs
r17276 r17426 25 25 using System.Threading; 26 26 using System.Threading.Tasks; 27 using System.Windows.Forms; 27 28 using HeuristicLab.Common; 28 29 using HeuristicLab.Data; … … 40 41 private CancellationTokenSource cancellationToken = new CancellationTokenSource(); 41 42 private List<Tuple<string, double>> rawVariableImpacts = new List<Tuple<string, double>>(); 42 private bool attachedToProgress = false;43 43 44 44 public new IClassificationSolution Content { … … 87 87 } 88 88 } 89 protected override void OnHidden(EventArgs e) { 90 base.OnHidden(e); 89 protected override void OnVisibleChanged(EventArgs e) { 90 base.OnVisibleChanged(e); 91 if (!this.Visible) { 92 cancellationToken.Cancel(); 93 } 94 } 95 96 protected override void OnClosed(FormClosedEventArgs e) { 97 base.OnClosed(e); 91 98 cancellationToken.Cancel(); 92 93 if (attachedToProgress) {94 Progress.Hide(this);95 attachedToProgress = false;96 }97 99 } 98 100 … … 133 135 variableImpactsArrayView.Caption = Content.Name + " Variable Impacts"; 134 136 progress = Progress.Show(this, "Calculating variable impacts for " + Content.Name); 135 attachedToProgress = true;136 137 cancellationToken = new CancellationTokenSource(); 137 138 … … 145 146 .ToList(); 146 147 147 List<Tuple<string, double>> impacts = null; 148 await Task.Run(() => { impacts = CalculateVariableImpacts(originalVariableOrdering, Content.Model, problemData, Content.EstimatedClassValues, dataPartition, replMethod, factorReplMethod, cancellationToken.Token, progress); }); 149 if (impacts == null) { return; } 148 var impacts = await Task.Run(() => CalculateVariableImpacts(originalVariableOrdering, Content.Model, problemData, Content.EstimatedClassValues, dataPartition, replMethod, factorReplMethod, cancellationToken.Token, progress)); 150 149 151 150 rawVariableImpacts.AddRange(impacts); 152 151 UpdateOrdering(); 152 } catch (OperationCanceledException) { 153 153 } finally { 154 if (attachedToProgress) { 155 Progress.Hide(this); 156 attachedToProgress = false; 157 } 154 Progress.Hide(this); 158 155 } 159 156 } … … 180 177 var clonedModel = (IClassificationModel)model.Clone(); 181 178 foreach (var variableName in originalVariableOrdering) { 182 if (cancellationToken.Token.IsCancellationRequested) { return null; }179 token.ThrowIfCancellationRequested(); 183 180 progress.ProgressValue = (double)++i / count; 184 181 progress.Message = string.Format("Calculating impact for variable {0} ({1} of {2})", variableName, i, count); -
trunk/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionVariableImpactsView.cs
r17276 r17426 25 25 using System.Threading; 26 26 using System.Threading.Tasks; 27 using System.Windows.Forms; 27 28 using HeuristicLab.Common; 28 29 using HeuristicLab.Data; … … 40 41 private CancellationTokenSource cancellationToken = new CancellationTokenSource(); 41 42 private List<Tuple<string, double>> rawVariableImpacts = new List<Tuple<string, double>>(); 42 private bool attachedToProgress = false;43 43 44 44 public new IRegressionSolution Content { … … 88 88 } 89 89 90 protected override void OnHidden(EventArgs e) { 91 base.OnHidden(e); 90 protected override void OnVisibleChanged(EventArgs e) { 91 base.OnVisibleChanged(e); 92 if (!this.Visible) { 93 cancellationToken.Cancel(); 94 } 95 } 96 97 protected override void OnClosed(FormClosedEventArgs e) { 98 base.OnClosed(e); 92 99 cancellationToken.Cancel(); 93 94 if (attachedToProgress) {95 Progress.Hide(this);96 attachedToProgress = false;97 }98 100 } 99 101 … … 132 134 variableImpactsArrayView.Caption = Content.Name + " Variable Impacts"; 133 135 var progress = Progress.Show(this, "Calculating variable impacts for " + Content.Name); 134 attachedToProgress = true;135 136 cancellationToken = new CancellationTokenSource(); 136 137 … … 144 145 .ToList(); 145 146 146 List<Tuple<string, double>> impacts = null; 147 await Task.Run(() => { impacts = CalculateVariableImpacts(originalVariableOrdering, Content.Model, problemData, Content.EstimatedValues, dataPartition, replMethod, factorReplMethod, cancellationToken.Token, progress); }); 148 if (impacts == null) { return; } 147 var impacts = await Task.Run(() => CalculateVariableImpacts(originalVariableOrdering, Content.Model, problemData, Content.EstimatedValues, dataPartition, replMethod, factorReplMethod, cancellationToken.Token, progress)); 149 148 150 149 rawVariableImpacts.AddRange(impacts); 151 150 UpdateOrdering(); 151 } catch (OperationCanceledException) { 152 152 } finally { 153 if (attachedToProgress) { 154 Progress.Hide(this); 155 attachedToProgress = false; 156 } 153 Progress.Hide(this); 157 154 } 158 155 } … … 179 176 180 177 foreach (var variableName in originalVariableOrdering) { 181 if (cancellationToken.Token.IsCancellationRequested) { return null; }178 token.ThrowIfCancellationRequested(); 182 179 progress.ProgressValue = (double)++i / count; 183 180 progress.Message = string.Format("Calculating impact for variable {0} ({1} of {2})", variableName, i, count);
Note: See TracChangeset
for help on using the changeset viewer.