- Timestamp:
- 04/04/17 17:52:44 (8 years ago)
- Location:
- trunk/sources
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources
- Property svn:mergeinfo changed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Views
- Property svn:mergeinfo changed
/branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Views (added) merged: 14240-14241,14248,14251,14277,14330,14351,14421,14449,14497-14499,14542,14591-14592,14762,14825
- Property svn:mergeinfo changed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionTargetResponseGradientView.cs
r14464 r14826 21 21 22 22 using System; 23 using System.Collections; 23 24 using System.Collections.Generic; 24 25 using System.Drawing; … … 35 36 [Content(typeof(IRegressionSolution))] 36 37 public partial class RegressionSolutionTargetResponseGradientView : DataAnalysisSolutionEvaluationView { 37 private readonly Dictionary<string, GradientChart> gradientCharts;38 private readonly Dictionary<string, IGradientChart> gradientCharts; 38 39 private readonly Dictionary<string, DensityChart> densityCharts; 39 40 private readonly Dictionary<string, Panel> groupingPanels; … … 49 50 } 50 51 } 51 private IEnumerable< GradientChart> VisibleGradientCharts {52 private IEnumerable<IGradientChart> VisibleGradientCharts { 52 53 get { return VisibleVariables.Select(v => gradientCharts[v]); } 53 54 } … … 61 62 public RegressionSolutionTargetResponseGradientView() { 62 63 InitializeComponent(); 63 gradientCharts = new Dictionary<string, GradientChart>();64 gradientCharts = new Dictionary<string, IGradientChart>(); 64 65 densityCharts = new Dictionary<string, DensityChart>(); 65 66 groupingPanels = new Dictionary<string, Panel>(); … … 120 121 121 122 122 var variableValues = allowedInputVariables.Select(x => new List<double> { problemData.Dataset.GetDoubleValues(x, problemData.TrainingIndices).Median() }); 123 var doubleVariables = allowedInputVariables.Where(problemData.Dataset.VariableHasType<double>); 124 var doubleVariableValues = (IEnumerable<IList>)doubleVariables.Select(x => new List<double> { problemData.Dataset.GetDoubleValues(x, problemData.TrainingIndices).Median() }); 125 126 var factorVariables = allowedInputVariables.Where(problemData.Dataset.VariableHasType<string>); 127 var factorVariableValues = (IEnumerable<IList>)factorVariables.Select(x => new List<string> { 128 problemData.Dataset.GetStringValues(x, problemData.TrainingIndices) 129 .GroupBy(val => val).OrderByDescending(g => g.Count()).First().Key // most frequent value 130 }); 131 123 132 if (sharedFixedVariables != null) 124 133 sharedFixedVariables.ItemChanged -= SharedFixedVariables_ItemChanged; 125 sharedFixedVariables = new ModifiableDataset(allowedInputVariables, variableValues); 126 // ItemChanged eventhandler is registered later, after creating the gradient charts 134 135 sharedFixedVariables = new ModifiableDataset(doubleVariables.Concat(factorVariables), doubleVariableValues.Concat(factorVariableValues)); 136 127 137 128 138 // create controls … … 130 140 densityCharts.Clear(); 131 141 groupingPanels.Clear(); 132 foreach (var variableName in allowedInputVariables) {142 foreach (var variableName in doubleVariables) { 133 143 var gradientChart = CreateGradientChart(variableName, sharedFixedVariables); 134 144 gradientCharts.Add(variableName, gradientChart); … … 158 168 // Initially, the inner plot areas are not initialized for hidden charts (scollpanel, ...) 159 169 // This event handler listens for the paint event once (where everything is already initialized) to do some manual layouting. 160 gradientChart.ChartPostPaint += OnGradientChart OnChartPostPaint;170 gradientChart.ChartPostPaint += OnGradientChartPostPaint; 161 171 162 172 var panel = new Panel() { … … 170 180 groupingPanels.Add(variableName, panel); 171 181 } 172 182 foreach (var variableName in factorVariables) { 183 var gradientChart = CreateFactorGradientChart(variableName, sharedFixedVariables); 184 gradientCharts.Add(variableName, gradientChart); 185 186 var densityChart = new DensityChart() { 187 Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right, 188 Margin = Padding.Empty, 189 Height = 12, 190 Visible = false, 191 Top = (int)(gradientChart.Height * 0.1), 192 }; 193 densityCharts.Add(variableName, densityChart); 194 gradientChart.ZoomChanged += (o, e) => { 195 var gradient = (FactorGradientChart)o; 196 var density = densityCharts[gradient.FreeVariable]; 197 density.Visible = densityComboBox.SelectedIndex != 0 && !gradient.IsZoomed; 198 if (density.Visible) 199 UpdateDensityChart(density, gradient.FreeVariable); 200 }; 201 gradientChart.SizeChanged += (o, e) => { 202 var gradient = (FactorGradientChart)o; 203 var density = densityCharts[gradient.FreeVariable]; 204 density.Top = (int)(gradient.Height * 0.1); 205 }; 206 207 // Initially, the inner plot areas are not initialized for hidden charts (scollpanel, ...) 208 // This event handler listens for the paint event once (where everything is already initialized) to do some manual layouting. 209 gradientChart.ChartPostPaint += OnFactorGradientChartPostPaint; 210 211 var panel = new Panel() { 212 Dock = DockStyle.Fill, 213 Margin = Padding.Empty, 214 BackColor = Color.White 215 }; 216 217 panel.Controls.Add(densityChart); 218 panel.Controls.Add(gradientChart); 219 groupingPanels.Add(variableName, panel); 220 } 173 221 // update variable list 174 222 variableListView.ItemChecked -= variableListView_ItemChecked; … … 196 244 } 197 245 198 private void OnGradientChartOnChartPostPaint(object o, EventArgs e) { 246 247 private void OnGradientChartPostPaint(object o, EventArgs e) { 199 248 var gradient = (GradientChart)o; 200 249 var density = densityCharts[gradient.FreeVariable]; … … 209 258 // removed after succesful layouting due to performance reasons 210 259 if (gcPlotPosition.Width != 0) 211 gradient.ChartPostPaint -= OnGradientChartOnChartPostPaint; 260 gradient.ChartPostPaint -= OnGradientChartPostPaint; 261 } 262 263 private void OnFactorGradientChartPostPaint(object o, EventArgs e) { 264 var gradient = (FactorGradientChart)o; 265 var density = densityCharts[gradient.FreeVariable]; 266 267 density.Width = gradient.Width; 268 269 var gcPlotPosition = gradient.InnerPlotPosition; 270 density.Left = (int)(gcPlotPosition.X / 100.0 * gradient.Width); 271 density.Width = (int)(gcPlotPosition.Width / 100.0 * gradient.Width); 272 gradient.UpdateTitlePosition(); 273 274 // removed after succesful layouting due to performance reasons 275 if (gcPlotPosition.Width != 0) 276 gradient.ChartPostPaint -= OnFactorGradientChartPostPaint; 212 277 } 213 278 … … 215 280 foreach (var variable in VisibleVariables) { 216 281 var gradientChart = gradientCharts[variable]; 217 await gradientChart.RecalculateAsync( );282 await gradientChart.RecalculateAsync(false, false); 218 283 } 219 284 gradientChartTableLayout.SuspendLayout(); … … 224 289 gradientChartTableLayout.Refresh(); 225 290 foreach (var variable in VisibleVariables) { 226 var densityChart = densityCharts[variable]; 227 UpdateDensityChart(densityChart, variable); 291 DensityChart densityChart; 292 if (densityCharts.TryGetValue(variable, out densityChart)) { 293 UpdateDensityChart(densityChart, variable); 294 } 228 295 } 229 296 } … … 238 305 }; 239 306 gradientChart.VariableValueChanged += async (o, e) => { 240 var recalculations = VisibleGradientCharts.Except(new[] { (GradientChart)o }).Select(async chart => { 241 await chart.RecalculateAsync(updateOnFinish: false, resetYAxis: false); 242 }).ToList(); 307 var recalculations = VisibleGradientCharts 308 .Except(new[] { (IGradientChart)o }) 309 .Select(async chart => { 310 await chart.RecalculateAsync(updateOnFinish: false, resetYAxis: false); 311 }).ToList(); 243 312 await Task.WhenAll(recalculations); 244 313 … … 251 320 return gradientChart; 252 321 } 253 322 private FactorGradientChart CreateFactorGradientChart(string variableName, ModifiableDataset sharedFixedVariables) { 323 var gradientChart = new FactorGradientChart { 324 Dock = DockStyle.Fill, 325 Margin = Padding.Empty, 326 ShowLegend = false, 327 ShowCursor = true, 328 YAxisTicks = 5, 329 }; 330 gradientChart.VariableValueChanged += async (o, e) => { 331 var recalculations = VisibleGradientCharts 332 .Except(new[] { (FactorGradientChart)o }) 333 .Select(async chart => { 334 await chart.RecalculateAsync(updateOnFinish: false, resetYAxis: false); 335 }).ToList(); 336 await Task.WhenAll(recalculations); 337 338 if (recalculations.All(t => t.IsCompleted)) 339 SetupYAxis(); 340 }; 341 var variableValues = Content.ProblemData.Dataset.GetStringValues(variableName).Distinct().OrderBy(n => n).ToList(); 342 gradientChart.Configure(new[] { Content }, sharedFixedVariables, variableName, variableValues); 343 gradientChart.SolutionAdded += gradientChart_SolutionAdded; 344 gradientChart.SolutionRemoved += gradientChart_SolutionRemoved; 345 return gradientChart; 346 } 254 347 private void SetupYAxis() { 255 348 double axisMin, axisMax; … … 345 438 if (item.Checked) { 346 439 tl.Controls.Add(chartsPanel); 347 await gradientChart.RecalculateAsync( );440 await gradientChart.RecalculateAsync(false, false); 348 441 } else { 349 442 tl.Controls.Remove(chartsPanel); … … 409 502 indices = GetDensityIndices(densityComboBox.SelectedIndex).ToList(); 410 503 } 411 var data = Content.ProblemData.Dataset.GetDoubleValues(variable, indices).ToList(); 412 var gradientChart = gradientCharts[variable]; 413 var min = gradientChart.FixedXAxisMin; 414 var max = gradientChart.FixedXAxisMax; 415 var buckets = gradientChart.DrawingSteps; 416 if (min.HasValue && max.HasValue) { 417 densityChart.UpdateChart(data, min.Value, max.Value, buckets); 418 densityChart.Width = gradientChart.Width; 419 420 var gcPlotPosition = gradientChart.InnerPlotPosition; 421 densityChart.Left = (int)(gcPlotPosition.X / 100.0 * gradientChart.Width); 422 densityChart.Width = (int)(gcPlotPosition.Width / 100.0 * gradientChart.Width); 423 424 densityChart.Visible = true; 425 } 426 427 gradientChart.UpdateTitlePosition(); 504 if (Content.ProblemData.Dataset.VariableHasType<double>(variable)) { 505 var data = Content.ProblemData.Dataset.GetDoubleValues(variable, indices).ToList(); 506 var gradientChart = gradientCharts[variable] as GradientChart; 507 if (gradientChart != null) { 508 var min = gradientChart.FixedXAxisMin; 509 var max = gradientChart.FixedXAxisMax; 510 var buckets = gradientChart.DrawingSteps; 511 if (min.HasValue && max.HasValue) { 512 densityChart.UpdateChart(data, min.Value, max.Value, buckets); 513 densityChart.Width = gradientChart.Width; 514 515 var gcPlotPosition = gradientChart.InnerPlotPosition; 516 densityChart.Left = (int)(gcPlotPosition.X / 100.0 * gradientChart.Width); 517 densityChart.Width = (int)(gcPlotPosition.Width / 100.0 * gradientChart.Width); 518 519 densityChart.Visible = true; 520 } 521 gradientChart.UpdateTitlePosition(); 522 } 523 } else if (Content.ProblemData.Dataset.VariableHasType<string>(variable)) { 524 var data = Content.ProblemData.Dataset.GetStringValues(variable).ToList(); 525 var gradientChart = gradientCharts[variable] as FactorGradientChart; 526 if (gradientChart != null) { 527 densityChart.UpdateChart(data); 528 densityChart.Width = gradientChart.Width; 529 530 var gcPlotPosition = gradientChart.InnerPlotPosition; 531 densityChart.Left = (int)(gcPlotPosition.X / 100.0 * gradientChart.Width); 532 densityChart.Width = (int)(gcPlotPosition.Width / 100.0 * gradientChart.Width); 533 534 densityChart.Visible = true; 535 536 gradientChart.UpdateTitlePosition(); 537 } 538 } 428 539 } 429 540 … … 448 559 var densityChart = densityCharts[variable]; 449 560 // recalculate and refresh 450 await gradientChart.RecalculateAsync( );561 await gradientChart.RecalculateAsync(false, false); 451 562 gradientChart.Refresh(); 452 563 UpdateDensityChart(densityChart, variable); -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionVariableImpactsView.Designer.cs
r14348 r14826 47 47 this.dataPartitionComboBox = new System.Windows.Forms.ComboBox(); 48 48 this.dataPartitionLabel = new System.Windows.Forms.Label(); 49 this. replacementLabel = new System.Windows.Forms.Label();49 this.numericVarReplacementLabel = new System.Windows.Forms.Label(); 50 50 this.replacementComboBox = new System.Windows.Forms.ComboBox(); 51 this.factorVarReplacementLabel = new System.Windows.Forms.Label(); 52 this.factorVarReplComboBox = new System.Windows.Forms.ComboBox(); 51 53 this.SuspendLayout(); 52 54 // … … 58 60 this.variableImactsArrayView.Caption = "StringConvertibleArray View"; 59 61 this.variableImactsArrayView.Content = null; 60 this.variableImactsArrayView.Location = new System.Drawing.Point(3, 59);62 this.variableImactsArrayView.Location = new System.Drawing.Point(3, 84); 61 63 this.variableImactsArrayView.Name = "variableImactsArrayView"; 62 64 this.variableImactsArrayView.ReadOnly = true; 63 this.variableImactsArrayView.Size = new System.Drawing.Size(3 04, 223);64 this.variableImactsArrayView.TabIndex = 4;65 this.variableImactsArrayView.Size = new System.Drawing.Size(363, 278); 66 this.variableImactsArrayView.TabIndex = 2; 65 67 // 66 68 // dataPartitionComboBox … … 71 73 HeuristicLab.Problems.DataAnalysis.RegressionSolutionVariableImpactsCalculator.DataPartitionEnum.Test, 72 74 HeuristicLab.Problems.DataAnalysis.RegressionSolutionVariableImpactsCalculator.DataPartitionEnum.All}); 73 this.dataPartitionComboBox.Location = new System.Drawing.Point( 82, 3);75 this.dataPartitionComboBox.Location = new System.Drawing.Point(197, 3); 74 76 this.dataPartitionComboBox.Name = "dataPartitionComboBox"; 75 77 this.dataPartitionComboBox.Size = new System.Drawing.Size(121, 21); … … 86 88 this.dataPartitionLabel.Text = "Data partition:"; 87 89 // 88 // replacementLabel90 // numericVarReplacementLabel 89 91 // 90 this. replacementLabel.AutoSize = true;91 this. replacementLabel.Location = new System.Drawing.Point(3, 35);92 this. replacementLabel.Name = "replacementLabel";93 this. replacementLabel.Size = new System.Drawing.Size(73, 13);94 this. replacementLabel.TabIndex = 2;95 this. replacementLabel.Text = "Replacement:";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:"; 96 98 // 97 99 // replacementComboBox … … 103 105 HeuristicLab.Problems.DataAnalysis.RegressionSolutionVariableImpactsCalculator.ReplacementMethodEnum.Noise, 104 106 HeuristicLab.Problems.DataAnalysis.RegressionSolutionVariableImpactsCalculator.ReplacementMethodEnum.Shuffle}); 105 this.replacementComboBox.Location = new System.Drawing.Point( 82, 32);107 this.replacementComboBox.Location = new System.Drawing.Point(197, 30); 106 108 this.replacementComboBox.Name = "replacementComboBox"; 107 109 this.replacementComboBox.Size = new System.Drawing.Size(121, 21); … … 109 111 this.replacementComboBox.SelectedIndexChanged += new System.EventHandler(this.replacementComboBox_SelectedIndexChanged); 110 112 // 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); 134 // 111 135 // RegressionSolutionVariableImpactsView 112 136 // 113 137 this.AllowDrop = true; 114 138 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit; 139 this.Controls.Add(this.factorVarReplComboBox); 140 this.Controls.Add(this.factorVarReplacementLabel); 115 141 this.Controls.Add(this.replacementComboBox); 116 this.Controls.Add(this. replacementLabel);142 this.Controls.Add(this.numericVarReplacementLabel); 117 143 this.Controls.Add(this.dataPartitionLabel); 118 144 this.Controls.Add(this.dataPartitionComboBox); 119 145 this.Controls.Add(this.variableImactsArrayView); 120 146 this.Name = "RegressionSolutionVariableImpactsView"; 121 this.Size = new System.Drawing.Size(3 10, 285);147 this.Size = new System.Drawing.Size(369, 365); 122 148 this.ResumeLayout(false); 123 149 this.PerformLayout(); … … 130 156 private System.Windows.Forms.ComboBox dataPartitionComboBox; 131 157 private System.Windows.Forms.Label dataPartitionLabel; 132 private System.Windows.Forms.Label replacementLabel;158 private System.Windows.Forms.Label numericVarReplacementLabel; 133 159 private System.Windows.Forms.ComboBox replacementComboBox; 160 private System.Windows.Forms.Label factorVarReplacementLabel; 161 private System.Windows.Forms.ComboBox factorVarReplComboBox; 134 162 } 135 163 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionVariableImpactsView.cs
r14348 r14826 43 43 this.dataPartitionComboBox.SelectedIndex = 0; 44 44 this.replacementComboBox.SelectedIndex = 0; 45 this.factorVarReplComboBox.SelectedIndex = 0; 45 46 } 46 47 … … 76 77 77 78 private void UpdateVariableImpacts() { 78 if (Content == null || replacementComboBox.SelectedIndex < 0 || dataPartitionComboBox.SelectedIndex < 0) return; 79 if (Content == null || replacementComboBox.SelectedIndex < 0 80 || factorVarReplComboBox.SelectedIndex < 0 81 || dataPartitionComboBox.SelectedIndex < 0) return; 79 82 var mainForm = (MainForm.WindowsForms.MainForm)MainFormManager.MainForm; 80 83 variableImactsArrayView.Caption = Content.Name + " Variable Impacts"; 81 84 var replMethod = 82 (RegressionSolutionVariableImpactsCalculator.ReplacementMethodEnum)replacementComboBox.Items[replacementComboBox.SelectedIndex]; 85 (RegressionSolutionVariableImpactsCalculator.ReplacementMethodEnum) 86 replacementComboBox.Items[replacementComboBox.SelectedIndex]; 87 var factorReplMethod = 88 (RegressionSolutionVariableImpactsCalculator.FactorReplacementMethodEnum) 89 factorVarReplComboBox.Items[factorVarReplComboBox.SelectedIndex]; 83 90 var dataPartition = 84 91 (RegressionSolutionVariableImpactsCalculator.DataPartitionEnum)dataPartitionComboBox.SelectedItem; … … 88 95 mainForm.AddOperationProgressToView(this, "Calculating variable impacts for " + Content.Name); 89 96 90 var impacts = RegressionSolutionVariableImpactsCalculator.CalculateImpacts(Content, dataPartition, replMethod );97 var impacts = RegressionSolutionVariableImpactsCalculator.CalculateImpacts(Content, dataPartition, replMethod, factorReplMethod); 91 98 var impactArray = new DoubleArray(impacts.Select(i => i.Item2).ToArray()); 92 99 impactArray.ElementNames = impacts.Select(i => i.Item1);
Note: See TracChangeset
for help on using the changeset viewer.