Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/14/11 13:59:25 (13 years ago)
Author:
epitzer
Message:

#1530 integrate changes from trunk

Location:
branches/PersistenceSpeedUp
Files:
6 edited
4 copied

Legend:

Unmodified
Added
Removed
  • branches/PersistenceSpeedUp

  • branches/PersistenceSpeedUp/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/ClassificationSolutionConfusionMatrixView.cs

    r5975 r6760  
    2424using System.Linq;
    2525using System.Windows.Forms;
    26 using HeuristicLab.Core.Views;
    2726using HeuristicLab.MainForm;
    2827using HeuristicLab.MainForm.WindowsForms;
     
    3130  [View("Confusion Matrix")]
    3231  [Content(typeof(IClassificationSolution))]
    33   public partial class ClassificationSolutionConfusionMatrixView : ItemView, IClassificationSolutionEvaluationView {
     32  public partial class ClassificationSolutionConfusionMatrixView : DataAnalysisSolutionEvaluationView {
    3433    private const string TrainingSamples = "Training";
    3534    private const string TestSamples = "Test";
     
    7877          dataGridView.ColumnCount = 1;
    7978        } else {
    80           dataGridView.ColumnCount = Content.ProblemData.Classes;
    81           dataGridView.RowCount = Content.ProblemData.Classes;
     79          dataGridView.ColumnCount = Content.ProblemData.Classes + 1;
     80          dataGridView.RowCount = Content.ProblemData.Classes + 1;
    8281
    8382          int i = 0;
     
    8786            i++;
    8887          }
     88          dataGridView.Columns[i].HeaderText = "Actual not classified";
     89          dataGridView.Rows[i].HeaderCell.Value = "Predicted not classified";
     90
    8991          dataGridView.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.ColumnHeader);
    9092          dataGridView.AutoResizeRowHeadersWidth(DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders);
     
    100102        if (Content == null) return;
    101103
    102         double[,] confusionMatrix = new double[Content.ProblemData.Classes, Content.ProblemData.Classes];
     104        double[,] confusionMatrix = new double[Content.ProblemData.Classes + 1, Content.ProblemData.Classes + 1];
    103105        IEnumerable<int> rows;
    104106
     107        double[] predictedValues;
    105108        if (cmbSamples.SelectedItem.ToString() == TrainingSamples) {
    106109          rows = Content.ProblemData.TrainingIndizes;
     110          predictedValues = Content.EstimatedTrainingClassValues.ToArray();
    107111        } else if (cmbSamples.SelectedItem.ToString() == TestSamples) {
    108112          rows = Content.ProblemData.TestIndizes;
     113          predictedValues = Content.EstimatedTestClassValues.ToArray();
    109114        } else throw new InvalidOperationException();
     115
     116        double[] targetValues = Content.ProblemData.Dataset.GetDoubleValues(Content.ProblemData.TargetVariable, rows).ToArray();
    110117
    111118        Dictionary<double, int> classValueIndexMapping = new Dictionary<double, int>();
     
    116123        }
    117124
    118         double[] targetValues = Content.ProblemData.Dataset.GetEnumeratedVariableValues(Content.ProblemData.TargetVariable, rows).ToArray();
    119         double[] predictedValues = Content.GetEstimatedClassValues(rows).ToArray();
    120 
    121125        for (int i = 0; i < targetValues.Length; i++) {
    122126          double targetValue = targetValues[i];
    123127          double predictedValue = predictedValues[i];
    124           int targetIndex = classValueIndexMapping[targetValue];
    125           int predictedIndex = classValueIndexMapping[predictedValue];
     128          int targetIndex;
     129          int predictedIndex;
     130          if (!classValueIndexMapping.TryGetValue(targetValue, out targetIndex)) {
     131            targetIndex = Content.ProblemData.Classes;
     132          }
     133          if (!classValueIndexMapping.TryGetValue(predictedValue, out predictedIndex)) {
     134            predictedIndex = Content.ProblemData.Classes;
     135          }
    126136
    127137          confusionMatrix[predictedIndex, targetIndex] += 1;
  • branches/PersistenceSpeedUp/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/ClassificationSolutionEstimatedClassValuesView.cs

    r5975 r6760  
    2222using System.Linq;
    2323using System.Windows.Forms;
    24 using HeuristicLab.Core.Views;
    2524using HeuristicLab.Data;
    2625using HeuristicLab.Data.Views;
     
    3130  [View("Estimated Class Values")]
    3231  [Content(typeof(IClassificationSolution))]
    33   public partial class ClassificationSolutionEstimatedClassValuesView : ItemView, IClassificationSolutionEvaluationView {
    34     private const string TARGETVARIABLE_SERIES_NAME = "TargetVariable";
    35     private const string ESTIMATEDVALUES_SERIES_NAME = "EstimatedClassValues";
     32  public partial class ClassificationSolutionEstimatedClassValuesView : DataAnalysisSolutionEvaluationView {
     33    private const string TARGETVARIABLE_SERIES_NAME = "Target Variable";
     34    private const string ESTIMATEDVALUES_SERIES_NAME = "Estimated Class Values (all)";
     35    private const string ESTIMATEDVALUES_TRAINING_SERIES_NAME = "Estimated Class Values (training)";
     36    private const string ESTIMATEDVALUES_TEST_SERIES_NAME = "Estimated Class Values (test)";
    3637
    3738    public new IClassificationSolution Content {
    3839      get { return (IClassificationSolution)base.Content; }
    39       set {
    40         base.Content = value;
    41       }
     40      set { base.Content = value; }
    4241    }
    4342
    44     private StringConvertibleMatrixView matrixView;
     43    protected StringConvertibleMatrixView matrixView;
    4544
    4645    public ClassificationSolutionEstimatedClassValuesView()
     
    8079    }
    8180
    82     private void UpdateEstimatedValues() {
     81    protected virtual void UpdateEstimatedValues() {
    8382      if (InvokeRequired) Invoke((Action)UpdateEstimatedValues);
    8483      else {
    85         DoubleMatrix matrix = null;
     84        StringMatrix matrix = null;
    8685        if (Content != null) {
    87           double[,] values = new double[Content.ProblemData.Dataset.Rows, 2];
     86          string[,] values = new string[Content.ProblemData.Dataset.Rows, 5];
    8887
    89           double[] target = Content.ProblemData.Dataset.GetVariableValues(Content.ProblemData.TargetVariable);
     88          double[] target = Content.ProblemData.Dataset.GetDoubleValues(Content.ProblemData.TargetVariable).ToArray();
    9089          double[] estimated = Content.EstimatedClassValues.ToArray();
    9190          for (int row = 0; row < target.Length; row++) {
    92             values[row, 0] = target[row];
    93             values[row, 1] = estimated[row];
     91            values[row, 0] = row.ToString();
     92            values[row, 1] = target[row].ToString();
     93            values[row, 2] = estimated[row].ToString();
    9494          }
    9595
    96           matrix = new DoubleMatrix(values);
    97           matrix.ColumnNames = new string[] { TARGETVARIABLE_SERIES_NAME, ESTIMATEDVALUES_SERIES_NAME };
     96          var estimatedTraining = Content.EstimatedTrainingClassValues.GetEnumerator();
     97          estimatedTraining.MoveNext();
     98          foreach (var trainingRow in Content.ProblemData.TrainingIndizes) {
     99            values[trainingRow, 3] = estimatedTraining.Current.ToString();
     100            estimatedTraining.MoveNext();
     101          }
     102          var estimatedTest = Content.EstimatedTestClassValues.GetEnumerator();
     103          estimatedTest.MoveNext();
     104          foreach (var testRow in Content.ProblemData.TestIndizes) {
     105            values[testRow, 4] = estimatedTest.Current.ToString();
     106            estimatedTest.MoveNext();
     107          }
     108
     109          matrix = new StringMatrix(values);
     110          matrix.ColumnNames = new string[] { "Id", TARGETVARIABLE_SERIES_NAME, ESTIMATEDVALUES_SERIES_NAME, ESTIMATEDVALUES_TRAINING_SERIES_NAME, ESTIMATEDVALUES_TEST_SERIES_NAME };
     111          matrix.SortableView = true;
    98112        }
    99113        matrixView.Content = matrix;
  • branches/PersistenceSpeedUp/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/DiscriminantFunctionClassificationRocCurvesView.cs

    r5975 r6760  
    2828using System.Windows.Forms.DataVisualization.Charting;
    2929using HeuristicLab.Common;
    30 using HeuristicLab.Core.Views;
    3130using HeuristicLab.MainForm;
    3231using HeuristicLab.MainForm.WindowsForms;
     
    3433  [View("ROC Curves")]
    3534  [Content(typeof(IDiscriminantFunctionClassificationSolution))]
    36   public partial class DiscriminantFunctionClassificationRocCurvesView : ItemView, IDiscriminantFunctionClassificationSolutionEvaluationView {
     35  public partial class DiscriminantFunctionClassificationRocCurvesView : DataAnalysisSolutionEvaluationView {
    3736    private const string xAxisTitle = "False Positive Rate";
    3837    private const string yAxisTitle = "True Positive Rate";
     
    108107
    109108        double[] estimatedValues = Content.GetEstimatedValues(rows).ToArray();
    110         double[] targetClassValues = Content.ProblemData.Dataset.GetEnumeratedVariableValues(Content.ProblemData.TargetVariable, rows).ToArray();
     109        double[] targetClassValues = Content.ProblemData.Dataset.GetDoubleValues(Content.ProblemData.TargetVariable, rows).ToArray();
    111110        double minThreshold = estimatedValues.Min();
    112111        double maxThreshold = estimatedValues.Max();
  • branches/PersistenceSpeedUp/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/DiscriminantFunctionClassificationSolutionEstimatedClassValuesView.cs

    r5975 r6760  
    2222using System.Linq;
    2323using System.Windows.Forms;
    24 using HeuristicLab.Core.Views;
    2524using HeuristicLab.Data;
    26 using HeuristicLab.Data.Views;
    2725using HeuristicLab.MainForm;
    2826using HeuristicLab.MainForm.WindowsForms;
     
    3129  [View("Estimated Class Values")]
    3230  [Content(typeof(IDiscriminantFunctionClassificationSolution))]
    33   public partial class DiscriminantFunctionClassificationSolutionEstimatedClassValuesView : ItemView, IDiscriminantFunctionClassificationSolutionEvaluationView {
     31  public partial class DiscriminantFunctionClassificationSolutionEstimatedClassValuesView : ClassificationSolutionEstimatedClassValuesView {
    3432    private const string TargetClassValuesSeriesname = "TargetVariable";
    3533    private const string EstimatedClassValuesSeriesName = "EstimatedClassValues";
     
    3836    public new IDiscriminantFunctionClassificationSolution Content {
    3937      get { return (IDiscriminantFunctionClassificationSolution)base.Content; }
    40       set {
    41         base.Content = value;
    42       }
     38      set { base.Content = value; }
    4339    }
    44 
    45     private StringConvertibleMatrixView matrixView;
    4640
    4741    public DiscriminantFunctionClassificationSolutionEstimatedClassValuesView()
    4842      : base() {
    4943      InitializeComponent();
    50       matrixView = new StringConvertibleMatrixView();
    51       matrixView.ShowRowsAndColumnsTextBox = false;
    52       matrixView.ShowStatisticalInformation = false;
    53       matrixView.Dock = DockStyle.Fill;
    54       this.Controls.Add(matrixView);
    5544    }
    5645
    57     #region events
    58     protected override void RegisterContentEvents() {
    59       base.RegisterContentEvents();
    60       Content.ModelChanged += new EventHandler(Content_ModelChanged);
    61       Content.ProblemDataChanged += new EventHandler(Content_ProblemDataChanged);
    62     }
    63 
    64     protected override void DeregisterContentEvents() {
    65       base.DeregisterContentEvents();
    66       Content.ModelChanged -= new EventHandler(Content_ModelChanged);
    67       Content.ProblemDataChanged -= new EventHandler(Content_ProblemDataChanged);
    68     }
    69 
    70     private void Content_ProblemDataChanged(object sender, EventArgs e) {
    71       OnContentChanged();
    72     }
    73 
    74     private void Content_ModelChanged(object sender, EventArgs e) {
    75       OnContentChanged();
    76     }
    77 
    78     protected override void OnContentChanged() {
    79       base.OnContentChanged();
    80       UpdateEstimatedValues();
    81     }
    82 
    83     private void UpdateEstimatedValues() {
     46    protected override void UpdateEstimatedValues() {
    8447      if (InvokeRequired) Invoke((Action)UpdateEstimatedValues);
    8548      else {
    86         DoubleMatrix matrix = null;
     49        StringMatrix matrix = null;
    8750        if (Content != null) {
    88           double[,] values = new double[Content.ProblemData.Dataset.Rows, 3];
     51          string[,] values = new string[Content.ProblemData.Dataset.Rows, 4];
    8952
    90           double[] target = Content.ProblemData.Dataset.GetVariableValues(Content.ProblemData.TargetVariable);
     53          double[] target = Content.ProblemData.Dataset.GetDoubleValues(Content.ProblemData.TargetVariable).ToArray();
    9154          double[] estimatedClassValues = Content.EstimatedClassValues.ToArray();
    9255          double[] estimatedValues = Content.EstimatedValues.ToArray();
    9356          for (int row = 0; row < target.Length; row++) {
    94             values[row, 0] = target[row];
    95             values[row, 1] = estimatedClassValues[row];
    96             values[row, 2] = estimatedValues[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();
    9761          }
    9862
    99           matrix = new DoubleMatrix(values);
    100           matrix.ColumnNames = new string[] { TargetClassValuesSeriesname, EstimatedClassValuesSeriesName, EstimatedValuesSeriesName };
     63          matrix = new StringMatrix(values);
     64          matrix.ColumnNames = new string[] { "Id", TargetClassValuesSeriesname, EstimatedClassValuesSeriesName, EstimatedValuesSeriesName };
     65          matrix.SortableView = true;
    10166        }
    10267        matrixView.Content = matrix;
    10368      }
    10469    }
    105     #endregion
    10670  }
    10771}
  • branches/PersistenceSpeedUp/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/DiscriminantFunctionClassificationSolutionThresholdView.cs

    r5975 r6760  
    2727using System.Windows.Forms.DataVisualization.Charting;
    2828using HeuristicLab.Common;
    29 using HeuristicLab.Core.Views;
    3029using HeuristicLab.MainForm;
    3130using HeuristicLab.MainForm.WindowsForms;
     
    3332namespace HeuristicLab.Problems.DataAnalysis.Views {
    3433  [View("Classification Threshold")]
    35   [Content(typeof(IDiscriminantFunctionClassificationSolution), true)]
    36   public sealed partial class DiscriminantFunctionClassificationSolutionThresholdView : ItemView, IDiscriminantFunctionClassificationSolutionEvaluationView {
     34  [Content(typeof(IDiscriminantFunctionClassificationSolution), false)]
     35  public sealed partial class DiscriminantFunctionClassificationSolutionThresholdView : DataAnalysisSolutionEvaluationView {
    3736    private const double TrainingAxisValue = 0.0;
    3837    private const double TestAxisValue = 10.0;
     
    136135    private void FillSeriesWithDataPoints(Series series) {
    137136      List<double> estimatedValues = Content.EstimatedValues.ToList();
     137      var targetValues = Content.ProblemData.Dataset.GetDoubleValues(Content.ProblemData.TargetVariable).ToList();
     138
    138139      foreach (int row in Content.ProblemData.TrainingIndizes) {
    139140        double estimatedValue = estimatedValues[row];
    140         double targetValue = Content.ProblemData.Dataset[Content.ProblemData.TargetVariable, row];
     141        double targetValue = targetValues[row];
    141142        if (targetValue.IsAlmost((double)series.Tag)) {
    142143          double jitterValue = random.NextDouble() * 2.0 - 1.0;
     
    151152      foreach (int row in Content.ProblemData.TestIndizes) {
    152153        double estimatedValue = estimatedValues[row];
    153         double targetValue = Content.ProblemData.Dataset[Content.ProblemData.TargetVariable, row];
    154         if (targetValue == (double)series.Tag) {
     154        double targetValue = targetValues[row];
     155        if (targetValue.IsAlmost((double)series.Tag)) {
    155156          double jitterValue = random.NextDouble() * 2.0 - 1.0;
    156157          DataPoint point = new DataPoint();
Note: See TracChangeset for help on using the changeset viewer.