Changeset 16422 for trunk/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionVariableImpactsView.cs
- Timestamp:
- 12/20/18 13:29:51 (6 years ago)
- Location:
- trunk/HeuristicLab.Problems.DataAnalysis.Views
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/HeuristicLab.Problems.DataAnalysis.Views
-
trunk/HeuristicLab.Problems.DataAnalysis.Views/3.4
-
Property
svn:mergeinfo
set to
(toggle deleted branches)
/branches/2904_CalculateImpacts/HeuristicLab.Problems.DataAnalysis.Views/3.4 merged eligible /stable/HeuristicLab.Problems.DataAnalysis.Views/3.4 merged eligible /branches/Async/HeuristicLab.Problems.DataAnalysis.Views/3.4 13329-15286 /branches/Benchmarking/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4 6917-7005 /branches/ClassificationModelComparison/HeuristicLab.Problems.DataAnalysis.Views/3.4 9116-13099 /branches/CloningRefactoring/HeuristicLab.Problems.DataAnalysis.Views/3.4 4656-4721 /branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Views/3.4 5471-5599 /branches/DataAnalysis SolutionEnsembles/HeuristicLab.Problems.DataAnalysis.Views/3.4 5815-6180 /branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.Views/3.4 4458-4459,4462,4464 /branches/DataPreprocessing/HeuristicLab.Problems.DataAnalysis.Views/3.4 10085-11101 /branches/DatasetFeatureCorrelation/HeuristicLab.Problems.DataAnalysis.Views/3.4 8036-8538 /branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis.Views/3.4 6284-6795 /branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Problems.DataAnalysis.Views/3.4 5060 /branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4 11570-12508 /branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.DataAnalysis.Views/3.4 11130-12721 /branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis.Views/3.4 13780-14091 /branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Views/3.4 7098-8789 /branches/NET40/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4 5138-5162 /branches/ParallelEngine/HeuristicLab.Problems.DataAnalysis.Views/3.4 5175-5192 /branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.DataAnalysis.Views/3.4 7568-7810 /branches/QAPAlgorithms/HeuristicLab.Problems.DataAnalysis.Views/3.4 6350-6627 /branches/Restructure trunk solution/HeuristicLab.Problems.DataAnalysis.Views/3.4 6828 /branches/SimplifierViewsProgress/HeuristicLab.Problems.DataAnalysis.Views/3.4 15318-15370 /branches/SuccessProgressAnalysis/HeuristicLab.Problems.DataAnalysis.Views/3.4 5370-5682 /branches/Trunk/HeuristicLab.Problems.DataAnalysis.Views/3.4 6829-6865 /branches/VNS/HeuristicLab.Problems.DataAnalysis.Views/3.4 5594-5752 /branches/histogram/HeuristicLab.Problems.DataAnalysis.Views/3.4 5959-6341 /branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Views/3.4 14232-14825
-
Property
svn:mergeinfo
set to
(toggle deleted branches)
-
trunk/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionVariableImpactsView.cs
r16021 r16422 33 33 [Content(typeof(IRegressionSolution))] 34 34 public partial class RegressionSolutionVariableImpactsView : DataAnalysisSolutionEvaluationView { 35 private CancellationTokenSource cancellationToken = new CancellationTokenSource();36 35 private enum SortingCriteria { 37 36 ImpactValue, … … 39 38 VariableName 40 39 } 40 private CancellationTokenSource cancellationToken = new CancellationTokenSource(); 41 41 private List<Tuple<string, double>> rawVariableImpacts = new List<Tuple<string, double>>(); 42 42 … … 64 64 Content.ProblemDataChanged += new EventHandler(Content_ProblemDataChanged); 65 65 } 66 67 66 protected override void DeregisterContentEvents() { 68 67 base.DeregisterContentEvents(); … … 74 73 OnContentChanged(); 75 74 } 76 77 75 protected virtual void Content_ModelChanged(object sender, EventArgs e) { 78 76 OnContentChanged(); 79 77 } 80 81 78 protected override void OnContentChanged() { 82 79 base.OnContentChanged(); 80 rawVariableImpacts.Clear(); 81 83 82 if (Content == null) { 84 variableIm actsArrayView.Content = null;83 variableImpactsArrayView.Content = null; 85 84 } else { 86 85 UpdateVariableImpact(); 87 86 } 88 87 } 89 90 88 private void RegressionSolutionVariableImpactsView_VisibleChanged(object sender, EventArgs e) { 91 89 cancellationToken.Cancel(); 92 90 } 93 91 94 95 92 private void dataPartitionComboBox_SelectedIndexChanged(object sender, EventArgs e) { 93 rawVariableImpacts.Clear(); 96 94 UpdateVariableImpact(); 97 95 } 98 99 96 private void replacementComboBox_SelectedIndexChanged(object sender, EventArgs e) { 97 rawVariableImpacts.Clear(); 100 98 UpdateVariableImpact(); 101 99 } 102 103 100 private void sortByComboBox_SelectedIndexChanged(object sender, EventArgs e) { 104 101 //Update the default ordering (asc,desc), but remove the eventHandler beforehand (otherwise the data would be ordered twice) … … 109 106 UpdateOrdering(); 110 107 } 111 112 108 private void ascendingCheckBox_CheckedChanged(object sender, EventArgs e) { 113 109 UpdateOrdering(); 114 110 } 115 116 111 117 112 private async void UpdateVariableImpact() { … … 130 125 var dataPartition = (RegressionSolutionVariableImpactsCalculator.DataPartitionEnum)dataPartitionComboBox.SelectedItem; 131 126 132 variableIm actsArrayView.Caption = Content.Name + " Variable Impacts";127 variableImpactsArrayView.Caption = Content.Name + " Variable Impacts"; 133 128 progress = mainForm.AddOperationProgressToView(this, "Calculating variable impacts for " + Content.Name); 134 129 progress.ProgressValue = 0; 135 130 136 131 cancellationToken = new CancellationTokenSource(); 137 //Remember the original ordering of the variables 132 138 133 try { 139 var impacts = await Task.Run(() => RegressionSolutionVariableImpactsCalculator.CalculateImpacts(Content, dataPartition, replMethod, factorReplMethod,140 (i, s) => {141 progress.ProgressValue = i;142 progress.Status = s;143 return cancellationToken.Token.IsCancellationRequested;144 }), cancellationToken.Token);145 146 if (cancellationToken.Token.IsCancellationRequested) { return; }147 134 var problemData = Content.ProblemData; 148 135 var inputvariables = new HashSet<string>(problemData.AllowedInputVariables.Union(Content.Model.VariablesUsedForPrediction)); 136 //Remember the original ordering of the variables 149 137 var originalVariableOrdering = problemData.Dataset.VariableNames 150 138 .Where(v => inputvariables.Contains(v)) … … 152 140 .ToList(); 153 141 154 rawVariableImpacts.Clear(); 155 originalVariableOrdering.ForEach(v => rawVariableImpacts.Add(new Tuple<string, double>(v, impacts.First(vv => vv.Item1 == v).Item2))); 142 List<Tuple<string, double>> impacts = null; 143 await Task.Run(() => { impacts = CalculateVariableImpacts(originalVariableOrdering, Content.Model, problemData, Content.EstimatedValues, dataPartition, replMethod, factorReplMethod, cancellationToken.Token, progress); }); 144 if (impacts == null) { return; } 145 146 rawVariableImpacts.AddRange(impacts); 156 147 UpdateOrdering(); 157 } finally { 148 } 149 finally { 158 150 ((MainForm.WindowsForms.MainForm)MainFormManager.MainForm).RemoveOperationProgressFromView(this); 159 151 } 160 152 } 153 private List<Tuple<string, double>> CalculateVariableImpacts(List<string> originalVariableOrdering, 154 IRegressionModel model, 155 IRegressionProblemData problemData, 156 IEnumerable<double> estimatedValues, 157 RegressionSolutionVariableImpactsCalculator.DataPartitionEnum dataPartition, 158 RegressionSolutionVariableImpactsCalculator.ReplacementMethodEnum replMethod, 159 RegressionSolutionVariableImpactsCalculator.FactorReplacementMethodEnum factorReplMethod, 160 CancellationToken token, 161 IProgress progress) { 162 List<Tuple<string, double>> impacts = new List<Tuple<string, double>>(); 163 int count = originalVariableOrdering.Count; 164 int i = 0; 165 var modifiableDataset = ((Dataset)(problemData.Dataset).Clone()).ToModifiable(); 166 IEnumerable<int> rows = RegressionSolutionVariableImpactsCalculator.GetPartitionRows(dataPartition, problemData); 167 168 //Calculate original quality-values (via calculator, default is R²) 169 IEnumerable<double> targetValuesPartition = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows); 170 IEnumerable<double> estimatedValuesPartition = Content.GetEstimatedValues(rows); 171 172 var originalCalculatorValue = RegressionSolutionVariableImpactsCalculator.CalculateQuality(targetValuesPartition, estimatedValuesPartition); 173 174 foreach (var variableName in originalVariableOrdering) { 175 if (cancellationToken.Token.IsCancellationRequested) { return null; } 176 progress.ProgressValue = (double)++i / count; 177 progress.Status = string.Format("Calculating impact for variable {0} ({1} of {2})", variableName, i, count); 178 179 double impact = 0; 180 //If the variable isn't used for prediction, it has zero impact. 181 if (model.VariablesUsedForPrediction.Contains(variableName)) { 182 impact = RegressionSolutionVariableImpactsCalculator.CalculateImpact(variableName, model, problemData, modifiableDataset, rows, replMethod, factorReplMethod, targetValuesPartition, originalCalculatorValue); 183 } 184 impacts.Add(new Tuple<string, double>(variableName, impact)); 185 } 186 187 return impacts; 188 } 161 189 162 190 /// <summary> 163 /// Updates the <see cref="variableIm actsArrayView"/> according to the selected ordering <see cref="ascendingCheckBox"/> of the selected Column <see cref="sortByComboBox"/>191 /// Updates the <see cref="variableImpactsArrayView"/> according to the selected ordering <see cref="ascendingCheckBox"/> of the selected Column <see cref="sortByComboBox"/> 164 192 /// The default is "Descending" by "VariableImpact" (as in previous versions) 165 193 /// </summary> … … 198 226 199 227 //Could be, if the View was closed 200 if (!variableIm actsArrayView.IsDisposed) {201 variableIm actsArrayView.Content = (DoubleArray)impactArray.AsReadOnly();228 if (!variableImpactsArrayView.IsDisposed) { 229 variableImpactsArrayView.Content = (DoubleArray)impactArray.AsReadOnly(); 202 230 } 203 231 }
Note: See TracChangeset
for help on using the changeset viewer.