Free cookie consent management tool by TermsFeed Policy Generator

Changeset 16435


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

#2871: Merged r15626, r15637, r15665, r15673, r15727, r15728, r15752, r15796, r15797, r15798, r15799, r15802, r15998, r15999, r16015, r16021, r16023 into stable.

Location:
stable
Files:
8 edited
1 copied

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Problems.DataAnalysis

  • stable/HeuristicLab.Problems.DataAnalysis.Views

  • stable/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionVariableImpactsView.Designer.cs

    r15584 r16435  
    1919 */
    2020#endregion
     21
     22
    2123namespace HeuristicLab.Problems.DataAnalysis.Views {
    2224  partial class RegressionSolutionVariableImpactsView {
     
    4446    /// </summary>
    4547    private void InitializeComponent() {
     48      this.ascendingCheckBox = new System.Windows.Forms.CheckBox();
     49      this.sortByLabel = new System.Windows.Forms.Label();
     50      this.sortByComboBox = new System.Windows.Forms.ComboBox();
     51      this.factorVarReplComboBox = new System.Windows.Forms.ComboBox();
     52      this.factorVarReplacementLabel = new System.Windows.Forms.Label();
     53      this.replacementComboBox = new System.Windows.Forms.ComboBox();
     54      this.numericVarReplacementLabel = new System.Windows.Forms.Label();
     55      this.dataPartitionLabel = new System.Windows.Forms.Label();
     56      this.dataPartitionComboBox = new System.Windows.Forms.ComboBox();
    4657      this.variableImactsArrayView = new HeuristicLab.Data.Views.StringConvertibleArrayView();
    47       this.dataPartitionComboBox = new System.Windows.Forms.ComboBox();
    48       this.dataPartitionLabel = new System.Windows.Forms.Label();
    49       this.numericVarReplacementLabel = new System.Windows.Forms.Label();
    50       this.replacementComboBox = new System.Windows.Forms.ComboBox();
    51       this.factorVarReplacementLabel = new System.Windows.Forms.Label();
    52       this.factorVarReplComboBox = new System.Windows.Forms.ComboBox();
    5358      this.SuspendLayout();
    5459      //
    55       // variableImactsArrayView
    56       //
    57       this.variableImactsArrayView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    58             | System.Windows.Forms.AnchorStyles.Left)
    59             | System.Windows.Forms.AnchorStyles.Right)));
    60       this.variableImactsArrayView.Caption = "StringConvertibleArray View";
    61       this.variableImactsArrayView.Content = null;
    62       this.variableImactsArrayView.Location = new System.Drawing.Point(3, 84);
    63       this.variableImactsArrayView.Name = "variableImactsArrayView";
    64       this.variableImactsArrayView.ReadOnly = true;
    65       this.variableImactsArrayView.Size = new System.Drawing.Size(363, 278);
    66       this.variableImactsArrayView.TabIndex = 2;
    67       //
    68       // dataPartitionComboBox
    69       //
    70       this.dataPartitionComboBox.FormattingEnabled = true;
    71       this.dataPartitionComboBox.Items.AddRange(new object[] {
    72             HeuristicLab.Problems.DataAnalysis.RegressionSolutionVariableImpactsCalculator.DataPartitionEnum.Training,
    73             HeuristicLab.Problems.DataAnalysis.RegressionSolutionVariableImpactsCalculator.DataPartitionEnum.Test,
    74             HeuristicLab.Problems.DataAnalysis.RegressionSolutionVariableImpactsCalculator.DataPartitionEnum.All});
    75       this.dataPartitionComboBox.Location = new System.Drawing.Point(197, 3);
    76       this.dataPartitionComboBox.Name = "dataPartitionComboBox";
    77       this.dataPartitionComboBox.Size = new System.Drawing.Size(121, 21);
    78       this.dataPartitionComboBox.TabIndex = 1;
    79       this.dataPartitionComboBox.SelectedIndexChanged += new System.EventHandler(this.dataPartitionComboBox_SelectedIndexChanged);
    80       //
    81       // dataPartitionLabel
    82       //
    83       this.dataPartitionLabel.AutoSize = true;
    84       this.dataPartitionLabel.Location = new System.Drawing.Point(3, 6);
    85       this.dataPartitionLabel.Name = "dataPartitionLabel";
    86       this.dataPartitionLabel.Size = new System.Drawing.Size(73, 13);
    87       this.dataPartitionLabel.TabIndex = 0;
    88       this.dataPartitionLabel.Text = "Data partition:";
    89       //
    90       // numericVarReplacementLabel
    91       //
    92       this.numericVarReplacementLabel.AutoSize = true;
    93       this.numericVarReplacementLabel.Location = new System.Drawing.Point(3, 33);
    94       this.numericVarReplacementLabel.Name = "numericVarReplacementLabel";
    95       this.numericVarReplacementLabel.Size = new System.Drawing.Size(173, 13);
    96       this.numericVarReplacementLabel.TabIndex = 2;
    97       this.numericVarReplacementLabel.Text = "Replacement for numeric variables:";
     60      // ascendingCheckBox
     61      //
     62      this.ascendingCheckBox.AutoSize = true;
     63      this.ascendingCheckBox.Location = new System.Drawing.Point(534, 6);
     64      this.ascendingCheckBox.Name = "ascendingCheckBox";
     65      this.ascendingCheckBox.Size = new System.Drawing.Size(76, 17);
     66      this.ascendingCheckBox.TabIndex = 7;
     67      this.ascendingCheckBox.Text = "Ascending";
     68      this.ascendingCheckBox.UseVisualStyleBackColor = true;
     69      this.ascendingCheckBox.CheckedChanged += new System.EventHandler(this.ascendingCheckBox_CheckedChanged);
     70      //
     71      // sortByLabel
     72      //
     73      this.sortByLabel.AutoSize = true;
     74      this.sortByLabel.Location = new System.Drawing.Point(324, 6);
     75      this.sortByLabel.Name = "sortByLabel";
     76      this.sortByLabel.Size = new System.Drawing.Size(77, 13);
     77      this.sortByLabel.TabIndex = 4;
     78      this.sortByLabel.Text = "Sorting criteria:";
     79      //
     80      // sortByComboBox
     81      //
     82      this.sortByComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
     83      this.sortByComboBox.FormattingEnabled = true;
     84      this.sortByComboBox.Items.AddRange(new object[] {
     85            HeuristicLab.Problems.DataAnalysis.Views.RegressionSolutionVariableImpactsView.SortingCriteria.ImpactValue,
     86            HeuristicLab.Problems.DataAnalysis.Views.RegressionSolutionVariableImpactsView.SortingCriteria.Occurrence,
     87            HeuristicLab.Problems.DataAnalysis.Views.RegressionSolutionVariableImpactsView.SortingCriteria.VariableName});
     88      this.sortByComboBox.Location = new System.Drawing.Point(407, 3);
     89      this.sortByComboBox.Name = "sortByComboBox";
     90      this.sortByComboBox.Size = new System.Drawing.Size(121, 21);
     91      this.sortByComboBox.TabIndex = 5;
     92      this.sortByComboBox.SelectedIndexChanged += new System.EventHandler(this.sortByComboBox_SelectedIndexChanged);
     93      //
     94      // factorVarReplComboBox
     95      //
     96      this.factorVarReplComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
     97      this.factorVarReplComboBox.FormattingEnabled = true;
     98      this.factorVarReplComboBox.Items.AddRange(new object[] {
     99            HeuristicLab.Problems.DataAnalysis.RegressionSolutionVariableImpactsCalculator.FactorReplacementMethodEnum.Best,
     100            HeuristicLab.Problems.DataAnalysis.RegressionSolutionVariableImpactsCalculator.FactorReplacementMethodEnum.Mode,
     101            HeuristicLab.Problems.DataAnalysis.RegressionSolutionVariableImpactsCalculator.FactorReplacementMethodEnum.Shuffle});
     102      this.factorVarReplComboBox.Location = new System.Drawing.Point(197, 57);
     103      this.factorVarReplComboBox.Name = "factorVarReplComboBox";
     104      this.factorVarReplComboBox.Size = new System.Drawing.Size(121, 21);
     105      this.factorVarReplComboBox.TabIndex = 1;
     106      this.factorVarReplComboBox.SelectedIndexChanged += new System.EventHandler(this.replacementComboBox_SelectedIndexChanged);
     107      //
     108      // factorVarReplacementLabel
     109      //
     110      this.factorVarReplacementLabel.AutoSize = true;
     111      this.factorVarReplacementLabel.Location = new System.Drawing.Point(3, 60);
     112      this.factorVarReplacementLabel.Name = "factorVarReplacementLabel";
     113      this.factorVarReplacementLabel.Size = new System.Drawing.Size(188, 13);
     114      this.factorVarReplacementLabel.TabIndex = 0;
     115      this.factorVarReplacementLabel.Text = "Replacement for categorical variables:";
    98116      //
    99117      // replacementComboBox
    100118      //
     119      this.replacementComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
    101120      this.replacementComboBox.FormattingEnabled = true;
    102121      this.replacementComboBox.Items.AddRange(new object[] {
     
    111130      this.replacementComboBox.SelectedIndexChanged += new System.EventHandler(this.replacementComboBox_SelectedIndexChanged);
    112131      //
    113       // factorVarReplacementLabel
    114       //
    115       this.factorVarReplacementLabel.AutoSize = true;
    116       this.factorVarReplacementLabel.Location = new System.Drawing.Point(3, 60);
    117       this.factorVarReplacementLabel.Name = "factorVarReplacementLabel";
    118       this.factorVarReplacementLabel.Size = new System.Drawing.Size(188, 13);
    119       this.factorVarReplacementLabel.TabIndex = 0;
    120       this.factorVarReplacementLabel.Text = "Replacement for categorical variables:";
    121       //
    122       // factorVarReplComboBox
    123       //
    124       this.factorVarReplComboBox.FormattingEnabled = true;
    125       this.factorVarReplComboBox.Items.AddRange(new object[] {
    126             HeuristicLab.Problems.DataAnalysis.RegressionSolutionVariableImpactsCalculator.FactorReplacementMethodEnum.Best,
    127             HeuristicLab.Problems.DataAnalysis.RegressionSolutionVariableImpactsCalculator.FactorReplacementMethodEnum.Mode,
    128             HeuristicLab.Problems.DataAnalysis.RegressionSolutionVariableImpactsCalculator.FactorReplacementMethodEnum.Shuffle});
    129       this.factorVarReplComboBox.Location = new System.Drawing.Point(197, 57);
    130       this.factorVarReplComboBox.Name = "factorVarReplComboBox";
    131       this.factorVarReplComboBox.Size = new System.Drawing.Size(121, 21);
    132       this.factorVarReplComboBox.TabIndex = 1;
    133       this.factorVarReplComboBox.SelectedIndexChanged += new System.EventHandler(this.replacementComboBox_SelectedIndexChanged);
     132      // numericVarReplacementLabel
     133      //
     134      this.numericVarReplacementLabel.AutoSize = true;
     135      this.numericVarReplacementLabel.Location = new System.Drawing.Point(3, 33);
     136      this.numericVarReplacementLabel.Name = "numericVarReplacementLabel";
     137      this.numericVarReplacementLabel.Size = new System.Drawing.Size(173, 13);
     138      this.numericVarReplacementLabel.TabIndex = 2;
     139      this.numericVarReplacementLabel.Text = "Replacement for numeric variables:";
     140      //
     141      // dataPartitionLabel
     142      //
     143      this.dataPartitionLabel.AutoSize = true;
     144      this.dataPartitionLabel.Location = new System.Drawing.Point(3, 6);
     145      this.dataPartitionLabel.Name = "dataPartitionLabel";
     146      this.dataPartitionLabel.Size = new System.Drawing.Size(73, 13);
     147      this.dataPartitionLabel.TabIndex = 0;
     148      this.dataPartitionLabel.Text = "Data partition:";
     149      //
     150      // dataPartitionComboBox
     151      //
     152      this.dataPartitionComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
     153      this.dataPartitionComboBox.FormattingEnabled = true;
     154      this.dataPartitionComboBox.Items.AddRange(new object[] {
     155            HeuristicLab.Problems.DataAnalysis.RegressionSolutionVariableImpactsCalculator.DataPartitionEnum.Training,
     156            HeuristicLab.Problems.DataAnalysis.RegressionSolutionVariableImpactsCalculator.DataPartitionEnum.Test,
     157            HeuristicLab.Problems.DataAnalysis.RegressionSolutionVariableImpactsCalculator.DataPartitionEnum.All});
     158      this.dataPartitionComboBox.Location = new System.Drawing.Point(197, 3);
     159      this.dataPartitionComboBox.Name = "dataPartitionComboBox";
     160      this.dataPartitionComboBox.Size = new System.Drawing.Size(121, 21);
     161      this.dataPartitionComboBox.TabIndex = 1;
     162      this.dataPartitionComboBox.SelectedIndexChanged += new System.EventHandler(this.dataPartitionComboBox_SelectedIndexChanged);
     163      //
     164      // variableImactsArrayView
     165      //
     166      this.variableImactsArrayView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     167            | System.Windows.Forms.AnchorStyles.Left)
     168            | System.Windows.Forms.AnchorStyles.Right)));
     169      this.variableImactsArrayView.Caption = "StringConvertibleArray View";
     170      this.variableImactsArrayView.Content = null;
     171      this.variableImactsArrayView.Location = new System.Drawing.Point(3, 84);
     172      this.variableImactsArrayView.Name = "variableImactsArrayView";
     173      this.variableImactsArrayView.ReadOnly = true;
     174      this.variableImactsArrayView.Size = new System.Drawing.Size(706, 278);
     175      this.variableImactsArrayView.TabIndex = 2;
    134176      //
    135177      // RegressionSolutionVariableImpactsView
     
    137179      this.AllowDrop = true;
    138180      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
     181      this.Controls.Add(this.ascendingCheckBox);
     182      this.Controls.Add(this.sortByLabel);
     183      this.Controls.Add(this.sortByComboBox);
    139184      this.Controls.Add(this.factorVarReplComboBox);
    140185      this.Controls.Add(this.factorVarReplacementLabel);
     
    145190      this.Controls.Add(this.variableImactsArrayView);
    146191      this.Name = "RegressionSolutionVariableImpactsView";
    147       this.Size = new System.Drawing.Size(369, 365);
     192      this.Size = new System.Drawing.Size(712, 365);
     193      this.VisibleChanged += new System.EventHandler(this.RegressionSolutionVariableImpactsView_VisibleChanged);
    148194      this.ResumeLayout(false);
    149195      this.PerformLayout();
     
    160206    private System.Windows.Forms.Label factorVarReplacementLabel;
    161207    private System.Windows.Forms.ComboBox factorVarReplComboBox;
     208    private System.Windows.Forms.Label sortByLabel;
     209    private System.Windows.Forms.ComboBox sortByComboBox;
     210    private System.Windows.Forms.CheckBox ascendingCheckBox;
    162211  }
    163212}
  • stable/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionVariableImpactsView.cs

    r15584 r16435  
    1919 */
    2020#endregion
     21
    2122using System;
     23using System.Collections.Generic;
    2224using System.Linq;
     25using System.Threading;
    2326using System.Threading.Tasks;
     27using HeuristicLab.Common;
    2428using HeuristicLab.Data;
    2529using HeuristicLab.MainForm;
    26 using HeuristicLab.Problems.DataAnalysis.Symbolic.Regression;
    2730
    2831namespace HeuristicLab.Problems.DataAnalysis.Views {
     
    3033  [Content(typeof(IRegressionSolution))]
    3134  public partial class RegressionSolutionVariableImpactsView : DataAnalysisSolutionEvaluationView {
     35    private CancellationTokenSource cancellationToken = new CancellationTokenSource();
     36    private enum SortingCriteria {
     37      ImpactValue,
     38      Occurrence,
     39      VariableName
     40    }
     41    private List<Tuple<string, double>> rawVariableImpacts = new List<Tuple<string, double>>();
    3242
    3343    public new IRegressionSolution Content {
     
    4151      : base() {
    4252      InitializeComponent();
     53
     54      //Set the default values
    4355      this.dataPartitionComboBox.SelectedIndex = 0;
    44       this.replacementComboBox.SelectedIndex = 0;
     56      this.replacementComboBox.SelectedIndex = 3;
    4557      this.factorVarReplComboBox.SelectedIndex = 0;
    46     }
    47 
    48     #region events
     58      this.sortByComboBox.SelectedItem = SortingCriteria.ImpactValue;
     59    }
     60
    4961    protected override void RegisterContentEvents() {
    5062      base.RegisterContentEvents();
     
    7284        variableImactsArrayView.Content = null;
    7385      } else {
    74         UpdateVariableImpacts();
    75       }
    76     }
    77 
    78     private void UpdateVariableImpacts() {
    79       if (Content == null || replacementComboBox.SelectedIndex < 0
    80         || factorVarReplComboBox.SelectedIndex < 0
    81         || dataPartitionComboBox.SelectedIndex < 0) return;
     86        UpdateVariableImpact();
     87      }
     88    }
     89
     90    private void RegressionSolutionVariableImpactsView_VisibleChanged(object sender, EventArgs e) {
     91      cancellationToken.Cancel();
     92    }
     93
     94
     95    private void dataPartitionComboBox_SelectedIndexChanged(object sender, EventArgs e) {
     96      UpdateVariableImpact();
     97    }
     98
     99    private void replacementComboBox_SelectedIndexChanged(object sender, EventArgs e) {
     100      UpdateVariableImpact();
     101    }
     102
     103    private void sortByComboBox_SelectedIndexChanged(object sender, EventArgs e) {
     104      //Update the default ordering (asc,desc), but remove the eventHandler beforehand (otherwise the data would be ordered twice)
     105      ascendingCheckBox.CheckedChanged -= ascendingCheckBox_CheckedChanged;
     106      ascendingCheckBox.Checked = (SortingCriteria)sortByComboBox.SelectedItem != SortingCriteria.ImpactValue;
     107      ascendingCheckBox.CheckedChanged += ascendingCheckBox_CheckedChanged;
     108
     109      UpdateOrdering();
     110    }
     111
     112    private void ascendingCheckBox_CheckedChanged(object sender, EventArgs e) {
     113      UpdateOrdering();
     114    }
     115
     116
     117    private async void UpdateVariableImpact() {
     118      IProgress progress;
     119
     120      //Check if the selection is valid
     121      if (Content == null) { return; }
     122      if (replacementComboBox.SelectedIndex < 0) { return; }
     123      if (dataPartitionComboBox.SelectedIndex < 0) { return; }
     124      if (factorVarReplComboBox.SelectedIndex < 0) { return; }
     125
     126      //Prepare arguments
    82127      var mainForm = (MainForm.WindowsForms.MainForm)MainFormManager.MainForm;
     128      var replMethod = (RegressionSolutionVariableImpactsCalculator.ReplacementMethodEnum)replacementComboBox.Items[replacementComboBox.SelectedIndex];
     129      var factorReplMethod = (RegressionSolutionVariableImpactsCalculator.FactorReplacementMethodEnum)factorVarReplComboBox.Items[factorVarReplComboBox.SelectedIndex];
     130      var dataPartition = (RegressionSolutionVariableImpactsCalculator.DataPartitionEnum)dataPartitionComboBox.SelectedItem;
     131
    83132      variableImactsArrayView.Caption = Content.Name + " Variable Impacts";
    84       var replMethod =
    85          (RegressionSolutionVariableImpactsCalculator.ReplacementMethodEnum)
    86            replacementComboBox.Items[replacementComboBox.SelectedIndex];
    87       var factorReplMethod =
    88         (RegressionSolutionVariableImpactsCalculator.FactorReplacementMethodEnum)
    89           factorVarReplComboBox.Items[factorVarReplComboBox.SelectedIndex];
    90       var dataPartition =
    91         (RegressionSolutionVariableImpactsCalculator.DataPartitionEnum)dataPartitionComboBox.SelectedItem;
    92 
    93       Task.Factory.StartNew(() => {
    94         try {
    95           mainForm.AddOperationProgressToView(this, "Calculating variable impacts for " + Content.Name);
    96 
    97           var impacts = RegressionSolutionVariableImpactsCalculator.CalculateImpacts(Content, dataPartition, replMethod, factorReplMethod);
    98           var impactArray = new DoubleArray(impacts.Select(i => i.Item2).ToArray());
    99           impactArray.ElementNames = impacts.Select(i => i.Item1);
    100           variableImactsArrayView.Content = (DoubleArray)impactArray.AsReadOnly();
    101         } finally {
    102           mainForm.RemoveOperationProgressFromView(this);
    103         }
    104       });
    105     }
    106 
    107     #endregion
    108 
    109     private void dataPartitionComboBox_SelectedIndexChanged(object sender, EventArgs e) {
    110       UpdateVariableImpacts();
    111     }
    112 
    113     private void replacementComboBox_SelectedIndexChanged(object sender, EventArgs e) {
    114       UpdateVariableImpacts();
     133      progress = mainForm.AddOperationProgressToView(this, "Calculating variable impacts for " + Content.Name);
     134      progress.ProgressValue = 0;
     135
     136      cancellationToken = new CancellationTokenSource();
     137      //Remember the original ordering of the variables
     138      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        var problemData = Content.ProblemData;
     148        var inputvariables = new HashSet<string>(problemData.AllowedInputVariables.Union(Content.Model.VariablesUsedForPrediction));
     149        var originalVariableOrdering = problemData.Dataset.VariableNames
     150          .Where(v => inputvariables.Contains(v))
     151          .Where(v => problemData.Dataset.VariableHasType<double>(v) || problemData.Dataset.VariableHasType<string>(v))
     152          .ToList();
     153
     154        rawVariableImpacts.Clear();
     155        originalVariableOrdering.ForEach(v => rawVariableImpacts.Add(new Tuple<string, double>(v, impacts.First(vv => vv.Item1 == v).Item2)));
     156        UpdateOrdering();
     157      } finally {
     158        ((MainForm.WindowsForms.MainForm)MainFormManager.MainForm).RemoveOperationProgressFromView(this);
     159      }
     160    }
     161
     162    /// <summary>
     163    /// Updates the <see cref="variableImactsArrayView"/> according to the selected ordering <see cref="ascendingCheckBox"/> of the selected Column <see cref="sortByComboBox"/>
     164    /// The default is "Descending" by "VariableImpact" (as in previous versions)
     165    /// </summary>
     166    private void UpdateOrdering() {
     167      //Check if valid sortingCriteria is selected and data exists
     168      if (sortByComboBox.SelectedIndex == -1) { return; }
     169      if (rawVariableImpacts == null) { return; }
     170      if (!rawVariableImpacts.Any()) { return; }
     171
     172      var selectedItem = (SortingCriteria)sortByComboBox.SelectedItem;
     173      bool ascending = ascendingCheckBox.Checked;
     174
     175      IEnumerable<Tuple<string, double>> orderedEntries = null;
     176
     177      //Sort accordingly
     178      switch (selectedItem) {
     179        case SortingCriteria.ImpactValue:
     180          orderedEntries = rawVariableImpacts.OrderBy(v => v.Item2);
     181          break;
     182        case SortingCriteria.Occurrence:
     183          orderedEntries = rawVariableImpacts;
     184          break;
     185        case SortingCriteria.VariableName:
     186          orderedEntries = rawVariableImpacts.OrderBy(v => v.Item1, new NaturalStringComparer());
     187          break;
     188        default:
     189          throw new NotImplementedException("Ordering for selected SortingCriteria not implemented");
     190      }
     191
     192      if (!ascending) { orderedEntries = orderedEntries.Reverse(); }
     193
     194      //Write the data back
     195      var impactArray = new DoubleArray(orderedEntries.Select(i => i.Item2).ToArray()) {
     196        ElementNames = orderedEntries.Select(i => i.Item1)
     197      };
     198
     199      //Could be, if the View was closed
     200      if (!variableImactsArrayView.IsDisposed) {
     201        variableImactsArrayView.Content = (DoubleArray)impactArray.AsReadOnly();
     202      }
    115203    }
    116204  }
  • stable/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionSolutionVariableImpactsCalculator.cs

    r15584 r16435  
    9696      DataPartitionEnum data = DataPartitionEnum.Training,
    9797      ReplacementMethodEnum replacementMethod = ReplacementMethodEnum.Median,
    98       FactorReplacementMethodEnum factorReplacementMethod = FactorReplacementMethodEnum.Best) {
     98      FactorReplacementMethodEnum factorReplacementMethod = FactorReplacementMethodEnum.Best,
     99      Func<double, string, bool> progressCallback = null) {
    99100
    100101      var problemData = solution.ProblemData;
     
    134135      var allowedInputVariables = dataset.VariableNames.Where(v => inputvariables.Contains(v)).ToList();
    135136
     137      int curIdx = 0;
     138      int count = allowedInputVariables.Where(problemData.Dataset.VariableHasType<double>).Count();
    136139      // calculate impacts for double variables
    137140      foreach (var inputVariable in allowedInputVariables.Where(problemData.Dataset.VariableHasType<double>)) {
     141        //Report the current progress in percent. If the callback returns true, it means the execution shall be stopped
     142        if (progressCallback != null) {
     143          curIdx++;
     144          if (progressCallback((double)curIdx / count, string.Format("Calculating impact for variable {0} ({1} of {2})", inputVariable, curIdx, count))) { return null; }
     145        }
    138146        var newEstimates = EvaluateModelWithReplacedVariable(solution.Model, inputVariable, modifiableDataset, rows, replacementMethod);
    139147        var newR2 = OnlinePearsonsRCalculator.Calculate(targetValues, newEstimates, out error);
     
    180188    }
    181189
     190
    182191    private static IEnumerable<double> EvaluateModelWithReplacedVariable(IRegressionModel model, string variable, ModifiableDataset dataset, IEnumerable<int> rows, ReplacementMethodEnum replacement = ReplacementMethodEnum.Median) {
    183192      var originalValues = dataset.GetReadOnlyDoubleValues(variable).ToList();
  • stable/HeuristicLab.Tests

  • stable/HeuristicLab.Tests/HeuristicLab.Tests.csproj

    r15984 r16435  
    586586    <Compile Include="HeuristicLab.Problems.DataAnalysis-3.4\OnlineCalculatorPerformanceTest.cs" />
    587587    <Compile Include="HeuristicLab.Problems.DataAnalysis-3.4\StatisticCalculatorsTest.cs" />
     588    <Compile Include="HeuristicLab.Problems.DataAnalysis-3.4\VariableImpactCalculationTest.cs" />
    588589    <Compile Include="HeuristicLab.Problems.DataAnalysis.Symbolic-3.4\InfixExpressionParserTest.cs" />
    589590    <Compile Include="HeuristicLab.Problems.DataAnalysis.Symbolic-3.4\SymbolicExpressionTreeBottomUpSimilarityCalculatorTest.cs" />
Note: See TracChangeset for help on using the changeset viewer.