Changeset 16516
- Timestamp:
- 01/08/19 12:06:01 (6 years ago)
- Location:
- branches/2972_PDPRowSelect/HeuristicLab.Problems.DataAnalysis.Views/3.4
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2972_PDPRowSelect/HeuristicLab.Problems.DataAnalysis.Views/3.4/Controls/PartialDependencePlot.cs
r16445 r16516 668 668 private void UpdateCursor() { 669 669 var x = VerticalLineAnnotation.X; 670 sharedFixedVariables.SetVariableValue(x, FreeVariable, 0); 670 671 if (!sharedFixedVariables.GetDoubleValue(FreeVariable, 0).IsAlmost(x)) 672 sharedFixedVariables.SetVariableValue(x, FreeVariable, 0); 671 673 672 674 if (ShowCursor) { -
branches/2972_PDPRowSelect/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionPartialDependencePlotView.Designer.cs
r16445 r16516 38 38 this.variableGroupBox = new System.Windows.Forms.GroupBox(); 39 39 this.rowSelectGroupBox = new System.Windows.Forms.GroupBox(); 40 this. comboBox1= new System.Windows.Forms.ComboBox();41 this. label2= new System.Windows.Forms.Label();40 this.variableValuesModeComboBox = new System.Windows.Forms.ComboBox(); 41 this.rowLabel = new System.Windows.Forms.Label(); 42 42 this.rowNrNumericUpDown = new System.Windows.Forms.NumericUpDown(); 43 43 this.scrollPanel = new System.Windows.Forms.Panel(); … … 71 71 // partialDependencePlotTableLayout 72 72 // 73 this.partialDependencePlotTableLayout.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 73 this.partialDependencePlotTableLayout.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 74 74 | System.Windows.Forms.AnchorStyles.Right))); 75 75 this.partialDependencePlotTableLayout.AutoSize = true; … … 98 98 // limitView 99 99 // 100 this.limitView.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 100 this.limitView.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 101 101 | System.Windows.Forms.AnchorStyles.Right))); 102 102 this.limitView.Caption = "DoubleLimit View"; … … 135 135 // columnsNumericUpDown 136 136 // 137 this.columnsNumericUpDown.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 137 this.columnsNumericUpDown.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 138 138 | System.Windows.Forms.AnchorStyles.Right))); 139 139 this.columnsNumericUpDown.Location = new System.Drawing.Point(66, 46); … … 164 164 // densityComboBox 165 165 // 166 this.densityComboBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 166 this.densityComboBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 167 167 | System.Windows.Forms.AnchorStyles.Right))); 168 168 this.densityComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; … … 214 214 this.variableGroupBox.Controls.Add(this.variableListView); 215 215 this.variableGroupBox.Dock = System.Windows.Forms.DockStyle.Fill; 216 this.variableGroupBox.Location = new System.Drawing.Point(0, 151);216 this.variableGroupBox.Location = new System.Drawing.Point(0, 225); 217 217 this.variableGroupBox.Name = "variableGroupBox"; 218 218 this.variableGroupBox.Size = new System.Drawing.Size(169, 423); … … 223 223 // rowSelectGroupBox 224 224 // 225 this.rowSelectGroupBox.Controls.Add(this. comboBox1);226 this.rowSelectGroupBox.Controls.Add(this. label2);225 this.rowSelectGroupBox.Controls.Add(this.variableValuesModeComboBox); 226 this.rowSelectGroupBox.Controls.Add(this.rowLabel); 227 227 this.rowSelectGroupBox.Controls.Add(this.rowNrNumericUpDown); 228 this.rowSelectGroupBox.Dock = System.Windows.Forms.DockStyle. Bottom;229 this.rowSelectGroupBox.Location = new System.Drawing.Point(0, 574);228 this.rowSelectGroupBox.Dock = System.Windows.Forms.DockStyle.Top; 229 this.rowSelectGroupBox.Location = new System.Drawing.Point(0, 151); 230 230 this.rowSelectGroupBox.Name = "rowSelectGroupBox"; 231 231 this.rowSelectGroupBox.Size = new System.Drawing.Size(169, 74); 232 232 this.rowSelectGroupBox.TabIndex = 1; 233 233 this.rowSelectGroupBox.TabStop = false; 234 this.rowSelectGroupBox.Text = "Set Fixed Variable Values"; 235 // 236 // comboBox1 237 // 238 this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; 239 this.comboBox1.FormattingEnabled = true; 240 this.comboBox1.Items.AddRange(new object[] { 234 this.rowSelectGroupBox.Text = "Variable Values"; 235 // 236 // variableValuesModeComboBox 237 // 238 this.variableValuesModeComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; 239 this.variableValuesModeComboBox.FormattingEnabled = true; 240 this.variableValuesModeComboBox.Items.AddRange(new object[] { 241 "Row", 241 242 "Mean", 242 243 "Median", 243 244 "Most Common"}); 244 this.comboBox1.Location = new System.Drawing.Point(10, 45); 245 this.comboBox1.Name = "comboBox1"; 246 this.comboBox1.Size = new System.Drawing.Size(150, 21); 247 this.comboBox1.TabIndex = 3; 248 // 249 // label2 250 // 251 this.label2.AutoSize = true; 252 this.label2.Location = new System.Drawing.Point(7, 21); 253 this.label2.Name = "label2"; 254 this.label2.Size = new System.Drawing.Size(46, 13); 255 this.label2.TabIndex = 2; 256 this.label2.Text = "Row Nr."; 245 this.variableValuesModeComboBox.Location = new System.Drawing.Point(10, 19); 246 this.variableValuesModeComboBox.Name = "variableValuesModeComboBox"; 247 this.variableValuesModeComboBox.Size = new System.Drawing.Size(150, 21); 248 this.variableValuesModeComboBox.TabIndex = 3; 249 this.variableValuesModeComboBox.SelectedValueChanged += new System.EventHandler(this.variableValuesComboBox_SelectedValueChanged); 250 // 251 // rowLabel 252 // 253 this.rowLabel.AutoSize = true; 254 this.rowLabel.Location = new System.Drawing.Point(7, 48); 255 this.rowLabel.Name = "rowLabel"; 256 this.rowLabel.Size = new System.Drawing.Size(44, 13); 257 this.rowLabel.TabIndex = 2; 258 this.rowLabel.Text = "Row nr."; 257 259 // 258 260 // rowNrNumericUpDown 259 261 // 260 this.rowNrNumericUpDown.Location = new System.Drawing.Point(66, 19);262 this.rowNrNumericUpDown.Location = new System.Drawing.Point(66, 46); 261 263 this.rowNrNumericUpDown.Name = "rowNrNumericUpDown"; 262 264 this.rowNrNumericUpDown.Size = new System.Drawing.Size(94, 20); … … 322 324 private System.Windows.Forms.NumericUpDown columnsNumericUpDown; 323 325 private System.Windows.Forms.GroupBox rowSelectGroupBox; 324 private System.Windows.Forms.ComboBox comboBox1;325 private System.Windows.Forms.Label label2;326 private System.Windows.Forms.ComboBox variableValuesModeComboBox; 327 private System.Windows.Forms.Label rowLabel; 326 328 private System.Windows.Forms.NumericUpDown rowNrNumericUpDown; 327 329 } -
branches/2972_PDPRowSelect/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionPartialDependencePlotView.cs
r16445 r16516 120 120 Content.ProblemData.Dataset.VariableNames.Where(v => inputvariables.Contains(v)).ToList(); 121 121 122 122 // ToDo: set default values with the variableValuesMode 123 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() }); 124 var doubleVariableValues = (IEnumerable<IList>)doubleVariables.Select(x => new List<double> { 125 problemData.Dataset.GetDoubleValues(x, problemData.TrainingIndices).Median() 126 }); 125 127 126 128 var factorVariables = allowedInputVariables.Where(problemData.Dataset.VariableHasType<string>); 127 129 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 MostCommon(problemData.Dataset.GetStringValues(x, problemData.TrainingIndices)) 130 131 }); 131 132 132 if (sharedFixedVariables != null) 133 if (sharedFixedVariables != null) { 133 134 sharedFixedVariables.ItemChanged -= SharedFixedVariables_ItemChanged; 135 sharedFixedVariables.Reset -= SharedFixedVariables_Reset; 136 } 134 137 135 138 sharedFixedVariables = new ModifiableDataset(doubleVariables.Concat(factorVariables), doubleVariableValues.Concat(factorVariableValues)); … … 230 233 231 234 sharedFixedVariables.ItemChanged += SharedFixedVariables_ItemChanged; 235 sharedFixedVariables.Reset += SharedFixedVariables_Reset; 232 236 233 237 rowNrNumericUpDown.Maximum = Content.ProblemData.Dataset.Rows - 1; … … 237 241 238 242 private void SharedFixedVariables_ItemChanged(object sender, EventArgs<int, int> e) { 243 SharedFixedVariablesChanged(); 244 } 245 private void SharedFixedVariables_Reset(object sender, EventArgs e) { 246 SharedFixedVariablesChanged(); 247 } 248 private void SharedFixedVariablesChanged() { 249 if (!setVariableValues) // set mode to "nothing" if change was not initiated from a "mode change" 250 variableValuesModeComboBox.SelectedIndex = -1; 251 239 252 double yValue = Content.Model.GetEstimatedValues(sharedFixedVariables, new[] { 0 }).Single(); 240 253 string title = Content.ProblemData.TargetVariable + ": " + yValue.ToString("G5", CultureInfo.CurrentCulture); … … 245 258 } 246 259 } 247 248 260 249 261 private void OnPartialDependencePlotPostPaint(object o, EventArgs e) { … … 567 579 } 568 580 581 // flag that the current change is not triggered by a manual change from within a single plot 582 private bool setVariableValues = false; 583 private void variableValuesComboBox_SelectedValueChanged(object sender, EventArgs e) { 584 if (variableValuesModeComboBox.SelectedIndex == -1) 585 return; // changed to "manual" due to manual change of a variable 586 setVariableValues = true; 587 UpdateVariableValues(); 588 setVariableValues = false; 589 } 569 590 private void rowNrNumericUpDown_ValueChanged(object sender, EventArgs e) { 570 int rowNumber = (int)rowNrNumericUpDown.Value; 591 if ((string)variableValuesModeComboBox.SelectedItem != "Row") { 592 variableValuesModeComboBox.SelectedItem = "Row"; // triggers UpdateVariableValues 593 } else { 594 setVariableValues = true; 595 UpdateVariableValues(); 596 setVariableValues = false; 597 } 598 } 599 private void UpdateVariableValues() { 600 string mode = (string)variableValuesModeComboBox.SelectedItem; 601 571 602 var dataset = Content.ProblemData.Dataset; 572 573 object[] newRow = sharedFixedVariables.VariableNames 574 .Select<string, object>(variableName => { 575 if (dataset.DoubleVariables.Contains(variableName)) { 576 return dataset.GetDoubleValue(variableName, rowNumber); 577 } else if (dataset.StringVariables.Contains(variableName)) { 578 return dataset.GetStringValue(variableName, rowNumber); 579 } else { 580 throw new NotSupportedException("Only double and string(factor) columns are currently supported."); 581 } 582 }).ToArray(); 603 object[] newRow; 604 605 if (mode == "Row") { 606 int rowNumber = (int)rowNrNumericUpDown.Value; 607 newRow = sharedFixedVariables.VariableNames 608 .Select<string, object>(variableName => { 609 if (dataset.DoubleVariables.Contains(variableName)) { 610 return dataset.GetDoubleValue(variableName, rowNumber); 611 } else if (dataset.StringVariables.Contains(variableName)) { 612 return dataset.GetStringValue(variableName, rowNumber); 613 } else { 614 throw new NotSupportedException("Only double and string(factor) columns are currently supported."); 615 } 616 }).ToArray(); 617 } else { 618 //int si = densityComboBox.SelectedIndex; 619 newRow = sharedFixedVariables.VariableNames 620 .Select<string, object>(variableName => { 621 if (dataset.DoubleVariables.Contains(variableName)) { 622 var values = dataset.GetDoubleValues(variableName/*, GetDensityIndices(si)*/); 623 return 624 mode == "Mean" ? values.Average() : 625 mode == "Median" ? values.Median() : 626 mode == "Most Common" ? MostCommon(values) : 627 throw new NotSupportedException(); 628 } else if (dataset.StringVariables.Contains(variableName)) { 629 var values = dataset.GetStringValues(variableName/*, GetDensityIndices(si)*/); 630 return 631 mode == "Mean" ? MostCommon(values) : 632 mode == "Median" ? MostCommon(values) : 633 mode == "Most Common" ? MostCommon(values) : 634 throw new NotSupportedException(); 635 } else { 636 throw new NotSupportedException("Only double and string(factor) columns are currently supported."); 637 } 638 }).ToArray(); 639 } 583 640 584 641 sharedFixedVariables.ReplaceRow(0, newRow); 642 } 643 644 private static T MostCommon<T>(IEnumerable<T> values) { 645 return values.GroupBy(x => x).OrderByDescending(g => g.Count()).Select(g => g.Key).First(); 585 646 } 586 647 }
Note: See TracChangeset
for help on using the changeset viewer.