Free cookie consent management tool by TermsFeed Policy Generator

Changeset 6672 for trunk


Ignore:
Timestamp:
08/19/11 11:12:25 (13 years ago)
Author:
mkommend
Message:

#1592: Implemented new estimated class values view for ClassificationEnsembleSolutions.

Location:
trunk/sources
Files:
7 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/ClassificationEnsembleSolutionEstimatedClassValuesView.Designer.cs

    r6661 r6672  
    2020#endregion
    2121namespace HeuristicLab.Problems.DataAnalysis.Views {
    22   partial class DiscriminantFunctionClassificationSolutionEstimatedClassValuesView {
     22  partial class ClassificationEnsembleSolutionEstimatedClassValuesView {
    2323    /// <summary>
    2424    /// Required designer variable.
     
    4444    /// </summary>
    4545    private void InitializeComponent() {
     46      this.problemView1 = new HeuristicLab.Optimization.Views.ProblemView();
     47      this.SamplesComboBox = new System.Windows.Forms.ComboBox();
    4648      this.SuspendLayout();
    4749      //
    48       // EstimatedValuesView
     50      // matrixView
    4951      //
    50       this.AllowDrop = true;
     52      this.matrixView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     53            | System.Windows.Forms.AnchorStyles.Left)
     54            | System.Windows.Forms.AnchorStyles.Right)));
     55      this.matrixView.Dock = System.Windows.Forms.DockStyle.None;
     56      this.matrixView.Location = new System.Drawing.Point(3, 31);
     57      this.matrixView.Size = new System.Drawing.Size(304, 251);
     58      //
     59      // problemView1
     60      //
     61      this.problemView1.Caption = "Problem View";
     62      this.problemView1.Content = null;
     63      this.problemView1.Location = new System.Drawing.Point(1147, 687);
     64      this.problemView1.Name = "problemView1";
     65      this.problemView1.ReadOnly = false;
     66      this.problemView1.Size = new System.Drawing.Size(490, 353);
     67      this.problemView1.TabIndex = 1;
     68      //
     69      // SamplesComboBox
     70      //
     71      this.SamplesComboBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
     72            | System.Windows.Forms.AnchorStyles.Right)));
     73      this.SamplesComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
     74      this.SamplesComboBox.FormattingEnabled = true;
     75      this.SamplesComboBox.Location = new System.Drawing.Point(4, 4);
     76      this.SamplesComboBox.Name = "SamplesComboBox";
     77      this.SamplesComboBox.Size = new System.Drawing.Size(303, 21);
     78      this.SamplesComboBox.TabIndex = 2;
     79      this.SamplesComboBox.SelectedIndexChanged += new System.EventHandler(this.SamplesComboBox_SelectedIndexChanged);
     80      //
     81      // ClassificationEnsembleSolutionEstimatedClassValuesView
     82      //
    5183      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    5284      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    53       this.Name = "EstimatedValuesView";
    54       this.Size = new System.Drawing.Size(310, 285);
     85      this.Controls.Add(this.SamplesComboBox);
     86      this.Controls.Add(this.problemView1);
     87      this.Name = "ClassificationEnsembleSolutionEstimatedClassValuesView";
     88      this.Controls.SetChildIndex(this.matrixView, 0);
     89      this.Controls.SetChildIndex(this.problemView1, 0);
     90      this.Controls.SetChildIndex(this.SamplesComboBox, 0);
    5591      this.ResumeLayout(false);
    5692
     
    5995    #endregion
    6096
     97    private Optimization.Views.ProblemView problemView1;
     98    private System.Windows.Forms.ComboBox SamplesComboBox;
     99
    61100  }
    62101}
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/ClassificationEnsembleSolutionEstimatedClassValuesView.cs

    r6661 r6672  
    2020#endregion
    2121using System;
     22using System.Collections.Generic;
    2223using System.Linq;
    2324using System.Windows.Forms;
     
    2829namespace HeuristicLab.Problems.DataAnalysis.Views {
    2930  [View("Estimated Class Values")]
    30   [Content(typeof(IDiscriminantFunctionClassificationSolution))]
    31   public partial class DiscriminantFunctionClassificationSolutionEstimatedClassValuesView : ClassificationSolutionEstimatedClassValuesView {
    32     private const string TargetClassValuesSeriesname = "TargetVariable";
    33     private const string EstimatedClassValuesSeriesName = "EstimatedClassValues";
    34     private const string EstimatedValuesSeriesName = "EstimatedValues";
     31  [Content(typeof(ClassificationEnsembleSolution))]
     32  public partial class ClassificationEnsembleSolutionEstimatedClassValuesView :
     33    ClassificationSolutionEstimatedClassValuesView {
     34    private const string RowColumnName = "Row";
     35    private const string TargetClassValuesColumnName = "TargetVariable";
     36    private const string EstimatedClassValuesColumnName = "EstimatedClassValues";
     37    private const string ConfidenceColumnName = "Confidence";
    3538
    36     public new IDiscriminantFunctionClassificationSolution Content {
    37       get { return (IDiscriminantFunctionClassificationSolution)base.Content; }
     39    private const string SamplesComboBoxAllSamples = "All Samples";
     40    private const string SamplesComboBoxTrainingSamples = "Training Samples";
     41    private const string SamplesComboBoxTestSamples = "Test Samples";
     42
     43    public new ClassificationEnsembleSolution Content {
     44      get { return (ClassificationEnsembleSolution)base.Content; }
    3845      set { base.Content = value; }
    3946    }
    4047
    41     public DiscriminantFunctionClassificationSolutionEstimatedClassValuesView()
     48    public ClassificationEnsembleSolutionEstimatedClassValuesView()
    4249      : base() {
    4350      InitializeComponent();
     51      SamplesComboBox.Items.AddRange(new string[] { SamplesComboBoxAllSamples, SamplesComboBoxTrainingSamples, SamplesComboBoxTestSamples });
     52      SamplesComboBox.SelectedIndex = 0;
     53    }
     54
     55    private void SamplesComboBox_SelectedIndexChanged(object sender, EventArgs e) {
     56      UpdateEstimatedValues();
    4457    }
    4558
    4659    protected override void UpdateEstimatedValues() {
    47       if (InvokeRequired) Invoke((Action)UpdateEstimatedValues);
    48       else {
    49         StringMatrix matrix = null;
    50         if (Content != null) {
    51           string[,] values = new string[Content.ProblemData.Dataset.Rows, 4];
     60      if (InvokeRequired) {
     61        Invoke((Action)UpdateEstimatedValues);
     62        return;
     63      }
     64      if (Content == null) {
     65        matrixView.Content = null;
     66        return;
     67      }
    5268
    53           double[] target = Content.ProblemData.Dataset.GetVariableValues(Content.ProblemData.TargetVariable);
    54           double[] estimatedClassValues = Content.EstimatedClassValues.ToArray();
    55           double[] estimatedValues = Content.EstimatedValues.ToArray();
    56           for (int row = 0; row < target.Length; row++) {
    57             values[row, 0] = row.ToString();
    58             values[row, 1] = target[row].ToString();
    59             values[row, 2] = estimatedClassValues[row].ToString();
    60             values[row, 3] = estimatedValues[row].ToString();
     69      int[] indizes;
     70      double[] estimatedClassValues;
     71
     72      switch (SamplesComboBox.SelectedItem.ToString()) {
     73        case SamplesComboBoxAllSamples: {
     74            indizes = Enumerable.Range(0, Content.ProblemData.Dataset.Rows).ToArray();
     75            estimatedClassValues = Content.EstimatedClassValues.ToArray();
     76            break;
    6177          }
     78        case SamplesComboBoxTrainingSamples: {
     79            indizes = Content.ProblemData.TrainingIndizes.ToArray();
     80            estimatedClassValues = Content.EstimatedTrainingClassValues.ToArray();
     81            break;
     82          }
     83        case SamplesComboBoxTestSamples: {
     84            indizes = Content.ProblemData.TestIndizes.ToArray();
     85            estimatedClassValues = Content.EstimatedTestClassValues.ToArray();
     86            break;
     87          }
     88        default:
     89          throw new ArgumentException();
     90      }
    6291
    63           matrix = new StringMatrix(values);
    64           matrix.ColumnNames = new string[] { "Id", TargetClassValuesSeriesname, EstimatedClassValuesSeriesName, EstimatedValuesSeriesName };
    65           matrix.SortableView = true;
     92      int classValuesCount = Content.ProblemData.ClassValues.Count;
     93      int modelCount = Content.Model.Models.Count();
     94      string[,] values = new string[indizes.Length, 4 + classValuesCount + modelCount];
     95      double[] target = Content.ProblemData.Dataset.GetVariableValues(Content.ProblemData.TargetVariable);
     96      List<List<double?>> estimatedValuesVector = GetEstimatedValues(SamplesComboBox.SelectedItem.ToString(), indizes,
     97                                                            Content.ClassificationSolutions);
     98
     99      for (int i = 0; i < indizes.Length; i++) {
     100        int row = indizes[i];
     101        values[i, 0] = row.ToString();
     102        values[i, 1] = target[i].ToString();
     103        values[i, 2] = estimatedClassValues[i].ToString();
     104        var groups = estimatedValuesVector[i].GroupBy(x => x).Select(g => new { Key = g.Key, Count = g.Count() }).ToList();
     105        var estimationCount = groups.Where(g => g.Key != null).Select(g => g.Count).Sum();
     106        values[i, 3] = (((double)groups.Where(g => g.Key == estimatedClassValues[i]).Single().Count) / estimationCount).ToString();
     107        for (int classIndex = 0; classIndex < Content.ProblemData.ClassValues.Count; classIndex++) {
     108          var group = groups.Where(g => g.Key == Content.ProblemData.ClassValues[classIndex]).SingleOrDefault();
     109          if (group == null) values[i, 4 + classIndex] = 0.ToString();
     110          else values[i, 4 + classIndex] = group.Count.ToString();
    66111        }
    67         matrixView.Content = matrix;
     112        for (int modelIndex = 0; modelIndex < estimatedValuesVector[i].Count; modelIndex++) {
     113          values[i, 4 + classValuesCount + modelIndex] = estimatedValuesVector[i][modelIndex] == null
     114                                                           ? string.Empty
     115                                                           : estimatedValuesVector[i][modelIndex].ToString();
     116        }
     117
    68118      }
     119
     120      StringMatrix matrix = new StringMatrix(values);
     121      List<string> columnNames = new List<string>() { "Id", TargetClassValuesColumnName, EstimatedClassValuesColumnName, ConfidenceColumnName };
     122      columnNames.AddRange(Content.ProblemData.ClassNames);
     123      columnNames.AddRange(Content.Model.Models.Select(m => m.Name));
     124      matrix.ColumnNames = columnNames;
     125      matrix.SortableView = true;
     126      matrixView.Content = matrix;
    69127    }
     128
     129    private List<List<double?>> GetEstimatedValues(string samplesSelection, int[] rows, IEnumerable<IClassificationSolution> solutions) {
     130      List<List<double?>> values = new List<List<double?>>();
     131      int solutionIndex = 0;
     132      foreach (var solution in solutions) {
     133        double[] estimation = solution.GetEstimatedClassValues(rows).ToArray();
     134        for (int i = 0; i < rows.Length; i++) {
     135          var row = rows[i];
     136          if (solutionIndex == 0) values.Add(new List<double?>());
     137
     138          if (samplesSelection == SamplesComboBoxAllSamples)
     139            values[i].Add(estimation[i]);
     140          else if (samplesSelection == SamplesComboBoxTrainingSamples && solution.ProblemData.IsTrainingSample(row))
     141            values[i].Add(estimation[i]);
     142          else if (samplesSelection == SamplesComboBoxTestSamples && solution.ProblemData.IsTestSample(row))
     143            values[i].Add(estimation[i]);
     144          else
     145            values[i].Add(null);
     146        }
     147        solutionIndex++;
     148      }
     149      return values;
     150    }
     151
     152
     153
    70154  }
    71155}
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/HeuristicLab.Problems.DataAnalysis.Views-3.4.csproj

    r6666 r6672  
    110110  </ItemGroup>
    111111  <ItemGroup>
     112    <Compile Include="Classification\ClassificationEnsembleSolutionEstimatedClassValuesView.cs">
     113      <SubType>UserControl</SubType>
     114    </Compile>
     115    <Compile Include="Classification\ClassificationEnsembleSolutionEstimatedClassValuesView.Designer.cs">
     116      <DependentUpon>ClassificationEnsembleSolutionEstimatedClassValuesView.cs</DependentUpon>
     117    </Compile>
    112118    <Compile Include="Classification\ClassificationEnsembleSolutionModelView.cs">
    113119      <SubType>UserControl</SubType>
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationEnsembleProblemData.cs

    r6666 r6672  
    2121
    2222using System.Collections.Generic;
    23 using System.Linq;
    2423using HeuristicLab.Common;
    2524using HeuristicLab.Core;
     
    3332  public class ClassificationEnsembleProblemData : ClassificationProblemData {
    3433
    35     public override IEnumerable<int> TrainingIndizes {
    36       get { return Enumerable.Range(TrainingPartition.Start, TrainingPartition.End - TrainingPartition.Start); }
    37     }
    38     public override IEnumerable<int> TestIndizes {
    39       get { return Enumerable.Range(TestPartition.Start, TestPartition.End - TestPartition.Start); }
     34    public override bool IsTrainingSample(int index) {
     35      return index >= 0 && index < Dataset.Rows &&
     36             TrainingPartition.Start <= index && index < TrainingPartition.End;
    4037    }
    4138
    42     private static ClassificationEnsembleProblemData emptyProblemData;
     39    public override bool IsTestSample(int index) {
     40      return index >= 0 && index < Dataset.Rows &&
     41             TestPartition.Start <= index && index < TestPartition.End;
     42    }
     43
     44    private static readonly ClassificationEnsembleProblemData emptyProblemData;
    4345    public static ClassificationEnsembleProblemData EmptyProblemData {
    4446      get { return emptyProblemData; }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationProblemData.cs

    r6666 r6672  
    171171     {1176881,7,5,3,7,4,10,7,5,5,4        }
    172172};
    173     private static Dataset defaultDataset;
    174     private static IEnumerable<string> defaultAllowedInputVariables;
    175     private static string defaultTargetVariable;
    176 
    177     private static ClassificationProblemData emptyProblemData;
     173    private static readonly Dataset defaultDataset;
     174    private static readonly IEnumerable<string> defaultAllowedInputVariables;
     175    private static readonly string defaultTargetVariable;
     176
     177    private static readonly ClassificationProblemData emptyProblemData;
    178178    public static ClassificationProblemData EmptyProblemData {
    179179      get { return EmptyProblemData; }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/DataAnalysisProblemData.cs

    r6666 r6672  
    7878      get {
    7979        return Enumerable.Range(TrainingPartition.Start, TrainingPartition.End - TrainingPartition.Start)
    80                          .Where(i => i >= 0 && i < Dataset.Rows && (i < TestPartition.Start || TestPartition.End <= i));
     80                         .Where(IsTrainingSample);
    8181      }
    8282    }
     
    8484      get {
    8585        return Enumerable.Range(TestPartition.Start, TestPartition.End - TestPartition.Start)
    86            .Where(i => i >= 0 && i < Dataset.Rows);
     86           .Where(IsTestSample);
    8787      }
     88    }
     89
     90    public virtual bool IsTrainingSample(int index) {
     91      return index >= 0 && index < Dataset.Rows &&
     92        TrainingPartition.Start <= index && index < TrainingPartition.End &&
     93        (index < TestPartition.Start || TestPartition.End <= index);
     94    }
     95
     96    public virtual bool IsTestSample(int index) {
     97      return index >= 0 && index < Dataset.Rows &&
     98             TestPartition.Start <= index && index < TestPartition.End;
    8899    }
    89100    #endregion
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionEnsembleProblemData.cs

    r6666 r6672  
    2121
    2222using System.Collections.Generic;
    23 using System.Linq;
    2423using HeuristicLab.Common;
    2524using HeuristicLab.Core;
     
    3332  public sealed class RegressionEnsembleProblemData : RegressionProblemData {
    3433
    35     public override IEnumerable<int> TrainingIndizes {
    36       get {
    37         return Enumerable.Range(TrainingPartition.Start, TrainingPartition.End - TrainingPartition.Start);
    38       }
     34    public override bool IsTrainingSample(int index) {
     35      return index >= 0 && index < Dataset.Rows &&
     36             TrainingPartition.Start <= index && index < TrainingPartition.End;
    3937    }
    4038
    41     public override IEnumerable<int> TestIndizes {
    42       get {
    43         return Enumerable.Range(TestPartition.Start, TestPartition.End - TestPartition.Start);
    44       }
     39    public override bool IsTestSample(int index) {
     40      return index >= 0 && index < Dataset.Rows &&
     41             TestPartition.Start <= index && index < TestPartition.End;
    4542    }
    4643
    47     private static RegressionEnsembleProblemData emptyProblemData;
     44    private static readonly RegressionEnsembleProblemData emptyProblemData;
    4845    public new static RegressionEnsembleProblemData EmptyProblemData {
    4946      get { return emptyProblemData; }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionProblemData.cs

    r6666 r6672  
    6464          {0.83763905,  0.468046718}
    6565    };
    66     private static Dataset defaultDataset;
    67     private static IEnumerable<string> defaultAllowedInputVariables;
    68     private static string defaultTargetVariable;
     66    private static readonly Dataset defaultDataset;
     67    private static readonly IEnumerable<string> defaultAllowedInputVariables;
     68    private static readonly string defaultTargetVariable;
    6969
    70     private static RegressionProblemData emptyProblemData;
     70    private static readonly RegressionProblemData emptyProblemData;
    7171    public static RegressionProblemData EmptyProblemData {
    7272      get { return emptyProblemData; }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/IDataAnalysisProblemData.cs

    r6666 r6672  
    3939    IEnumerable<int> TestIndizes { get; }
    4040
     41    bool IsTrainingSample(int index);
     42    bool IsTestSample(int index);
     43
    4144    event EventHandler Changed;
    4245  }
Note: See TracChangeset for help on using the changeset viewer.