- Timestamp:
- 12/21/18 14:10:11 (6 years ago)
- Location:
- stable
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
/trunk merged: 15727-15728,15752,15796-15799,15802,15998-15999,16015,16021,16023 /trunk/sources merged: 15626,15637,15665,15673
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.DataAnalysis.Views
-
stable/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionVariableImpactsView.Designer.cs
r15584 r16435 19 19 */ 20 20 #endregion 21 22 21 23 namespace HeuristicLab.Problems.DataAnalysis.Views { 22 24 partial class RegressionSolutionVariableImpactsView { … … 44 46 /// </summary> 45 47 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(); 46 57 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();53 58 this.SuspendLayout(); 54 59 // 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:"; 98 116 // 99 117 // replacementComboBox 100 118 // 119 this.replacementComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; 101 120 this.replacementComboBox.FormattingEnabled = true; 102 121 this.replacementComboBox.Items.AddRange(new object[] { … … 111 130 this.replacementComboBox.SelectedIndexChanged += new System.EventHandler(this.replacementComboBox_SelectedIndexChanged); 112 131 // 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; 134 176 // 135 177 // RegressionSolutionVariableImpactsView … … 137 179 this.AllowDrop = true; 138 180 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); 139 184 this.Controls.Add(this.factorVarReplComboBox); 140 185 this.Controls.Add(this.factorVarReplacementLabel); … … 145 190 this.Controls.Add(this.variableImactsArrayView); 146 191 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); 148 194 this.ResumeLayout(false); 149 195 this.PerformLayout(); … … 160 206 private System.Windows.Forms.Label factorVarReplacementLabel; 161 207 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; 162 211 } 163 212 } -
stable/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionVariableImpactsView.cs
r15584 r16435 19 19 */ 20 20 #endregion 21 21 22 using System; 23 using System.Collections.Generic; 22 24 using System.Linq; 25 using System.Threading; 23 26 using System.Threading.Tasks; 27 using HeuristicLab.Common; 24 28 using HeuristicLab.Data; 25 29 using HeuristicLab.MainForm; 26 using HeuristicLab.Problems.DataAnalysis.Symbolic.Regression;27 30 28 31 namespace HeuristicLab.Problems.DataAnalysis.Views { … … 30 33 [Content(typeof(IRegressionSolution))] 31 34 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>>(); 32 42 33 43 public new IRegressionSolution Content { … … 41 51 : base() { 42 52 InitializeComponent(); 53 54 //Set the default values 43 55 this.dataPartitionComboBox.SelectedIndex = 0; 44 this.replacementComboBox.SelectedIndex = 0;56 this.replacementComboBox.SelectedIndex = 3; 45 57 this.factorVarReplComboBox.SelectedIndex = 0; 46 }47 48 #region events 58 this.sortByComboBox.SelectedItem = SortingCriteria.ImpactValue; 59 } 60 49 61 protected override void RegisterContentEvents() { 50 62 base.RegisterContentEvents(); … … 72 84 variableImactsArrayView.Content = null; 73 85 } 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 82 127 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 83 132 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 } 115 203 } 116 204 }
Note: See TracChangeset
for help on using the changeset viewer.