Changeset 16519 for trunk/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionPartialDependencePlotView.cs
- Timestamp:
- 01/08/19 15:29:57 (6 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/2972_PDPRowSelect (added) merged: 16444-16445,16516-16518
- Property svn:mergeinfo changed
-
trunk/HeuristicLab.Problems.DataAnalysis.Views
- Property svn:mergeinfo changed
/branches/2972_PDPRowSelect/HeuristicLab.Problems.DataAnalysis.Views (added) merged: 16445,16516-16517
- Property svn:mergeinfo changed
-
trunk/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionPartialDependencePlotView.cs
r15583 r16519 97 97 var problemData = Content.ProblemData; 98 98 99 if (sharedFixedVariables != null) { 100 sharedFixedVariables.ItemChanged -= SharedFixedVariables_ItemChanged; 101 sharedFixedVariables.Reset -= SharedFixedVariables_Reset; 102 } 103 99 104 // Init Y-axis range 100 105 double min = double.MaxValue, max = double.MinValue; … … 120 125 Content.ProblemData.Dataset.VariableNames.Where(v => inputvariables.Contains(v)).ToList(); 121 126 122 123 127 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() }); 128 var doubleVariableValues = (IEnumerable<IList>)doubleVariables.Select(x => new List<double> { 129 problemData.Dataset.GetDoubleValue(x, 0) 130 }); 125 131 126 132 var factorVariables = allowedInputVariables.Where(problemData.Dataset.VariableHasType<string>); 127 133 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 134 problemData.Dataset.GetStringValue(x, 0) 130 135 }); 131 136 132 if (sharedFixedVariables != null)133 sharedFixedVariables.ItemChanged -= SharedFixedVariables_ItemChanged;134 135 137 sharedFixedVariables = new ModifiableDataset(doubleVariables.Concat(factorVariables), doubleVariableValues.Concat(factorVariableValues)); 136 138 variableValuesModeComboBox.SelectedItem = "Median"; // triggers UpdateVariableValue and changes shardFixedVariables 137 139 138 140 // create controls … … 166 168 }; 167 169 168 // Initially, the inner plot areas are not initialized for hidden charts (sc ollpanel, ...)170 // Initially, the inner plot areas are not initialized for hidden charts (scrollpanel, ...) 169 171 // This event handler listens for the paint event once (where everything is already initialized) to do some manual layouting. 170 172 plot.ChartPostPaint += OnPartialDependencePlotPostPaint; … … 205 207 }; 206 208 207 // Initially, the inner plot areas are not initialized for hidden charts (sc ollpanel, ...)209 // Initially, the inner plot areas are not initialized for hidden charts (scrollpanel, ...) 208 210 // This event handler listens for the paint event once (where everything is already initialized) to do some manual layouting. 209 211 plot.ChartPostPaint += OnFactorPartialDependencePlotPostPaint; … … 230 232 231 233 sharedFixedVariables.ItemChanged += SharedFixedVariables_ItemChanged; 234 sharedFixedVariables.Reset += SharedFixedVariables_Reset; 235 236 rowNrNumericUpDown.Maximum = Content.ProblemData.Dataset.Rows - 1; 232 237 233 238 RecalculateAndRelayoutCharts(); … … 235 240 236 241 private void SharedFixedVariables_ItemChanged(object sender, EventArgs<int, int> e) { 242 SharedFixedVariablesChanged(); 243 } 244 private void SharedFixedVariables_Reset(object sender, EventArgs e) { 245 SharedFixedVariablesChanged(); 246 } 247 private void SharedFixedVariablesChanged() { 248 if (!setVariableValues) // set mode to "nothing" if change was not initiated from a "mode change" 249 variableValuesModeComboBox.SelectedIndex = -1; 250 237 251 double yValue = Content.Model.GetEstimatedValues(sharedFixedVariables, new[] { 0 }).Single(); 238 252 string title = Content.ProblemData.TargetVariable + ": " + yValue.ToString("G5", CultureInfo.CurrentCulture); … … 243 257 } 244 258 } 245 246 259 247 260 private void OnPartialDependencePlotPostPaint(object o, EventArgs e) { … … 564 577 } 565 578 } 579 580 // flag that the current change is not triggered by a manual change from within a single plot 581 private bool setVariableValues = false; 582 private void variableValuesComboBox_SelectedValueChanged(object sender, EventArgs e) { 583 if (variableValuesModeComboBox.SelectedIndex == -1) 584 return; // changed to "manual" due to manual change of a variable 585 setVariableValues = true; 586 UpdateVariableValues(); 587 setVariableValues = false; 588 } 589 private void rowNrNumericUpDown_ValueChanged(object sender, EventArgs e) { 590 if ((string)variableValuesModeComboBox.SelectedItem != "Row") { 591 variableValuesModeComboBox.SelectedItem = "Row"; // triggers UpdateVariableValues 592 } else { 593 setVariableValues = true; 594 UpdateVariableValues(); 595 setVariableValues = false; 596 } 597 } 598 private void UpdateVariableValues() { 599 string mode = (string)variableValuesModeComboBox.SelectedItem; 600 601 var dataset = Content.ProblemData.Dataset; 602 object[] newRow; 603 604 if (mode == "Row") { 605 int rowNumber = (int)rowNrNumericUpDown.Value; 606 newRow = sharedFixedVariables.VariableNames 607 .Select<string, object>(variableName => { 608 if (dataset.DoubleVariables.Contains(variableName)) { 609 return dataset.GetDoubleValue(variableName, rowNumber); 610 } else if (dataset.StringVariables.Contains(variableName)) { 611 return dataset.GetStringValue(variableName, rowNumber); 612 } else { 613 throw new NotSupportedException("Only double and string(factor) columns are currently supported."); 614 } 615 }).ToArray(); 616 } else { 617 newRow = sharedFixedVariables.VariableNames 618 .Select<string, object>(variableName => { 619 if (dataset.DoubleVariables.Contains(variableName)) { 620 var values = dataset.GetDoubleValues(variableName); 621 return 622 mode == "Mean" ? values.Average() : 623 mode == "Median" ? values.Median() : 624 mode == "Most Common" ? MostCommon(values) : 625 throw new NotSupportedException(); 626 } else if (dataset.StringVariables.Contains(variableName)) { 627 var values = dataset.GetStringValues(variableName); 628 return 629 mode == "Mean" ? MostCommon(values) : 630 mode == "Median" ? MostCommon(values) : 631 mode == "Most Common" ? MostCommon(values) : 632 throw new NotSupportedException(); 633 } else { 634 throw new NotSupportedException("Only double and string(factor) columns are currently supported."); 635 } 636 }).ToArray(); 637 } 638 639 sharedFixedVariables.ReplaceRow(0, newRow); 640 } 641 642 private static T MostCommon<T>(IEnumerable<T> values) { 643 return values.GroupBy(x => x).OrderByDescending(g => g.Count()).Select(g => g.Key).First(); 644 } 645 646 // ToolTips cannot be shown longer than 5000ms, only by using ToolTip.Show manually 647 // See: https://stackoverflow.com/questions/8225807/c-sharp-tooltip-doesnt-display-long-enough 648 private void variableValuesModeComboBox_MouseHover(object sender, EventArgs e) { 649 string tooltipText = @"Sets each variable to a specific value: 650 Row - Selects the value based on a specified row of the dataset. 651 Mean - Sets the value to the arithmetic mean of the variable. 652 Median - Sets the value to the median of the variable. 653 Most Common - Sets the value to the most common value of the variable (first if multiple). 654 655 Note: For categorical values, the most common value is used when selecting Mean, Median or Most Common."; 656 toolTip.Show(tooltipText, variableValuesModeComboBox, 30000); 657 toolTip.Active = true; 658 } 659 private void variableValuesModeComboBox_MouseLeave(object sender, EventArgs e) { 660 toolTip.Active = false; 661 } 566 662 } 567 663 }
Note: See TracChangeset
for help on using the changeset viewer.