Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/21/18 14:20:24 (5 years ago)
Author:
mkommend
Message:

#2904: Merged r16422 and r16423 into stable.

Location:
stable
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Problems.DataAnalysis.Views

  • stable/HeuristicLab.Problems.DataAnalysis.Views/3.4

    • Property svn:mergeinfo set to (toggle deleted branches)
      /trunk/HeuristicLab.Problems.DataAnalysis.Views/3.4mergedeligible
      /branches/2904_CalculateImpacts/HeuristicLab.Problems.DataAnalysis.Views/3.416029-16421
      /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-5808
      /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/sources/HeuristicLab.Problems.DataAnalysis.Views/3.49568,​9845,​9859-9860,​9865-9868,​9893-9896,​9900-9901,​9905,​9907,​9973-9975,​9994,​10173-10176,​10500,​10526,​10540-10541,​10543,​10545,​10941,​11031,​11093,​11114,​11116,​11156,​11214,​11367,​11623,​11631,​11634,​12137,​12151-12152,​12365,​12493,​12509-12511,​12524,​12577-12578,​12614,​12642,​12670,​12679,​12722,​12770,​12772,​12790-12792,​12796,​12798,​12801,​12811-12812,​12817,​12836-12837,​12907,​12971,​13002-13004,​13087,​13100-13104,​13154,​13167-13169,​13186,​13268,​13406,​13428-13430,​13434,​13439,​13450,​13474,​13501,​13503,​13511,​13513,​13534-13535,​13540,​13550,​13552,​13592-13593,​13645,​13648,​13650-13652,​13654,​13657-13659,​13661-13662,​13666,​13669,​13682-13684,​13690-13693,​13704-13705,​13708-13709,​13711,​13715,​13724,​13746,​13764-13766,​13807,​13938,​13942,​13958,​13985-13987,​13992-13993,​14000-14001,​14007-14008,​14014-14016,​14095-14096,​14098-14099,​14107,​14118-14119,​14131,​14135,​14142,​14152,​14155-14160,​14226,​14228-14230,​14234-14236,​14244-14247,​14250,​14255-14258,​14260,​14267,​14271-14272,​14282,​14284-14292,​14296-14298,​14300,​14307,​14314-14316,​14319,​14322,​14332,​14343-14350,​14358,​14367-14368,​14378,​14381-14382,​14384,​14388,​14390-14391,​14393-14394,​14396,​14400,​14405,​14407-14408,​14418,​14422-14423,​14425,​14434,​14463-14464,​14468-14469,​14479,​14483,​14486,​14507,​14517,​14523,​14527,​14529,​14531-14533,​14553,​14623,​14630,​14770,​14772,​14781,​14789-14791,​14805,​14826-14827,​14829-14832,​14839-14840,​14843,​14845-14847,​14851-14854,​14857,​14864-14865,​14871,​14889-14890,​14899,​14904,​14918,​14937-14938,​14940,​14943-14946,​14948-14951,​15002,​15013,​15015-15016,​15023-15024,​15026,​15046,​15052-15054,​15058,​15077,​15085,​15088,​15094,​15103-15106,​15111-15113,​15122-15124,​15129,​15139,​15160,​15163,​15165,​15184-15185,​15187,​15194,​15211,​15213,​15222,​15287,​15371-15372,​15390,​15395,​15400,​15402,​15427,​15486
  • stable/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionVariableImpactsView.cs

    r16435 r16438  
    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.