Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/20/18 13:29:51 (6 years ago)
Author:
fholzing
Message:

#2904: reintegrated branch

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.4mergedeligible
      /stable/HeuristicLab.Problems.DataAnalysis.Views/3.4mergedeligible
      /branches/Async/HeuristicLab.Problems.DataAnalysis.Views/3.413329-15286
      /branches/Benchmarking/sources/HeuristicLab.Problems.DataAnalysis.Views/3.46917-7005
      /branches/ClassificationModelComparison/HeuristicLab.Problems.DataAnalysis.Views/3.49116-13099
      /branches/CloningRefactoring/HeuristicLab.Problems.DataAnalysis.Views/3.44656-4721
      /branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Views/3.45471-5599
      /branches/DataAnalysis SolutionEnsembles/HeuristicLab.Problems.DataAnalysis.Views/3.45815-6180
      /branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.Views/3.44458-4459,​4462,​4464
      /branches/DataPreprocessing/HeuristicLab.Problems.DataAnalysis.Views/3.410085-11101
      /branches/DatasetFeatureCorrelation/HeuristicLab.Problems.DataAnalysis.Views/3.48036-8538
      /branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis.Views/3.46284-6795
      /branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Problems.DataAnalysis.Views/3.45060
      /branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.Problems.DataAnalysis.Views/3.411570-12508
      /branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.DataAnalysis.Views/3.411130-12721
      /branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis.Views/3.413780-14091
      /branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Views/3.47098-8789
      /branches/NET40/sources/HeuristicLab.Problems.DataAnalysis.Views/3.45138-5162
      /branches/ParallelEngine/HeuristicLab.Problems.DataAnalysis.Views/3.45175-5192
      /branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.DataAnalysis.Views/3.47568-7810
      /branches/QAPAlgorithms/HeuristicLab.Problems.DataAnalysis.Views/3.46350-6627
      /branches/Restructure trunk solution/HeuristicLab.Problems.DataAnalysis.Views/3.46828
      /branches/SimplifierViewsProgress/HeuristicLab.Problems.DataAnalysis.Views/3.415318-15370
      /branches/SuccessProgressAnalysis/HeuristicLab.Problems.DataAnalysis.Views/3.45370-5682
      /branches/Trunk/HeuristicLab.Problems.DataAnalysis.Views/3.46829-6865
      /branches/VNS/HeuristicLab.Problems.DataAnalysis.Views/3.45594-5752
      /branches/histogram/HeuristicLab.Problems.DataAnalysis.Views/3.45959-6341
      /branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Views/3.414232-14825
  • trunk/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionVariableImpactsView.cs

    r16021 r16422  
    3333  [Content(typeof(IRegressionSolution))]
    3434  public partial class RegressionSolutionVariableImpactsView : DataAnalysisSolutionEvaluationView {
    35     private CancellationTokenSource cancellationToken = new CancellationTokenSource();
    3635    private enum SortingCriteria {
    3736      ImpactValue,
     
    3938      VariableName
    4039    }
     40    private CancellationTokenSource cancellationToken = new CancellationTokenSource();
    4141    private List<Tuple<string, double>> rawVariableImpacts = new List<Tuple<string, double>>();
    4242
     
    6464      Content.ProblemDataChanged += new EventHandler(Content_ProblemDataChanged);
    6565    }
    66 
    6766    protected override void DeregisterContentEvents() {
    6867      base.DeregisterContentEvents();
     
    7473      OnContentChanged();
    7574    }
    76 
    7775    protected virtual void Content_ModelChanged(object sender, EventArgs e) {
    7876      OnContentChanged();
    7977    }
    80 
    8178    protected override void OnContentChanged() {
    8279      base.OnContentChanged();
     80      rawVariableImpacts.Clear();
     81
    8382      if (Content == null) {
    84         variableImactsArrayView.Content = null;
     83        variableImpactsArrayView.Content = null;
    8584      } else {
    8685        UpdateVariableImpact();
    8786      }
    8887    }
    89 
    9088    private void RegressionSolutionVariableImpactsView_VisibleChanged(object sender, EventArgs e) {
    9189      cancellationToken.Cancel();
    9290    }
    9391
    94 
    9592    private void dataPartitionComboBox_SelectedIndexChanged(object sender, EventArgs e) {
     93      rawVariableImpacts.Clear();
    9694      UpdateVariableImpact();
    9795    }
    98 
    9996    private void replacementComboBox_SelectedIndexChanged(object sender, EventArgs e) {
     97      rawVariableImpacts.Clear();
    10098      UpdateVariableImpact();
    10199    }
    102 
    103100    private void sortByComboBox_SelectedIndexChanged(object sender, EventArgs e) {
    104101      //Update the default ordering (asc,desc), but remove the eventHandler beforehand (otherwise the data would be ordered twice)
     
    109106      UpdateOrdering();
    110107    }
    111 
    112108    private void ascendingCheckBox_CheckedChanged(object sender, EventArgs e) {
    113109      UpdateOrdering();
    114110    }
    115 
    116111
    117112    private async void UpdateVariableImpact() {
     
    130125      var dataPartition = (RegressionSolutionVariableImpactsCalculator.DataPartitionEnum)dataPartitionComboBox.SelectedItem;
    131126
    132       variableImactsArrayView.Caption = Content.Name + " Variable Impacts";
     127      variableImpactsArrayView.Caption = Content.Name + " Variable Impacts";
    133128      progress = mainForm.AddOperationProgressToView(this, "Calculating variable impacts for " + Content.Name);
    134129      progress.ProgressValue = 0;
    135130
    136131      cancellationToken = new CancellationTokenSource();
    137       //Remember the original ordering of the variables
     132
    138133      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; }
    147134        var problemData = Content.ProblemData;
    148135        var inputvariables = new HashSet<string>(problemData.AllowedInputVariables.Union(Content.Model.VariablesUsedForPrediction));
     136        //Remember the original ordering of the variables
    149137        var originalVariableOrdering = problemData.Dataset.VariableNames
    150138          .Where(v => inputvariables.Contains(v))
     
    152140          .ToList();
    153141
    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);
    156147        UpdateOrdering();
    157       } finally {
     148      }
     149      finally {
    158150        ((MainForm.WindowsForms.MainForm)MainFormManager.MainForm).RemoveOperationProgressFromView(this);
    159151      }
    160152    }
     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    }
    161189
    162190    /// <summary>
    163     /// Updates the <see cref="variableImactsArrayView"/> 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"/>
    164192    /// The default is "Descending" by "VariableImpact" (as in previous versions)
    165193    /// </summary>
     
    198226
    199227      //Could be, if the View was closed
    200       if (!variableImactsArrayView.IsDisposed) {
    201         variableImactsArrayView.Content = (DoubleArray)impactArray.AsReadOnly();
     228      if (!variableImpactsArrayView.IsDisposed) {
     229        variableImpactsArrayView.Content = (DoubleArray)impactArray.AsReadOnly();
    202230      }
    203231    }
Note: See TracChangeset for help on using the changeset viewer.