Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/28/11 13:47:28 (13 years ago)
Author:
sforsten
Message:

#1669: branch has been merged with the trunk in revision 7081 and methods in RegressionBenchmark have been renamed.

Location:
branches/RegressionBenchmarks
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • branches/RegressionBenchmarks

  • branches/RegressionBenchmarks/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/ClassificationEnsembleSolutionEstimatedClassValuesView.cs

    r6740 r7085  
    2424using System.Linq;
    2525using System.Windows.Forms;
     26using HeuristicLab.Common;
    2627using HeuristicLab.Data;
    2728using HeuristicLab.MainForm;
     
    9697
    9798      int classValuesCount = Content.ProblemData.ClassValues.Count;
    98       int modelCount = Content.Model.Models.Count();
    99       string[,] values = new string[indizes.Length, 5 + classValuesCount + modelCount];
     99      int solutionsCount = Content.ClassificationSolutions.Count();
     100      string[,] values = new string[indizes.Length, 5 + classValuesCount + solutionsCount];
    100101      double[] target = Content.ProblemData.Dataset.GetDoubleValues(Content.ProblemData.TargetVariable).ToArray();
    101102      List<List<double?>> estimatedValuesVector = GetEstimatedValues(SamplesComboBox.SelectedItem.ToString(), indizes,
     
    106107        values[i, 0] = row.ToString();
    107108        values[i, 1] = target[i].ToString();
    108         values[i, 2] = estimatedClassValues[i].ToString();
    109         values[i, 3] = (target[i] == estimatedClassValues[i]).ToString();
    110         var groups = estimatedValuesVector[i].GroupBy(x => x).Select(g => new { Key = g.Key, Count = g.Count() }).ToList();
    111         var estimationCount = groups.Where(g => g.Key != null).Select(g => g.Count).Sum();
    112         values[i, 4] = (((double)groups.Where(g => g.Key == estimatedClassValues[i]).Single().Count) / estimationCount).ToString();
    113         for (int classIndex = 0; classIndex < Content.ProblemData.ClassValues.Count; classIndex++) {
    114           var group = groups.Where(g => g.Key == Content.ProblemData.ClassValues[classIndex]).SingleOrDefault();
    115           if (group == null) values[i, 5 + classIndex] = 0.ToString();
    116           else values[i, 5 + classIndex] = group.Count.ToString();
     109        //display only indices and target values if no models are present
     110        if (solutionsCount > 0) {
     111          values[i, 2] = estimatedClassValues[i].ToString();
     112          values[i, 3] = (target[i].IsAlmost(estimatedClassValues[i])).ToString();
     113          var groups =
     114            estimatedValuesVector[i].GroupBy(x => x).Select(g => new { Key = g.Key, Count = g.Count() }).ToList();
     115          var estimationCount = groups.Where(g => g.Key != null).Select(g => g.Count).Sum();
     116          values[i, 4] =
     117            (((double)groups.Where(g => g.Key == estimatedClassValues[i]).Single().Count) / estimationCount).ToString();
     118          for (int classIndex = 0; classIndex < Content.ProblemData.ClassValues.Count; classIndex++) {
     119            var group = groups.Where(g => g.Key == Content.ProblemData.ClassValues[classIndex]).SingleOrDefault();
     120            if (group == null) values[i, 5 + classIndex] = 0.ToString();
     121            else values[i, 5 + classIndex] = group.Count.ToString();
     122          }
     123          for (int modelIndex = 0; modelIndex < estimatedValuesVector[i].Count; modelIndex++) {
     124            values[i, 5 + classValuesCount + modelIndex] = estimatedValuesVector[i][modelIndex] == null
     125                                                             ? string.Empty
     126                                                             : estimatedValuesVector[i][modelIndex].ToString();
     127          }
    117128        }
    118         for (int modelIndex = 0; modelIndex < estimatedValuesVector[i].Count; modelIndex++) {
    119           values[i, 5 + classValuesCount + modelIndex] = estimatedValuesVector[i][modelIndex] == null
    120                                                            ? string.Empty
    121                                                            : estimatedValuesVector[i][modelIndex].ToString();
    122         }
    123 
    124129      }
    125130
     
    131136      matrix.SortableView = true;
    132137      matrixView.Content = matrix;
    133       UpdateColoringOfRows();
    134138    }
    135139
     
    162166        return;
    163167      }
    164       bool correctClassified = bool.Parse(matrixView.DataGridView[3, e.RowIndex].Value.ToString());
     168      var cellValue = matrixView.DataGridView[3, e.RowIndex].Value.ToString();
     169      if (string.IsNullOrEmpty(cellValue)) return;
     170      bool correctClassified = bool.Parse(cellValue);
    165171      matrixView.DataGridView.Rows[e.RowIndex].DefaultCellStyle.ForeColor = correctClassified ? Color.MediumSeaGreen : Color.Red;
    166     }
    167 
    168     private void UpdateColoringOfRows() {
    169       if (InvokeRequired) {
    170         Invoke((Action)UpdateColoringOfRows);
    171         return;
    172       }
    173       //matrixView.DataGridView.SuspendRepaint();
    174       //for (int i = 0; i < matrixView.DataGridView.Rows.Count; i++) {
    175       //  bool correctClassified = bool.Parse(matrixView.Content.GetValue(i, 3));
    176       //  matrixView.DataGridView.Rows[i].DefaultCellStyle.ForeColor = correctClassified ? Color.MediumSeaGreen : Color.Red;
    177       //}
    178       //matrixView.DataGridView.ResumeRepaint(true);
    179172    }
    180173  }
  • branches/RegressionBenchmarks/HeuristicLab.Problems.DataAnalysis.Views/3.4/DataAnalysisProblemView.Designer.cs

    r6968 r7085  
    4949      this.benchmarkComboBox = new System.Windows.Forms.ComboBox();
    5050      this.loadButton = new System.Windows.Forms.Button();
     51      this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
    5152      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit();
     53      this.tableLayoutPanel1.SuspendLayout();
    5254      this.SuspendLayout();
    5355      //
    5456      // parameterCollectionView
    5557      //
    56       this.parameterCollectionView.Location = new System.Drawing.Point(3, 55);
    57       this.parameterCollectionView.Size = new System.Drawing.Size(490, 279);
     58      this.parameterCollectionView.Location = new System.Drawing.Point(3, 80);
     59      this.parameterCollectionView.Size = new System.Drawing.Size(490, 254);
    5860      this.parameterCollectionView.TabIndex = 4;
    5961      //
     
    7476      this.importButton.Location = new System.Drawing.Point(3, 24);
    7577      this.importButton.Name = "importButton";
    76       this.importButton.Size = new System.Drawing.Size(243, 23);
     78      this.importButton.Size = new System.Drawing.Size(487, 23);
    7779      this.importButton.TabIndex = 3;
    7880      this.importButton.Text = "Import from CSV file";
     
    8284      // openFileDialog
    8385      //
    84       this.openFileDialog.FileName = "openFileDialog";
     86      this.openFileDialog.Filter = "CSV files|*.csv|Text files|*.txt|All files|*.*";
     87      this.openFileDialog.Title = "Import data...";
    8588      //
    8689      // benchmarkComboBox
    8790      //
    88       this.benchmarkComboBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
     91      this.benchmarkComboBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
     92            | System.Windows.Forms.AnchorStyles.Right)));
    8993      this.benchmarkComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
    9094      this.benchmarkComboBox.FormattingEnabled = true;
    91       this.benchmarkComboBox.Location = new System.Drawing.Point(252, 25);
     95      this.benchmarkComboBox.Location = new System.Drawing.Point(3, 3);
    9296      this.benchmarkComboBox.Name = "benchmarkComboBox";
    93       this.benchmarkComboBox.Size = new System.Drawing.Size(183, 21);
     97      this.benchmarkComboBox.Size = new System.Drawing.Size(240, 21);
    9498      this.benchmarkComboBox.TabIndex = 5;
    9599      //
    96100      // loadButton
    97101      //
    98       this.loadButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
    99       this.loadButton.Location = new System.Drawing.Point(439, 24);
     102      this.loadButton.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
     103            | System.Windows.Forms.AnchorStyles.Right)));
     104      this.loadButton.Location = new System.Drawing.Point(249, 2);
     105      this.loadButton.Margin = new System.Windows.Forms.Padding(3, 2, 3, 3);
    100106      this.loadButton.Name = "loadButton";
    101       this.loadButton.Size = new System.Drawing.Size(50, 23);
     107      this.loadButton.Size = new System.Drawing.Size(241, 23);
    102108      this.loadButton.TabIndex = 6;
    103109      this.loadButton.Text = "Load";
     
    105111      this.loadButton.Click += new System.EventHandler(this.loadButton_Click);
    106112      //
     113      // tableLayoutPanel1
     114      //
     115      this.tableLayoutPanel1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
     116            | System.Windows.Forms.AnchorStyles.Right)));
     117      this.tableLayoutPanel1.ColumnCount = 2;
     118      this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
     119      this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
     120      this.tableLayoutPanel1.Controls.Add(this.benchmarkComboBox, 0, 0);
     121      this.tableLayoutPanel1.Controls.Add(this.loadButton, 1, 0);
     122      this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 51);
     123      this.tableLayoutPanel1.Name = "tableLayoutPanel1";
     124      this.tableLayoutPanel1.RowCount = 1;
     125      this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
     126      this.tableLayoutPanel1.Size = new System.Drawing.Size(493, 28);
     127      this.tableLayoutPanel1.TabIndex = 7;
     128      //
    107129      // DataAnalysisProblemView
    108130      //
    109131      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    110132      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    111       this.Controls.Add(this.loadButton);
    112133      this.Controls.Add(this.importButton);
    113       this.Controls.Add(this.benchmarkComboBox);
     134      this.Controls.Add(this.tableLayoutPanel1);
    114135      this.Name = "DataAnalysisProblemView";
    115136      this.Size = new System.Drawing.Size(493, 334);
    116       this.Controls.SetChildIndex(this.benchmarkComboBox, 0);
     137      this.Controls.SetChildIndex(this.tableLayoutPanel1, 0);
    117138      this.Controls.SetChildIndex(this.importButton, 0);
    118       this.Controls.SetChildIndex(this.loadButton, 0);
     139      this.Controls.SetChildIndex(this.parameterCollectionView, 0);
    119140      this.Controls.SetChildIndex(this.infoLabel, 0);
    120141      this.Controls.SetChildIndex(this.nameTextBox, 0);
    121142      this.Controls.SetChildIndex(this.nameLabel, 0);
    122       this.Controls.SetChildIndex(this.parameterCollectionView, 0);
    123143      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).EndInit();
     144      this.tableLayoutPanel1.ResumeLayout(false);
    124145      this.ResumeLayout(false);
    125146      this.PerformLayout();
     
    133154    private System.Windows.Forms.ComboBox benchmarkComboBox;
    134155    private System.Windows.Forms.Button loadButton;
     156    private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1;
    135157  }
    136158}
  • branches/RegressionBenchmarks/HeuristicLab.Problems.DataAnalysis.Views/3.4/DataAnalysisProblemView.cs

    r7044 r7085  
    2424using System.Linq;
    2525using System.Windows.Forms;
     26using HeuristicLab.Common;
    2627using HeuristicLab.MainForm;
    2728using HeuristicLab.Optimization.Views;
     
    6566      base.OnContentChanged();
    6667      benchmarkComboBox.Items.Clear();
    67       benchmarkComboBox.Items.AddRange(GetBenchmarkProblemDataGenerators().OrderBy(b => b.Name).ToArray());
     68      benchmarkComboBox.Items.AddRange(GetBenchmarkProblemDataGenerators().OrderBy(b => b.Name, new NaturalStringComparer()).ToArray());
    6869      if (benchmarkComboBox.Items.Count > 0)
    6970        benchmarkComboBox.SelectedIndex = 0;
  • branches/RegressionBenchmarks/HeuristicLab.Problems.DataAnalysis.Views/3.4/DataAnalysisProblemView.resx

    r6969 r7085  
    121121    <value>107, 17</value>
    122122  </metadata>
     123  <metadata name="errorProvider.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
     124    <value>107, 17</value>
     125  </metadata>
    123126  <metadata name="toolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
    124127    <value>17, 17</value>
  • branches/RegressionBenchmarks/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionErrorCharacteristicsCurveView.Designer.cs

    r6642 r7085  
    4949      this.chart.TabIndex = 0;
    5050      this.chart.Text = "chart";
     51      this.chart.MouseDown += new System.Windows.Forms.MouseEventHandler(this.chart_MouseDown);
    5152      //
    5253      // label1
  • branches/RegressionBenchmarks/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionErrorCharacteristicsCurveView.cs

    r6750 r7085  
    3131  [Content(typeof(IRegressionSolution))]
    3232  public partial class RegressionSolutionErrorCharacteristicsCurveView : DataAnalysisSolutionEvaluationView {
     33    private IRegressionSolution constantModel;
    3334    protected const string TrainingSamples = "Training";
    3435    protected const string TestSamples = "Test";
     
    101102      if (Content == null) return;
    102103
    103       var originalValues = GetOriginalValues();
    104       var meanModelEstimatedValues = GetMeanModelEstimatedValues(originalValues);
     104      var originalValues = GetOriginalValues().ToList();
     105      constantModel = CreateConstantModel();
     106      var meanModelEstimatedValues = GetEstimatedValues(constantModel);
    105107      var meanModelResiduals = GetResiduals(originalValues, meanModelEstimatedValues);
    106108
     
    113115      UpdateSeries(meanModelResiduals, meanModelSeries);
    114116      meanModelSeries.ToolTip = "Area over Curve: " + CalculateAreaOverCurve(meanModelSeries);
     117      meanModelSeries.Tag = constantModel;
    115118      chart.Series.Add(meanModelSeries);
    116119
     
    133136      series.Points.Clear();
    134137      residuals.Sort();
     138      if (!residuals.Any() || residuals.All(double.IsNaN)) return;
    135139
    136140      series.Points.AddXY(0, 0);
     
    146150
    147151        point.XValue = residuals[i];
    148         point.YValues[0] = ((double)i+1) / residuals.Count;
     152        point.YValues[0] = ((double)i + 1) / residuals.Count;
    149153        point.ToolTip = "Error: " + point.XValue + "\n" + "Samples: " + point.YValues[0];
    150154        series.Points.Add(point);
     
    206210
    207211    private double CalculateAreaOverCurve(Series series) {
    208       if (series.Points.Count < 1) throw new ArgumentException("Could not calculate area under curve if less than 1 data points were given.");
     212      if (series.Points.Count < 1) return 0;
    209213
    210214      double auc = 0.0;
     
    224228      else UpdateChart();
    225229    }
     230
     231    #region Mean Model
     232    private void chart_MouseDown(object sender, MouseEventArgs e) {
     233      if (e.Clicks < 2) return;
     234      HitTestResult result = chart.HitTest(e.X, e.Y);
     235      if (result.ChartElementType != ChartElementType.LegendItem) return;
     236      if (result.Series.Name != constantModel.Name) return;
     237
     238      MainFormManager.MainForm.ShowContent((IRegressionSolution)result.Series.Tag);
     239    }
     240
     241    private IRegressionSolution CreateConstantModel() {
     242      double averageTrainingTarget = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndizes).Average();
     243      var solution = new ConstantRegressionModel(averageTrainingTarget).CreateRegressionSolution(ProblemData);
     244      solution.Name = "Mean Model";
     245      return solution;
     246    }
     247    #endregion
    226248  }
    227249}
  • branches/RegressionBenchmarks/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionScatterPlotView.cs

    r6740 r7085  
    2020#endregion
    2121using System;
    22 using System.Collections.Generic;
    2322using System.Drawing;
    2423using System.Linq;
     
    172171        string targetVariableName = Content.ProblemData.TargetVariable;
    173172
    174         IEnumerable<double> predictedValues = null;
    175         IEnumerable<double> targetValues = null;
     173        double[] predictedValues = null;
     174        double[] targetValues = null;
    176175        switch (series.Name) {
    177176          case ALL_SERIES:
     
    188187            break;
    189188        }
    190         series.Points.DataBindXY(predictedValues, "", targetValues, "");
     189        if (predictedValues.Length == targetValues.Length)
     190          series.Points.DataBindXY(predictedValues, "", targetValues, "");
    191191        this.chart.Legends[series.Legend].ForeColor = Color.Black;
    192192        UpdateCursorInterval();
  • branches/RegressionBenchmarks/HeuristicLab.Problems.DataAnalysis.Views/3.4/Solution Views/ClassificationEnsembleSolutionView.cs

    r6666 r7085  
    3737    }
    3838
     39    protected override void OnContentChanged() {
     40      base.OnContentChanged();
     41      itemsListView.Items.Remove(itemsListView.FindItemWithText("Model: ClassificationEnsembleModel"));
     42    }
     43
    3944    #region drag & drop
    4045    protected override void itemsListView_DragDrop(object sender, DragEventArgs e) {
  • branches/RegressionBenchmarks/HeuristicLab.Problems.DataAnalysis.Views/3.4/Solution Views/RegressionEnsembleSolutionView.cs

    r6666 r7085  
    3737    }
    3838
     39    protected override void OnContentChanged() {
     40      base.OnContentChanged();
     41      itemsListView.Items.Remove(itemsListView.FindItemWithText("Model: RegressionEnsembleModel"));
     42    }
     43
    3944    #region drag & drop
    4045    protected override void itemsListView_DragDrop(object sender, DragEventArgs e) {
Note: See TracChangeset for help on using the changeset viewer.