Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/08/19 12:06:01 (5 years ago)
Author:
pfleck
Message:

#2972 Updated UI for PDP variable values selection.

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  
    668668    private void UpdateCursor() {
    669669      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);
    671673
    672674      if (ShowCursor) {
  • branches/2972_PDPRowSelect/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionPartialDependencePlotView.Designer.cs

    r16445 r16516  
    3838      this.variableGroupBox = new System.Windows.Forms.GroupBox();
    3939      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();
    4242      this.rowNrNumericUpDown = new System.Windows.Forms.NumericUpDown();
    4343      this.scrollPanel = new System.Windows.Forms.Panel();
     
    7171      // partialDependencePlotTableLayout
    7272      //
    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)
    7474            | System.Windows.Forms.AnchorStyles.Right)));
    7575      this.partialDependencePlotTableLayout.AutoSize = true;
     
    9898      // limitView
    9999      //
    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)
    101101            | System.Windows.Forms.AnchorStyles.Right)));
    102102      this.limitView.Caption = "DoubleLimit View";
     
    135135      // columnsNumericUpDown
    136136      //
    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)
    138138            | System.Windows.Forms.AnchorStyles.Right)));
    139139      this.columnsNumericUpDown.Location = new System.Drawing.Point(66, 46);
     
    164164      // densityComboBox
    165165      //
    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)
    167167            | System.Windows.Forms.AnchorStyles.Right)));
    168168      this.densityComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
     
    214214      this.variableGroupBox.Controls.Add(this.variableListView);
    215215      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);
    217217      this.variableGroupBox.Name = "variableGroupBox";
    218218      this.variableGroupBox.Size = new System.Drawing.Size(169, 423);
     
    223223      // rowSelectGroupBox
    224224      //
    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);
    227227      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);
    230230      this.rowSelectGroupBox.Name = "rowSelectGroupBox";
    231231      this.rowSelectGroupBox.Size = new System.Drawing.Size(169, 74);
    232232      this.rowSelectGroupBox.TabIndex = 1;
    233233      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",
    241242            "Mean",
    242243            "Median",
    243244            "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.";
    257259      //
    258260      // rowNrNumericUpDown
    259261      //
    260       this.rowNrNumericUpDown.Location = new System.Drawing.Point(66, 19);
     262      this.rowNrNumericUpDown.Location = new System.Drawing.Point(66, 46);
    261263      this.rowNrNumericUpDown.Name = "rowNrNumericUpDown";
    262264      this.rowNrNumericUpDown.Size = new System.Drawing.Size(94, 20);
     
    322324    private System.Windows.Forms.NumericUpDown columnsNumericUpDown;
    323325    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;
    326328    private System.Windows.Forms.NumericUpDown rowNrNumericUpDown;
    327329  }
  • branches/2972_PDPRowSelect/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionPartialDependencePlotView.cs

    r16445 r16516  
    120120        Content.ProblemData.Dataset.VariableNames.Where(v => inputvariables.Contains(v)).ToList();
    121121
    122 
     122      // ToDo: set default values with the variableValuesMode
    123123      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      });
    125127
    126128      var factorVariables = allowedInputVariables.Where(problemData.Dataset.VariableHasType<string>);
    127129      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))
    130131      });
    131132
    132       if (sharedFixedVariables != null)
     133      if (sharedFixedVariables != null) {
    133134        sharedFixedVariables.ItemChanged -= SharedFixedVariables_ItemChanged;
     135        sharedFixedVariables.Reset -= SharedFixedVariables_Reset;
     136      }
    134137
    135138      sharedFixedVariables = new ModifiableDataset(doubleVariables.Concat(factorVariables), doubleVariableValues.Concat(factorVariableValues));
     
    230233
    231234      sharedFixedVariables.ItemChanged += SharedFixedVariables_ItemChanged;
     235      sharedFixedVariables.Reset += SharedFixedVariables_Reset;
    232236
    233237      rowNrNumericUpDown.Maximum = Content.ProblemData.Dataset.Rows - 1;
     
    237241
    238242    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
    239252      double yValue = Content.Model.GetEstimatedValues(sharedFixedVariables, new[] { 0 }).Single();
    240253      string title = Content.ProblemData.TargetVariable + ": " + yValue.ToString("G5", CultureInfo.CurrentCulture);
     
    245258      }
    246259    }
    247 
    248260
    249261    private void OnPartialDependencePlotPostPaint(object o, EventArgs e) {
     
    567579    }
    568580
     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    }
    569590    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
    571602      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      }
    583640
    584641      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();
    585646    }
    586647  }
Note: See TracChangeset for help on using the changeset viewer.