Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/21/18 14:05:46 (5 years ago)
Author:
pfleck
Message:

#2965 Merged recent trunk changes.
Enabled the prepared hooks that allows to cancel the save file using the recently introduced cancelable progressbars (in FileManager).

Location:
branches/2965_CancelablePersistence
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • branches/2965_CancelablePersistence

  • branches/2965_CancelablePersistence/HeuristicLab.Problems.DataAnalysis.Views

  • branches/2965_CancelablePersistence/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/ClassificationSolutionVariableImpactsView.Designer.cs

    r15753 r16433  
    1919 */
    2020#endregion
     21
     22
    2123namespace HeuristicLab.Problems.DataAnalysis.Views {
    2224  partial class ClassificationSolutionVariableImpactsView {
     
    4446    /// </summary>
    4547    private void InitializeComponent() {
    46       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();
    5348      this.ascendingCheckBox = new System.Windows.Forms.CheckBox();
    5449      this.sortByLabel = new System.Windows.Forms.Label();
    5550      this.sortByComboBox = new System.Windows.Forms.ComboBox();
    56       this.backgroundWorker = new System.ComponentModel.BackgroundWorker();
     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();
     57      this.variableImpactsArrayView = new HeuristicLab.Data.Views.StringConvertibleArrayView();
    5758      this.SuspendLayout();
    5859      //
    59       // variableImactsArrayView
    60       //
    61       this.variableImactsArrayView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    62             | System.Windows.Forms.AnchorStyles.Left)
    63             | System.Windows.Forms.AnchorStyles.Right)));
    64       this.variableImactsArrayView.Caption = "StringConvertibleArray View";
    65       this.variableImactsArrayView.Content = null;
    66       this.variableImactsArrayView.Location = new System.Drawing.Point(3, 84);
    67       this.variableImactsArrayView.Name = "variableImactsArrayView";
    68       this.variableImactsArrayView.ReadOnly = true;
    69       this.variableImactsArrayView.Size = new System.Drawing.Size(662, 278);
    70       this.variableImactsArrayView.TabIndex = 2;
    71       //
    72       // dataPartitionComboBox
    73       //
    74       this.dataPartitionComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
    75       this.dataPartitionComboBox.FormattingEnabled = true;
    76       this.dataPartitionComboBox.Items.AddRange(new object[] {
    77             HeuristicLab.Problems.DataAnalysis.ClassificationSolutionVariableImpactsCalculator.DataPartitionEnum.Training,
    78             HeuristicLab.Problems.DataAnalysis.ClassificationSolutionVariableImpactsCalculator.DataPartitionEnum.Test,
    79             HeuristicLab.Problems.DataAnalysis.ClassificationSolutionVariableImpactsCalculator.DataPartitionEnum.All});
    80       this.dataPartitionComboBox.Location = new System.Drawing.Point(197, 3);
    81       this.dataPartitionComboBox.Name = "dataPartitionComboBox";
    82       this.dataPartitionComboBox.Size = new System.Drawing.Size(121, 21);
    83       this.dataPartitionComboBox.TabIndex = 1;
    84       this.dataPartitionComboBox.SelectedIndexChanged += new System.EventHandler(this.dataPartitionComboBox_SelectedIndexChanged);
    85       //
    86       // dataPartitionLabel
    87       //
    88       this.dataPartitionLabel.AutoSize = true;
    89       this.dataPartitionLabel.Location = new System.Drawing.Point(3, 6);
    90       this.dataPartitionLabel.Name = "dataPartitionLabel";
    91       this.dataPartitionLabel.Size = new System.Drawing.Size(73, 13);
    92       this.dataPartitionLabel.TabIndex = 0;
    93       this.dataPartitionLabel.Text = "Data partition:";
    94       //
    95       // numericVarReplacementLabel
    96       //
    97       this.numericVarReplacementLabel.AutoSize = true;
    98       this.numericVarReplacementLabel.Location = new System.Drawing.Point(3, 33);
    99       this.numericVarReplacementLabel.Name = "numericVarReplacementLabel";
    100       this.numericVarReplacementLabel.Size = new System.Drawing.Size(173, 13);
    101       this.numericVarReplacementLabel.TabIndex = 2;
    102       this.numericVarReplacementLabel.Text = "Replacement for numeric variables:";
     60      // ascendingCheckBox
     61      //
     62      this.ascendingCheckBox.AutoSize = true;
     63      this.ascendingCheckBox.CheckAlign = System.Drawing.ContentAlignment.MiddleRight;
     64      this.ascendingCheckBox.Location = new System.Drawing.Point(452, 32);
     65      this.ascendingCheckBox.Name = "ascendingCheckBox";
     66      this.ascendingCheckBox.Size = new System.Drawing.Size(76, 17);
     67      this.ascendingCheckBox.TabIndex = 7;
     68      this.ascendingCheckBox.Text = "Ascending";
     69      this.ascendingCheckBox.UseVisualStyleBackColor = true;
     70      this.ascendingCheckBox.CheckedChanged += new System.EventHandler(this.ascendingCheckBox_CheckedChanged);
     71      //
     72      // sortByLabel
     73      //
     74      this.sortByLabel.AutoSize = true;
     75      this.sortByLabel.Location = new System.Drawing.Point(324, 6);
     76      this.sortByLabel.Name = "sortByLabel";
     77      this.sortByLabel.Size = new System.Drawing.Size(77, 13);
     78      this.sortByLabel.TabIndex = 4;
     79      this.sortByLabel.Text = "Sorting criteria:";
     80      //
     81      // sortByComboBox
     82      //
     83      this.sortByComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
     84      this.sortByComboBox.FormattingEnabled = true;
     85      this.sortByComboBox.Items.AddRange(new object[] {
     86            HeuristicLab.Problems.DataAnalysis.Views.ClassificationSolutionVariableImpactsView.SortingCriteria.ImpactValue,
     87            HeuristicLab.Problems.DataAnalysis.Views.ClassificationSolutionVariableImpactsView.SortingCriteria.Occurrence,
     88            HeuristicLab.Problems.DataAnalysis.Views.ClassificationSolutionVariableImpactsView.SortingCriteria.VariableName});
     89      this.sortByComboBox.Location = new System.Drawing.Point(407, 3);
     90      this.sortByComboBox.Name = "sortByComboBox";
     91      this.sortByComboBox.Size = new System.Drawing.Size(121, 21);
     92      this.sortByComboBox.TabIndex = 5;
     93      this.sortByComboBox.SelectedIndexChanged += new System.EventHandler(this.sortByComboBox_SelectedIndexChanged);
     94      //
     95      // factorVarReplComboBox
     96      //
     97      this.factorVarReplComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
     98      this.factorVarReplComboBox.FormattingEnabled = true;
     99      this.factorVarReplComboBox.Items.AddRange(new object[] {
     100            HeuristicLab.Problems.DataAnalysis.ClassificationSolutionVariableImpactsCalculator.FactorReplacementMethodEnum.Best,
     101            HeuristicLab.Problems.DataAnalysis.ClassificationSolutionVariableImpactsCalculator.FactorReplacementMethodEnum.Mode,
     102            HeuristicLab.Problems.DataAnalysis.ClassificationSolutionVariableImpactsCalculator.FactorReplacementMethodEnum.Shuffle});
     103      this.factorVarReplComboBox.Location = new System.Drawing.Point(197, 57);
     104      this.factorVarReplComboBox.Name = "factorVarReplComboBox";
     105      this.factorVarReplComboBox.Size = new System.Drawing.Size(121, 21);
     106      this.factorVarReplComboBox.TabIndex = 1;
     107      this.factorVarReplComboBox.SelectedIndexChanged += new System.EventHandler(this.replacementComboBox_SelectedIndexChanged);
     108      //
     109      // factorVarReplacementLabel
     110      //
     111      this.factorVarReplacementLabel.AutoSize = true;
     112      this.factorVarReplacementLabel.Location = new System.Drawing.Point(3, 60);
     113      this.factorVarReplacementLabel.Name = "factorVarReplacementLabel";
     114      this.factorVarReplacementLabel.Size = new System.Drawing.Size(188, 13);
     115      this.factorVarReplacementLabel.TabIndex = 0;
     116      this.factorVarReplacementLabel.Text = "Replacement for categorical variables:";
    103117      //
    104118      // replacementComboBox
     
    117131      this.replacementComboBox.SelectedIndexChanged += new System.EventHandler(this.replacementComboBox_SelectedIndexChanged);
    118132      //
    119       // factorVarReplacementLabel
    120       //
    121       this.factorVarReplacementLabel.AutoSize = true;
    122       this.factorVarReplacementLabel.Location = new System.Drawing.Point(3, 60);
    123       this.factorVarReplacementLabel.Name = "factorVarReplacementLabel";
    124       this.factorVarReplacementLabel.Size = new System.Drawing.Size(188, 13);
    125       this.factorVarReplacementLabel.TabIndex = 0;
    126       this.factorVarReplacementLabel.Text = "Replacement for categorical variables:";
    127       //
    128       // factorVarReplComboBox
    129       //
    130       this.factorVarReplComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
    131       this.factorVarReplComboBox.FormattingEnabled = true;
    132       this.factorVarReplComboBox.Items.AddRange(new object[] {
    133             HeuristicLab.Problems.DataAnalysis.ClassificationSolutionVariableImpactsCalculator.FactorReplacementMethodEnum.Best,
    134             HeuristicLab.Problems.DataAnalysis.ClassificationSolutionVariableImpactsCalculator.FactorReplacementMethodEnum.Mode,
    135             HeuristicLab.Problems.DataAnalysis.ClassificationSolutionVariableImpactsCalculator.FactorReplacementMethodEnum.Shuffle});
    136       this.factorVarReplComboBox.Location = new System.Drawing.Point(197, 57);
    137       this.factorVarReplComboBox.Name = "factorVarReplComboBox";
    138       this.factorVarReplComboBox.Size = new System.Drawing.Size(121, 21);
    139       this.factorVarReplComboBox.TabIndex = 1;
    140       this.factorVarReplComboBox.SelectedIndexChanged += new System.EventHandler(this.replacementComboBox_SelectedIndexChanged);
    141       //
    142       // ascendingCheckBox
    143       //
    144       this.ascendingCheckBox.AutoSize = true;
    145       this.ascendingCheckBox.Location = new System.Drawing.Point(534, 6);
    146       this.ascendingCheckBox.Name = "ascendingCheckBox";
    147       this.ascendingCheckBox.Size = new System.Drawing.Size(76, 17);
    148       this.ascendingCheckBox.TabIndex = 10;
    149       this.ascendingCheckBox.Text = "Ascending";
    150       this.ascendingCheckBox.UseVisualStyleBackColor = true;
    151       this.ascendingCheckBox.CheckedChanged += new System.EventHandler(this.ascendingCheckBox_CheckedChanged);
    152       //
    153       // sortByLabel
    154       //
    155       this.sortByLabel.AutoSize = true;
    156       this.sortByLabel.Location = new System.Drawing.Point(324, 6);
    157       this.sortByLabel.Name = "sortByLabel";
    158       this.sortByLabel.Size = new System.Drawing.Size(77, 13);
    159       this.sortByLabel.TabIndex = 8;
    160       this.sortByLabel.Text = "Sorting criteria:";
    161       //
    162       // sortByComboBox
    163       //
    164       this.sortByComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
    165       this.sortByComboBox.FormattingEnabled = true;
    166       this.sortByComboBox.Location = new System.Drawing.Point(407, 3);
    167       this.sortByComboBox.Name = "sortByComboBox";
    168       this.sortByComboBox.Size = new System.Drawing.Size(121, 21);
    169       this.sortByComboBox.TabIndex = 9;
    170       this.sortByComboBox.SelectedIndexChanged += new System.EventHandler(this.sortByComboBox_SelectedIndexChanged);
     133      // numericVarReplacementLabel
     134      //
     135      this.numericVarReplacementLabel.AutoSize = true;
     136      this.numericVarReplacementLabel.Location = new System.Drawing.Point(3, 33);
     137      this.numericVarReplacementLabel.Name = "numericVarReplacementLabel";
     138      this.numericVarReplacementLabel.Size = new System.Drawing.Size(173, 13);
     139      this.numericVarReplacementLabel.TabIndex = 2;
     140      this.numericVarReplacementLabel.Text = "Replacement for numeric variables:";
     141      //
     142      // dataPartitionLabel
     143      //
     144      this.dataPartitionLabel.AutoSize = true;
     145      this.dataPartitionLabel.Location = new System.Drawing.Point(3, 6);
     146      this.dataPartitionLabel.Name = "dataPartitionLabel";
     147      this.dataPartitionLabel.Size = new System.Drawing.Size(73, 13);
     148      this.dataPartitionLabel.TabIndex = 0;
     149      this.dataPartitionLabel.Text = "Data partition:";
     150      //
     151      // dataPartitionComboBox
     152      //
     153      this.dataPartitionComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
     154      this.dataPartitionComboBox.FormattingEnabled = true;
     155      this.dataPartitionComboBox.Items.AddRange(new object[] {
     156            HeuristicLab.Problems.DataAnalysis.ClassificationSolutionVariableImpactsCalculator.DataPartitionEnum.Training,
     157            HeuristicLab.Problems.DataAnalysis.ClassificationSolutionVariableImpactsCalculator.DataPartitionEnum.Test,
     158            HeuristicLab.Problems.DataAnalysis.ClassificationSolutionVariableImpactsCalculator.DataPartitionEnum.All});
     159      this.dataPartitionComboBox.Location = new System.Drawing.Point(197, 3);
     160      this.dataPartitionComboBox.Name = "dataPartitionComboBox";
     161      this.dataPartitionComboBox.Size = new System.Drawing.Size(121, 21);
     162      this.dataPartitionComboBox.TabIndex = 1;
     163      this.dataPartitionComboBox.SelectedIndexChanged += new System.EventHandler(this.dataPartitionComboBox_SelectedIndexChanged);
     164      //
     165      // variableImpactsArrayView
     166      //
     167      this.variableImpactsArrayView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     168            | System.Windows.Forms.AnchorStyles.Left)
     169            | System.Windows.Forms.AnchorStyles.Right)));
     170      this.variableImpactsArrayView.Caption = "StringConvertibleArray View";
     171      this.variableImpactsArrayView.Content = null;
     172      this.variableImpactsArrayView.Location = new System.Drawing.Point(3, 84);
     173      this.variableImpactsArrayView.Name = "variableImpactsArrayView";
     174      this.variableImpactsArrayView.ReadOnly = true;
     175      this.variableImpactsArrayView.Size = new System.Drawing.Size(706, 278);
     176      this.variableImpactsArrayView.TabIndex = 2;
    171177      //
    172178      // ClassificationSolutionVariableImpactsView
     
    183189      this.Controls.Add(this.dataPartitionLabel);
    184190      this.Controls.Add(this.dataPartitionComboBox);
    185       this.Controls.Add(this.variableImactsArrayView);
     191      this.Controls.Add(this.variableImpactsArrayView);
    186192      this.Name = "ClassificationSolutionVariableImpactsView";
    187       this.Size = new System.Drawing.Size(668, 365);
     193      this.Size = new System.Drawing.Size(712, 365);
    188194      this.VisibleChanged += new System.EventHandler(this.ClassificationSolutionVariableImpactsView_VisibleChanged);
    189195      this.ResumeLayout(false);
     
    194200    #endregion
    195201
    196     private Data.Views.StringConvertibleArrayView variableImactsArrayView;
     202    private Data.Views.StringConvertibleArrayView variableImpactsArrayView;
    197203    private System.Windows.Forms.ComboBox dataPartitionComboBox;
    198204    private System.Windows.Forms.Label dataPartitionLabel;
     
    201207    private System.Windows.Forms.Label factorVarReplacementLabel;
    202208    private System.Windows.Forms.ComboBox factorVarReplComboBox;
    203     private System.Windows.Forms.CheckBox ascendingCheckBox;
    204209    private System.Windows.Forms.Label sortByLabel;
    205210    private System.Windows.Forms.ComboBox sortByComboBox;
    206     private System.ComponentModel.BackgroundWorker backgroundWorker;
     211    private System.Windows.Forms.CheckBox ascendingCheckBox;
    207212  }
    208213}
  • branches/2965_CancelablePersistence/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/ClassificationSolutionVariableImpactsView.cs

    r16232 r16433  
    3333  [Content(typeof(IClassificationSolution))]
    3434  public partial class ClassificationSolutionVariableImpactsView : DataAnalysisSolutionEvaluationView {
    35     #region Nested Types
    3635    private enum SortingCriteria {
    3736      ImpactValue,
     
    3938      VariableName
    4039    }
    41     #endregion
    42 
    43     #region Fields
    44     private Dictionary<string, double> rawVariableImpacts = new Dictionary<string, double>();
    45     private Thread thread;
    46     #endregion
    47 
    48     #region Getter/Setter
     40    private CancellationTokenSource cancellationToken = new CancellationTokenSource();
     41    private List<Tuple<string, double>> rawVariableImpacts = new List<Tuple<string, double>>();
     42
    4943    public new IClassificationSolution Content {
    5044      get { return (IClassificationSolution)base.Content; }
     
    5347      }
    5448    }
    55     #endregion
    56 
    57     #region Ctor
     49
    5850    public ClassificationSolutionVariableImpactsView()
    5951      : base() {
    6052      InitializeComponent();
    6153
    62       this.sortByComboBox.Items.AddRange(Enum.GetValues(typeof(SortingCriteria)).Cast<object>().ToArray());
    63       this.sortByComboBox.SelectedItem = SortingCriteria.ImpactValue;
    64 
    6554      //Set the default values
    6655      this.dataPartitionComboBox.SelectedIndex = 0;
    67       this.replacementComboBox.SelectedIndex = 0;
     56      this.replacementComboBox.SelectedIndex = 3;
    6857      this.factorVarReplComboBox.SelectedIndex = 0;
    69     }
    70     #endregion
    71 
    72     #region Events
     58      this.sortByComboBox.SelectedItem = SortingCriteria.ImpactValue;
     59    }
     60
    7361    protected override void RegisterContentEvents() {
    7462      base.RegisterContentEvents();
     
    7664      Content.ProblemDataChanged += new EventHandler(Content_ProblemDataChanged);
    7765    }
    78 
    7966    protected override void DeregisterContentEvents() {
    8067      base.DeregisterContentEvents();
     
    8673      OnContentChanged();
    8774    }
    88 
    8975    protected virtual void Content_ModelChanged(object sender, EventArgs e) {
    9076      OnContentChanged();
    9177    }
    92 
    9378    protected override void OnContentChanged() {
    9479      base.OnContentChanged();
     80      rawVariableImpacts.Clear();
     81
    9582      if (Content == null) {
    96         variableImactsArrayView.Content = null;
     83        variableImpactsArrayView.Content = null;
    9784      } else {
    9885        UpdateVariableImpact();
    9986      }
    10087    }
    101 
    10288    private void ClassificationSolutionVariableImpactsView_VisibleChanged(object sender, EventArgs e) {
    103       if (thread == null) { return; }
    104 
    105       if (thread.IsAlive) { thread.Abort(); }
    106       thread = null;
    107     }
    108 
     89      cancellationToken.Cancel();
     90    }
    10991
    11092    private void dataPartitionComboBox_SelectedIndexChanged(object sender, EventArgs e) {
     93      rawVariableImpacts.Clear();
    11194      UpdateVariableImpact();
    11295    }
    113 
    11496    private void replacementComboBox_SelectedIndexChanged(object sender, EventArgs e) {
     97      rawVariableImpacts.Clear();
    11598      UpdateVariableImpact();
    11699    }
    117 
    118100    private void sortByComboBox_SelectedIndexChanged(object sender, EventArgs e) {
    119101      //Update the default ordering (asc,desc), but remove the eventHandler beforehand (otherwise the data would be ordered twice)
    120102      ascendingCheckBox.CheckedChanged -= ascendingCheckBox_CheckedChanged;
    121       switch ((SortingCriteria)sortByComboBox.SelectedItem) {
    122         case SortingCriteria.ImpactValue:
    123           ascendingCheckBox.Checked = false;
    124           break;
    125         case SortingCriteria.Occurrence:
    126           ascendingCheckBox.Checked = true;
    127           break;
    128         case SortingCriteria.VariableName:
    129           ascendingCheckBox.Checked = true;
    130           break;
    131         default:
    132           throw new NotImplementedException("Ordering for selected SortingCriteria not implemented");
    133       }
     103      ascendingCheckBox.Checked = (SortingCriteria)sortByComboBox.SelectedItem != SortingCriteria.ImpactValue;
    134104      ascendingCheckBox.CheckedChanged += ascendingCheckBox_CheckedChanged;
    135105
    136       UpdateDataOrdering();
    137     }
    138 
     106      UpdateOrdering();
     107    }
    139108    private void ascendingCheckBox_CheckedChanged(object sender, EventArgs e) {
    140       UpdateDataOrdering();
    141     }
    142 
    143     #endregion
    144 
    145     #region Helper Methods   
    146     private void UpdateVariableImpact() {
     109      UpdateOrdering();
     110    }
     111
     112    private async void UpdateVariableImpact() {
     113      IProgress progress;
     114
    147115      //Check if the selection is valid
    148116      if (Content == null) { return; }
     
    152120
    153121      //Prepare arguments
    154       var mainForm = (MainForm.WindowsForms.MainForm)MainFormManager.MainForm;
    155122      var replMethod = (ClassificationSolutionVariableImpactsCalculator.ReplacementMethodEnum)replacementComboBox.Items[replacementComboBox.SelectedIndex];
    156123      var factorReplMethod = (ClassificationSolutionVariableImpactsCalculator.FactorReplacementMethodEnum)factorVarReplComboBox.Items[factorVarReplComboBox.SelectedIndex];
    157124      var dataPartition = (ClassificationSolutionVariableImpactsCalculator.DataPartitionEnum)dataPartitionComboBox.SelectedItem;
    158125
    159       variableImactsArrayView.Caption = Content.Name + " Variable Impacts";
    160 
    161       mainForm.AddOperationProgressToView(this, "Calculating variable impacts for " + Content.Name);
    162 
    163       Task.Factory.StartNew(() => {
    164         thread = Thread.CurrentThread;
    165         //Remember the original ordering of the variables
    166         var impacts = ClassificationSolutionVariableImpactsCalculator.CalculateImpacts(Content, dataPartition, replMethod, factorReplMethod);
     126      variableImpactsArrayView.Caption = Content.Name + " Variable Impacts";
     127      progress = Progress.Show(this, "Calculating variable impacts for " + Content.Name);
     128      cancellationToken = new CancellationTokenSource();
     129
     130      try {
    167131        var problemData = Content.ProblemData;
    168132        var inputvariables = new HashSet<string>(problemData.AllowedInputVariables.Union(Content.Model.VariablesUsedForPrediction));
    169         var originalVariableOrdering = problemData.Dataset.VariableNames.Where(v => inputvariables.Contains(v)).Where(problemData.Dataset.VariableHasType<double>).ToList();
    170 
    171         rawVariableImpacts.Clear();
    172         originalVariableOrdering.ForEach(v => rawVariableImpacts.Add(v, impacts.First(vv => vv.Item1 == v).Item2));
    173       }).ContinueWith((o) => {
    174         UpdateDataOrdering();
    175         mainForm.RemoveOperationProgressFromView(this);
    176         thread = null;
    177       }, TaskScheduler.FromCurrentSynchronizationContext());
     133        //Remember the original ordering of the variables
     134        var originalVariableOrdering = problemData.Dataset.VariableNames
     135          .Where(v => inputvariables.Contains(v))
     136          .Where(v => problemData.Dataset.VariableHasType<double>(v) || problemData.Dataset.VariableHasType<string>(v))
     137          .ToList();
     138
     139        List<Tuple<string, double>> impacts = null;
     140        await Task.Run(() => { impacts = CalculateVariableImpacts(originalVariableOrdering, Content.Model, problemData, Content.EstimatedClassValues, dataPartition, replMethod, factorReplMethod, cancellationToken.Token, progress); });
     141        if (impacts == null) { return; }
     142
     143        rawVariableImpacts.AddRange(impacts);
     144        UpdateOrdering();
     145      } finally {
     146        Progress.Hide(this);
     147      }
     148    }
     149    private List<Tuple<string, double>> CalculateVariableImpacts(List<string> originalVariableOrdering,
     150      IClassificationModel model,
     151      IClassificationProblemData problemData,
     152      IEnumerable<double> estimatedClassValues,
     153      ClassificationSolutionVariableImpactsCalculator.DataPartitionEnum dataPartition,
     154      ClassificationSolutionVariableImpactsCalculator.ReplacementMethodEnum replMethod,
     155      ClassificationSolutionVariableImpactsCalculator.FactorReplacementMethodEnum factorReplMethod,
     156      CancellationToken token,
     157      IProgress progress) {
     158      List<Tuple<string, double>> impacts = new List<Tuple<string, double>>();
     159      int count = originalVariableOrdering.Count;
     160      int i = 0;
     161      var modifiableDataset = ((Dataset)(problemData.Dataset).Clone()).ToModifiable();
     162      IEnumerable<int> rows = ClassificationSolutionVariableImpactsCalculator.GetPartitionRows(dataPartition, problemData);
     163
     164      //Calculate original quality-values (via calculator, default is R²)
     165      IEnumerable<double> targetValuesPartition = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
     166      IEnumerable<double> estimatedClassValuesPartition = Content.GetEstimatedClassValues(rows);
     167
     168      var originalCalculatorValue = ClassificationSolutionVariableImpactsCalculator.CalculateQuality(targetValuesPartition, estimatedClassValuesPartition);
     169      var clonedModel = (IClassificationModel)model.Clone();
     170      foreach (var variableName in originalVariableOrdering) {
     171        if (cancellationToken.Token.IsCancellationRequested) { return null; }
     172        progress.ProgressValue = (double)++i / count;
     173        progress.Message = string.Format("Calculating impact for variable {0} ({1} of {2})", variableName, i, count);
     174
     175        double impact = 0;
     176        //If the variable isn't used for prediction, it has zero impact.
     177        if (model.VariablesUsedForPrediction.Contains(variableName)) {
     178          impact = ClassificationSolutionVariableImpactsCalculator.CalculateImpact(variableName, clonedModel, problemData, modifiableDataset, rows, replMethod, factorReplMethod, targetValuesPartition, originalCalculatorValue);
     179        }
     180        impacts.Add(new Tuple<string, double>(variableName, impact));
     181      }
     182
     183      return impacts;
    178184    }
    179185
    180186    /// <summary>
    181     /// Updates the <see cref="variableImactsArrayView"/> according to the selected ordering <see cref="ascendingCheckBox"/> of the selected Column <see cref="sortByComboBox"/>
     187    /// Updates the <see cref="variableImpactsArrayView"/> according to the selected ordering <see cref="ascendingCheckBox"/> of the selected Column <see cref="sortByComboBox"/>
    182188    /// The default is "Descending" by "VariableImpact" (as in previous versions)
    183189    /// </summary>
    184     private void UpdateDataOrdering() {
     190    private void UpdateOrdering() {
    185191      //Check if valid sortingCriteria is selected and data exists
    186192      if (sortByComboBox.SelectedIndex == -1) { return; }
     
    191197      bool ascending = ascendingCheckBox.Checked;
    192198
    193       IEnumerable<KeyValuePair<string, double>> orderedEntries = null;
     199      IEnumerable<Tuple<string, double>> orderedEntries = null;
    194200
    195201      //Sort accordingly
    196202      switch (selectedItem) {
    197203        case SortingCriteria.ImpactValue:
    198           orderedEntries = rawVariableImpacts.OrderBy(v => v.Value);
     204          orderedEntries = rawVariableImpacts.OrderBy(v => v.Item2);
    199205          break;
    200206        case SortingCriteria.Occurrence:
     
    202208          break;
    203209        case SortingCriteria.VariableName:
    204           orderedEntries = rawVariableImpacts.OrderBy(v => v.Key, new NaturalStringComparer());
     210          orderedEntries = rawVariableImpacts.OrderBy(v => v.Item1, new NaturalStringComparer());
    205211          break;
    206212        default:
     
    211217
    212218      //Write the data back
    213       var impactArray = new DoubleArray(orderedEntries.Select(i => i.Value).ToArray()) {
    214         ElementNames = orderedEntries.Select(i => i.Key)
     219      var impactArray = new DoubleArray(orderedEntries.Select(i => i.Item2).ToArray()) {
     220        ElementNames = orderedEntries.Select(i => i.Item1)
    215221      };
    216222
    217223      //Could be, if the View was closed
    218       if (!variableImactsArrayView.IsDisposed) {
    219         variableImactsArrayView.Content = (DoubleArray)impactArray.AsReadOnly();
    220       }
    221     }
    222     #endregion 
     224      if (!variableImpactsArrayView.IsDisposed) {
     225        variableImpactsArrayView.Content = (DoubleArray)impactArray.AsReadOnly();
     226      }
     227    }
    223228  }
    224229}
  • branches/2965_CancelablePersistence/HeuristicLab.Problems.DataAnalysis.Views/3.4/MenuItems/ShrinkDataAnalysisRunsMenuItem.cs

    r15583 r16433  
    7272    public override void Execute() {
    7373      IContentView activeView = (IContentView)MainFormManager.MainForm.ActiveView;
    74       var mainForm = (MainForm.WindowsForms.MainForm)MainFormManager.MainForm;
    75       mainForm.AddOperationProgressToContent(activeView.Content, "Removing duplicate datasets.");
     74      var content = activeView.Content;
     75      Progress.Show(content, "Removing duplicate datasets.", ProgressMode.Indeterminate);
    7676
    7777      Action<IContentView> action = (view) => DatasetUtil.RemoveDuplicateDatasets(view.Content);
     
    7979      action.BeginInvoke(activeView, delegate (IAsyncResult result) {
    8080        action.EndInvoke(result);
    81         mainForm.RemoveOperationProgressFromContent(activeView.Content);
     81        Progress.Hide(content);
    8282      }, null);
    8383    }
  • branches/2965_CancelablePersistence/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionVariableImpactsView.Designer.cs

    r15999 r16433  
    5555      this.dataPartitionLabel = new System.Windows.Forms.Label();
    5656      this.dataPartitionComboBox = new System.Windows.Forms.ComboBox();
    57       this.variableImactsArrayView = new HeuristicLab.Data.Views.StringConvertibleArrayView();
     57      this.variableImpactsArrayView = new HeuristicLab.Data.Views.StringConvertibleArrayView();
    5858      this.SuspendLayout();
    5959      //
     
    6161      //
    6262      this.ascendingCheckBox.AutoSize = true;
    63       this.ascendingCheckBox.Location = new System.Drawing.Point(534, 6);
     63      this.ascendingCheckBox.CheckAlign = System.Drawing.ContentAlignment.MiddleRight;
     64      this.ascendingCheckBox.Location = new System.Drawing.Point(452, 32);
    6465      this.ascendingCheckBox.Name = "ascendingCheckBox";
    6566      this.ascendingCheckBox.Size = new System.Drawing.Size(76, 17);
     
    162163      this.dataPartitionComboBox.SelectedIndexChanged += new System.EventHandler(this.dataPartitionComboBox_SelectedIndexChanged);
    163164      //
    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)
     165      // variableImpactsArrayView
     166      //
     167      this.variableImpactsArrayView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     168            | System.Windows.Forms.AnchorStyles.Left) 
    168169            | 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;
     170      this.variableImpactsArrayView.Caption = "StringConvertibleArray View";
     171      this.variableImpactsArrayView.Content = null;
     172      this.variableImpactsArrayView.Location = new System.Drawing.Point(3, 84);
     173      this.variableImpactsArrayView.Name = "variableImpactsArrayView";
     174      this.variableImpactsArrayView.ReadOnly = true;
     175      this.variableImpactsArrayView.Size = new System.Drawing.Size(706, 278);
     176      this.variableImpactsArrayView.TabIndex = 2;
    176177      //
    177178      // RegressionSolutionVariableImpactsView
     
    188189      this.Controls.Add(this.dataPartitionLabel);
    189190      this.Controls.Add(this.dataPartitionComboBox);
    190       this.Controls.Add(this.variableImactsArrayView);
     191      this.Controls.Add(this.variableImpactsArrayView);
    191192      this.Name = "RegressionSolutionVariableImpactsView";
    192193      this.Size = new System.Drawing.Size(712, 365);
     
    199200    #endregion
    200201
    201     private Data.Views.StringConvertibleArrayView variableImactsArrayView;
     202    private Data.Views.StringConvertibleArrayView variableImpactsArrayView;
    202203    private System.Windows.Forms.ComboBox dataPartitionComboBox;
    203204    private System.Windows.Forms.Label dataPartitionLabel;
  • branches/2965_CancelablePersistence/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionVariableImpactsView.cs

    r16021 r16433  
    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    }
    115111
    116 
    117112    private async void UpdateVariableImpact() {
    118       IProgress progress;
    119 
    120113      //Check if the selection is valid
    121114      if (Content == null) { return; }
     
    125118
    126119      //Prepare arguments
    127       var mainForm = (MainForm.WindowsForms.MainForm)MainFormManager.MainForm;
    128120      var replMethod = (RegressionSolutionVariableImpactsCalculator.ReplacementMethodEnum)replacementComboBox.Items[replacementComboBox.SelectedIndex];
    129121      var factorReplMethod = (RegressionSolutionVariableImpactsCalculator.FactorReplacementMethodEnum)factorVarReplComboBox.Items[factorVarReplComboBox.SelectedIndex];
    130122      var dataPartition = (RegressionSolutionVariableImpactsCalculator.DataPartitionEnum)dataPartitionComboBox.SelectedItem;
    131123
    132       variableImactsArrayView.Caption = Content.Name + " Variable Impacts";
    133       progress = mainForm.AddOperationProgressToView(this, "Calculating variable impacts for " + Content.Name);
    134       progress.ProgressValue = 0;
    135 
     124      variableImpactsArrayView.Caption = Content.Name + " Variable Impacts";
     125      var progress = Progress.Show(this, "Calculating variable impacts for " + Content.Name);
    136126      cancellationToken = new CancellationTokenSource();
    137       //Remember the original ordering of the variables
     127
    138128      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; }
    147129        var problemData = Content.ProblemData;
    148130        var inputvariables = new HashSet<string>(problemData.AllowedInputVariables.Union(Content.Model.VariablesUsedForPrediction));
     131        //Remember the original ordering of the variables
    149132        var originalVariableOrdering = problemData.Dataset.VariableNames
    150133          .Where(v => inputvariables.Contains(v))
     
    152135          .ToList();
    153136
    154         rawVariableImpacts.Clear();
    155         originalVariableOrdering.ForEach(v => rawVariableImpacts.Add(new Tuple<string, double>(v, impacts.First(vv => vv.Item1 == v).Item2)));
     137        List<Tuple<string, double>> impacts = null;
     138        await Task.Run(() => { impacts = CalculateVariableImpacts(originalVariableOrdering, Content.Model, problemData, Content.EstimatedValues, dataPartition, replMethod, factorReplMethod, cancellationToken.Token, progress); });
     139        if (impacts == null) { return; }
     140
     141        rawVariableImpacts.AddRange(impacts);
    156142        UpdateOrdering();
    157       } finally {
    158         ((MainForm.WindowsForms.MainForm)MainFormManager.MainForm).RemoveOperationProgressFromView(this);
    159       }
     143      }
     144      finally {
     145        Progress.Hide(this);
     146      }
     147    }
     148    private List<Tuple<string, double>> CalculateVariableImpacts(List<string> originalVariableOrdering,
     149      IRegressionModel model,
     150      IRegressionProblemData problemData,
     151      IEnumerable<double> estimatedValues,
     152      RegressionSolutionVariableImpactsCalculator.DataPartitionEnum dataPartition,
     153      RegressionSolutionVariableImpactsCalculator.ReplacementMethodEnum replMethod,
     154      RegressionSolutionVariableImpactsCalculator.FactorReplacementMethodEnum factorReplMethod,
     155      CancellationToken token,
     156      IProgress progress) {
     157      List<Tuple<string, double>> impacts = new List<Tuple<string, double>>();
     158      int count = originalVariableOrdering.Count;
     159      int i = 0;
     160      var modifiableDataset = ((Dataset)(problemData.Dataset).Clone()).ToModifiable();
     161      IEnumerable<int> rows = RegressionSolutionVariableImpactsCalculator.GetPartitionRows(dataPartition, problemData);
     162
     163      //Calculate original quality-values (via calculator, default is R²)
     164      IEnumerable<double> targetValuesPartition = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
     165      IEnumerable<double> estimatedValuesPartition = Content.GetEstimatedValues(rows);
     166
     167      var originalCalculatorValue = RegressionSolutionVariableImpactsCalculator.CalculateQuality(targetValuesPartition, estimatedValuesPartition);
     168
     169      foreach (var variableName in originalVariableOrdering) {
     170        if (cancellationToken.Token.IsCancellationRequested) { return null; }
     171        progress.ProgressValue = (double)++i / count;
     172        progress.Message = string.Format("Calculating impact for variable {0} ({1} of {2})", variableName, i, count);
     173
     174        double impact = 0;
     175        //If the variable isn't used for prediction, it has zero impact.
     176        if (model.VariablesUsedForPrediction.Contains(variableName)) {
     177          impact = RegressionSolutionVariableImpactsCalculator.CalculateImpact(variableName, model, problemData, modifiableDataset, rows, replMethod, factorReplMethod, targetValuesPartition, originalCalculatorValue);
     178        }
     179        impacts.Add(new Tuple<string, double>(variableName, impact));
     180      }
     181
     182      return impacts;
    160183    }
    161184
    162185    /// <summary>
    163     /// Updates the <see cref="variableImactsArrayView"/> according to the selected ordering <see cref="ascendingCheckBox"/> of the selected Column <see cref="sortByComboBox"/>
     186    /// Updates the <see cref="variableImpactsArrayView"/> according to the selected ordering <see cref="ascendingCheckBox"/> of the selected Column <see cref="sortByComboBox"/>
    164187    /// The default is "Descending" by "VariableImpact" (as in previous versions)
    165188    /// </summary>
     
    198221
    199222      //Could be, if the View was closed
    200       if (!variableImactsArrayView.IsDisposed) {
    201         variableImactsArrayView.Content = (DoubleArray)impactArray.AsReadOnly();
     223      if (!variableImpactsArrayView.IsDisposed) {
     224        variableImpactsArrayView.Content = (DoubleArray)impactArray.AsReadOnly();
    202225      }
    203226    }
Note: See TracChangeset for help on using the changeset viewer.