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:
2 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  }
Note: See TracChangeset for help on using the changeset viewer.