Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/16/11 12:00:36 (13 years ago)
Author:
mkommend
Message:

#1479: Integrated trunk changes.

Location:
branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis.Views/3.4
Files:
17 edited

Legend:

Unmodified
Added
Removed
  • branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/ClassificationEnsembleSolutionEstimatedClassValuesView.Designer.cs

    r6675 r6784  
    4444    /// </summary>
    4545    private void InitializeComponent() {
    46       this.problemView1 = new HeuristicLab.Optimization.Views.ProblemView();
    4746      this.SamplesComboBox = new System.Windows.Forms.ComboBox();
    4847      this.SuspendLayout();
     
    5655      this.matrixView.Location = new System.Drawing.Point(3, 31);
    5756      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;
    6857      //
    6958      // SamplesComboBox
     
    8473      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    8574      this.Controls.Add(this.SamplesComboBox);
    86       this.Controls.Add(this.problemView1);
    8775      this.Name = "ClassificationEnsembleSolutionEstimatedClassValuesView";
    8876      this.Controls.SetChildIndex(this.matrixView, 0);
    89       this.Controls.SetChildIndex(this.problemView1, 0);
    9077      this.Controls.SetChildIndex(this.SamplesComboBox, 0);
    9178      this.ResumeLayout(false);
     
    9582    #endregion
    9683
    97     private Optimization.Views.ProblemView problemView1;
    9884    private System.Windows.Forms.ComboBox SamplesComboBox;
    9985
  • branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/ClassificationEnsembleSolutionEstimatedClassValuesView.cs

    r6675 r6784  
    2121using System;
    2222using System.Collections.Generic;
     23using System.Drawing;
    2324using System.Linq;
    2425using System.Windows.Forms;
     
    3334    ClassificationSolutionEstimatedClassValuesView {
    3435    private const string RowColumnName = "Row";
    35     private const string TargetClassValuesColumnName = "TargetVariable";
    36     private const string EstimatedClassValuesColumnName = "EstimatedClassValues";
     36    private const string TargetClassValuesColumnName = "Target Variable";
     37    private const string EstimatedClassValuesColumnName = "Estimated Class Values";
     38    private const string CorrectClassificationColumnName = "Correct Classification";
    3739    private const string ConfidenceColumnName = "Confidence";
    3840
     
    5153      SamplesComboBox.Items.AddRange(new string[] { SamplesComboBoxAllSamples, SamplesComboBoxTrainingSamples, SamplesComboBoxTestSamples });
    5254      SamplesComboBox.SelectedIndex = 0;
     55      matrixView.DataGridView.RowPrePaint += new DataGridViewRowPrePaintEventHandler(DataGridView_RowPrePaint);
    5356    }
     57
     58
    5459
    5560    private void SamplesComboBox_SelectedIndexChanged(object sender, EventArgs e) {
     
    9297      int classValuesCount = Content.ProblemData.ClassValues.Count;
    9398      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);
     99      string[,] values = new string[indizes.Length, 5 + classValuesCount + modelCount];
     100      double[] target = Content.ProblemData.Dataset.GetDoubleValues(Content.ProblemData.TargetVariable).ToArray();
    96101      List<List<double?>> estimatedValuesVector = GetEstimatedValues(SamplesComboBox.SelectedItem.ToString(), indizes,
    97102                                                            Content.ClassificationSolutions);
     
    102107        values[i, 1] = target[i].ToString();
    103108        values[i, 2] = estimatedClassValues[i].ToString();
     109        values[i, 3] = (target[i] == estimatedClassValues[i]).ToString();
    104110        var groups = estimatedValuesVector[i].GroupBy(x => x).Select(g => new { Key = g.Key, Count = g.Count() }).ToList();
    105111        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();
     112        values[i, 4] = (((double)groups.Where(g => g.Key == estimatedClassValues[i]).Single().Count) / estimationCount).ToString();
    107113        for (int classIndex = 0; classIndex < Content.ProblemData.ClassValues.Count; classIndex++) {
    108114          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();
     115          if (group == null) values[i, 5 + classIndex] = 0.ToString();
     116          else values[i, 5 + classIndex] = group.Count.ToString();
    111117        }
    112118        for (int modelIndex = 0; modelIndex < estimatedValuesVector[i].Count; modelIndex++) {
    113           values[i, 4 + classValuesCount + modelIndex] = estimatedValuesVector[i][modelIndex] == null
     119          values[i, 5 + classValuesCount + modelIndex] = estimatedValuesVector[i][modelIndex] == null
    114120                                                           ? string.Empty
    115121                                                           : estimatedValuesVector[i][modelIndex].ToString();
     
    119125
    120126      StringMatrix matrix = new StringMatrix(values);
    121       List<string> columnNames = new List<string>() { "Id", TargetClassValuesColumnName, EstimatedClassValuesColumnName, ConfidenceColumnName };
     127      List<string> columnNames = new List<string>() { "Id", TargetClassValuesColumnName, EstimatedClassValuesColumnName, CorrectClassificationColumnName, ConfidenceColumnName };
    122128      columnNames.AddRange(Content.ProblemData.ClassNames);
    123129      columnNames.AddRange(Content.Model.Models.Select(m => m.Name));
     
    125131      matrix.SortableView = true;
    126132      matrixView.Content = matrix;
     133      UpdateColoringOfRows();
    127134    }
    128135
     
    150157    }
    151158
     159    private void DataGridView_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e) {
     160      if (InvokeRequired) {
     161        Invoke(new EventHandler<DataGridViewRowPrePaintEventArgs>(DataGridView_RowPrePaint), sender, e);
     162        return;
     163      }
     164      bool correctClassified = bool.Parse(matrixView.DataGridView[3, e.RowIndex].Value.ToString());
     165      matrixView.DataGridView.Rows[e.RowIndex].DefaultCellStyle.ForeColor = correctClassified ? Color.MediumSeaGreen : Color.Red;
     166    }
    152167
    153 
     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);
     179    }
    154180  }
    155181}
  • branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/ClassificationSolutionConfusionMatrixView.cs

    r6647 r6784  
    114114        } else throw new InvalidOperationException();
    115115
    116         double[] targetValues = Content.ProblemData.Dataset.GetEnumeratedVariableValues(Content.ProblemData.TargetVariable, rows).ToArray();
     116        double[] targetValues = Content.ProblemData.Dataset.GetDoubleValues(Content.ProblemData.TargetVariable, rows).ToArray();
    117117
    118118        Dictionary<double, int> classValueIndexMapping = new Dictionary<double, int>();
  • branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/ClassificationSolutionEstimatedClassValuesView.cs

    r6647 r6784  
    8686          string[,] values = new string[Content.ProblemData.Dataset.Rows, 5];
    8787
    88           double[] target = Content.ProblemData.Dataset.GetVariableValues(Content.ProblemData.TargetVariable);
     88          double[] target = Content.ProblemData.Dataset.GetDoubleValues(Content.ProblemData.TargetVariable).ToArray();
    8989          double[] estimated = Content.EstimatedClassValues.ToArray();
    9090          for (int row = 0; row < target.Length; row++) {
  • branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/DiscriminantFunctionClassificationRocCurvesView.cs

    r6647 r6784  
    107107
    108108        double[] estimatedValues = Content.GetEstimatedValues(rows).ToArray();
    109         double[] targetClassValues = Content.ProblemData.Dataset.GetEnumeratedVariableValues(Content.ProblemData.TargetVariable, rows).ToArray();
     109        double[] targetClassValues = Content.ProblemData.Dataset.GetDoubleValues(Content.ProblemData.TargetVariable, rows).ToArray();
    110110        double minThreshold = estimatedValues.Min();
    111111        double maxThreshold = estimatedValues.Max();
  • branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/DiscriminantFunctionClassificationSolutionEstimatedClassValuesView.cs

    r6647 r6784  
    5151          string[,] values = new string[Content.ProblemData.Dataset.Rows, 4];
    5252
    53           double[] target = Content.ProblemData.Dataset.GetVariableValues(Content.ProblemData.TargetVariable);
     53          double[] target = Content.ProblemData.Dataset.GetDoubleValues(Content.ProblemData.TargetVariable).ToArray();
    5454          double[] estimatedClassValues = Content.EstimatedClassValues.ToArray();
    5555          double[] estimatedValues = Content.EstimatedValues.ToArray();
  • branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/DiscriminantFunctionClassificationSolutionThresholdView.cs

    r6647 r6784  
    3232namespace HeuristicLab.Problems.DataAnalysis.Views {
    3333  [View("Classification Threshold")]
    34   [Content(typeof(IDiscriminantFunctionClassificationSolution), true)]
     34  [Content(typeof(IDiscriminantFunctionClassificationSolution), false)]
    3535  public sealed partial class DiscriminantFunctionClassificationSolutionThresholdView : DataAnalysisSolutionEvaluationView {
    3636    private const double TrainingAxisValue = 0.0;
     
    135135    private void FillSeriesWithDataPoints(Series series) {
    136136      List<double> estimatedValues = Content.EstimatedValues.ToList();
     137      var targetValues = Content.ProblemData.Dataset.GetDoubleValues(Content.ProblemData.TargetVariable).ToList();
     138
    137139      foreach (int row in Content.ProblemData.TrainingIndizes) {
    138140        double estimatedValue = estimatedValues[row];
    139         double targetValue = Content.ProblemData.Dataset[Content.ProblemData.TargetVariable, row];
     141        double targetValue = targetValues[row];
    140142        if (targetValue.IsAlmost((double)series.Tag)) {
    141143          double jitterValue = random.NextDouble() * 2.0 - 1.0;
     
    150152      foreach (int row in Content.ProblemData.TestIndizes) {
    151153        double estimatedValue = estimatedValues[row];
    152         double targetValue = Content.ProblemData.Dataset[Content.ProblemData.TargetVariable, row];
    153         if (targetValue == (double)series.Tag) {
     154        double targetValue = targetValues[row];
     155        if (targetValue.IsAlmost((double)series.Tag)) {
    154156          double jitterValue = random.NextDouble() * 2.0 - 1.0;
    155157          DataPoint point = new DataPoint();
  • branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis.Views/3.4/Clustering/ClusteringSolutionEstimatedClusterView.cs

    r6647 r6784  
    8585          int[] clusters = Content.Model.GetClusterValues(Content.ProblemData.Dataset, Enumerable.Range(0, Content.ProblemData.Dataset.Rows)).ToArray();
    8686          var dataset = Content.ProblemData.Dataset;
    87           int columns = Content.ProblemData.AllowedInputVariables.Count() + 1;
    88           var columnsIndixes = Content.ProblemData.AllowedInputVariables.Select(x => dataset.GetVariableIndex(x)).ToList();
     87          int columns = Content.ProblemData.AllowedInputVariables.Count() + 1;         
    8988
    9089          double[,] values = new double[dataset.Rows, columns];
     
    9392
    9493            int column = 1;
    95             foreach (int columnIndex in columnsIndixes) {
    96               values[row, column] = dataset[row, columnIndex];
     94            foreach (var columnName in Content.ProblemData.AllowedInputVariables) {
     95              values[row, column] = dataset.GetDoubleValue(columnName, row);
    9796              column++;
    9897            }
  • branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionErrorCharacteristicsCurveView.cs

    r6647 r6784  
    139139        if (residuals[i] > chart.ChartAreas[0].AxisX.Maximum) {
    140140          point.XValue = chart.ChartAreas[0].AxisX.Maximum;
    141           point.YValues[0] = ((double)i - 1) / residuals.Count;
     141          point.YValues[0] = ((double)i) / residuals.Count;
    142142          point.ToolTip = "Error: " + point.XValue + "\n" + "Samples: " + point.YValues[0];
    143143          series.Points.Add(point);
     
    146146
    147147        point.XValue = residuals[i];
    148         point.YValues[0] = ((double)i) / residuals.Count;
     148        point.YValues[0] = ((double)i+1) / residuals.Count;
    149149        point.ToolTip = "Error: " + point.XValue + "\n" + "Samples: " + point.YValues[0];
    150150        series.Points.Add(point);
     
    164164      switch (cmbSamples.SelectedItem.ToString()) {
    165165        case TrainingSamples:
    166           originalValues = ProblemData.Dataset.GetEnumeratedVariableValues(ProblemData.TargetVariable, ProblemData.TrainingIndizes);
     166          originalValues = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndizes);
    167167          break;
    168168        case TestSamples:
    169           originalValues = ProblemData.Dataset.GetEnumeratedVariableValues(ProblemData.TargetVariable, ProblemData.TestIndizes);
     169          originalValues = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TestIndizes);
    170170          break;
    171171        case AllSamples:
    172           originalValues = ProblemData.Dataset.GetEnumeratedVariableValues(ProblemData.TargetVariable);
     172          originalValues = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable);
    173173          break;
    174174        default:
     
    197197
    198198    protected IEnumerable<double> GetMeanModelEstimatedValues(IEnumerable<double> originalValues) {
    199       double averageTrainingTarget = ProblemData.Dataset.GetEnumeratedVariableValues(ProblemData.TargetVariable, ProblemData.TrainingIndizes).Average();
     199      double averageTrainingTarget = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndizes).Average();
    200200      return Enumerable.Repeat(averageTrainingTarget, originalValues.Count());
    201201    }
  • branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionEstimatedValuesView.cs

    r6647 r6784  
    8888          string[,] values = new string[Content.ProblemData.Dataset.Rows, 7];
    8989
    90           double[] target = Content.ProblemData.Dataset.GetVariableValues(Content.ProblemData.TargetVariable);
     90          double[] target = Content.ProblemData.Dataset.GetDoubleValues(Content.ProblemData.TargetVariable).ToArray();
    9191          var estimated = Content.EstimatedValues.GetEnumerator();
    9292          var estimated_training = Content.EstimatedTrainingValues.GetEnumerator();
  • branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionLineChartView.Designer.cs

    r5809 r6784  
    6363      this.chart.Size = new System.Drawing.Size(358, 225);
    6464      this.chart.TabIndex = 0;
     65      this.chart.CustomizeLegend += new System.EventHandler<System.Windows.Forms.DataVisualization.Charting.CustomizeLegendEventArgs>(this.chart_CustomizeLegend);
    6566      this.chart.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.Chart_MouseDoubleClick);
     67      this.chart.MouseDown += new System.Windows.Forms.MouseEventHandler(this.chart_MouseDown);
     68      this.chart.MouseMove += new System.Windows.Forms.MouseEventHandler(this.chart_MouseMove);
    6669      //
    67       // LineChartView
     70      // RegressionSolutionLineChartView
    6871      //
    6972      this.AllowDrop = true;
     
    7174      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    7275      this.Controls.Add(this.chart);
    73       this.Name = "LineChartView";
     76      this.Name = "RegressionSolutionLineChartView";
    7477      this.Size = new System.Drawing.Size(358, 225);
    7578      ((System.ComponentModel.ISupportInitialize)(this.chart)).EndInit();
  • branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionLineChartView.cs

    r6647 r6784  
    2020#endregion
    2121using System;
     22using System.Collections.Generic;
    2223using System.Drawing;
    2324using System.Linq;
     
    3435    private const string ESTIMATEDVALUES_TRAINING_SERIES_NAME = "Estimated Values (training)";
    3536    private const string ESTIMATEDVALUES_TEST_SERIES_NAME = "Estimated Values (test)";
     37    private const string ESTIMATEDVALUES_ALL_SERIES_NAME = "Estimated Values (all samples)";
    3638
    3739    public new IRegressionSolution Content {
     
    6567        this.chart.Series[TARGETVARIABLE_SERIES_NAME].ChartType = SeriesChartType.FastLine;
    6668        this.chart.Series[TARGETVARIABLE_SERIES_NAME].Points.DataBindXY(Enumerable.Range(0, Content.ProblemData.Dataset.Rows).ToArray(),
    67           Content.ProblemData.Dataset.GetVariableValues(Content.ProblemData.TargetVariable));
     69          Content.ProblemData.Dataset.GetDoubleValues(Content.ProblemData.TargetVariable).ToArray());
    6870
    6971        this.chart.Series.Add(ESTIMATEDVALUES_TRAINING_SERIES_NAME);
    7072        this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME].LegendText = ESTIMATEDVALUES_TRAINING_SERIES_NAME;
    7173        this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME].ChartType = SeriesChartType.FastLine;
    72         this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME].Points.DataBindXY(Content.ProblemData.TrainingIndizes.ToArray(),
    73           Content.EstimatedTrainingValues.ToArray());
    74         this.chart.DataManipulator.InsertEmptyPoints(Content.ProblemData.Dataset.Rows, IntervalType.Number, ESTIMATEDVALUES_TRAINING_SERIES_NAME);
     74        this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME].Points.DataBindXY(Content.ProblemData.TrainingIndizes.ToArray(), Content.EstimatedTrainingValues.ToArray());
    7575        this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME].Tag = Content;
     76        this.chart.DataManipulator.InsertEmptyPoints(1, IntervalType.Number, ESTIMATEDVALUES_TRAINING_SERIES_NAME);
     77        this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME].EmptyPointStyle.BorderWidth = 0;
     78        this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME].EmptyPointStyle.MarkerStyle = MarkerStyle.None;
     79
    7680
    7781        this.chart.Series.Add(ESTIMATEDVALUES_TEST_SERIES_NAME);
    7882        this.chart.Series[ESTIMATEDVALUES_TEST_SERIES_NAME].LegendText = ESTIMATEDVALUES_TEST_SERIES_NAME;
    7983        this.chart.Series[ESTIMATEDVALUES_TEST_SERIES_NAME].ChartType = SeriesChartType.FastLine;
    80         this.chart.Series[ESTIMATEDVALUES_TEST_SERIES_NAME].Points.DataBindXY(Content.ProblemData.TestIndizes.ToArray(),
    81           Content.EstimatedTestValues.ToArray());
     84        this.chart.Series[ESTIMATEDVALUES_TEST_SERIES_NAME].Points.DataBindXY(Content.ProblemData.TestIndizes.ToArray(), Content.EstimatedTestValues.ToArray());
    8285        this.chart.Series[ESTIMATEDVALUES_TEST_SERIES_NAME].Tag = Content;
     86
     87
     88        int[] allIndizes = Enumerable.Range(0, Content.ProblemData.Dataset.Rows).Except(Content.ProblemData.TrainingIndizes).Except(Content.ProblemData.TestIndizes).ToArray();
     89        var estimatedValues = Content.EstimatedValues.ToArray();
     90        List<double> allEstimatedValues = allIndizes.Select(index => estimatedValues[index]).ToList();
     91
     92        this.chart.Series.Add(ESTIMATEDVALUES_ALL_SERIES_NAME);
     93        this.chart.Series[ESTIMATEDVALUES_ALL_SERIES_NAME].LegendText = ESTIMATEDVALUES_ALL_SERIES_NAME;
     94        this.chart.Series[ESTIMATEDVALUES_ALL_SERIES_NAME].ChartType = SeriesChartType.FastLine;
     95        this.chart.Series[ESTIMATEDVALUES_ALL_SERIES_NAME].Points.DataBindXY(allIndizes, allEstimatedValues);
     96        this.chart.Series[ESTIMATEDVALUES_ALL_SERIES_NAME].Tag = Content;
     97        this.chart.DataManipulator.InsertEmptyPoints(1, IntervalType.Number, ESTIMATEDVALUES_ALL_SERIES_NAME);
     98        this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME].EmptyPointStyle.BorderWidth = 0;
     99        this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME].EmptyPointStyle.MarkerStyle = MarkerStyle.None;
     100        this.ToggleSeriesData(this.chart.Series[ESTIMATEDVALUES_ALL_SERIES_NAME]);
     101
    83102        UpdateCursorInterval();
    84103        this.UpdateStripLines();
     
    109128    }
    110129
    111     private void Content_ProblemDataChanged(object sender, EventArgs e) {
    112       RedrawChart();
    113     }
    114 
    115     private void Content_ModelChanged(object sender, EventArgs e) {
    116       UpdateEstimatedValuesLineChart();
    117     }
    118 
    119130    protected override void OnContentChanged() {
    120131      base.OnContentChanged();
    121132      RedrawChart();
    122133    }
    123 
    124     private void UpdateEstimatedValuesLineChart() {
    125       if (InvokeRequired) Invoke((Action)UpdateEstimatedValuesLineChart);
    126       else {
    127         if (this.chart.Series.Count > 0) {
    128           Series s = this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME];
    129           if (s != null) {
    130             s.Points.DataBindXY(Content.ProblemData.TrainingIndizes.ToArray(), Content.EstimatedTrainingValues.ToArray());
    131             s.LegendText = ESTIMATEDVALUES_TRAINING_SERIES_NAME;
    132           }
    133           s = this.chart.Series[ESTIMATEDVALUES_TEST_SERIES_NAME];
    134           if (s != null) {
    135             s.Points.DataBindXY(Content.ProblemData.TestIndizes.ToArray(), Content.EstimatedTestValues.ToArray());
    136             s.LegendText = ESTIMATEDVALUES_TEST_SERIES_NAME;
    137           }
    138           this.UpdateStripLines();
    139           UpdateCursorInterval();
    140         }
    141       }
    142     }
     134    private void Content_ProblemDataChanged(object sender, EventArgs e) {
     135      RedrawChart();
     136    }
     137    private void Content_ModelChanged(object sender, EventArgs e) {
     138      RedrawChart();
     139    }
     140
     141
    143142
    144143    private void Chart_MouseDoubleClick(object sender, MouseEventArgs e) {
     
    201200      this.chart.ChartAreas[0].AxisX.StripLines.Add(stripLine);
    202201    }
     202
     203    private void ToggleSeriesData(Series series) {
     204      if (series.Points.Count > 0) {  //checks if series is shown
     205        if (this.chart.Series.Any(s => s != series && s.Points.Count > 0)) {
     206          series.Points.Clear();
     207        }
     208      } else if (Content != null) {
     209        string targetVariableName = Content.ProblemData.TargetVariable;
     210
     211        IEnumerable<int> indizes = null;
     212        IEnumerable<double> predictedValues = null;
     213        switch (series.Name) {
     214          case ESTIMATEDVALUES_ALL_SERIES_NAME:
     215            indizes = Enumerable.Range(0, Content.ProblemData.Dataset.Rows).Except(Content.ProblemData.TrainingIndizes).Except(Content.ProblemData.TestIndizes).ToArray();
     216            var estimatedValues = Content.EstimatedValues.ToArray();
     217            predictedValues = indizes.Select(index => estimatedValues[index]).ToList();
     218            break;
     219          case ESTIMATEDVALUES_TRAINING_SERIES_NAME:
     220            indizes = Content.ProblemData.TrainingIndizes.ToArray();
     221            predictedValues = Content.EstimatedTrainingValues.ToArray();
     222            break;
     223          case ESTIMATEDVALUES_TEST_SERIES_NAME:
     224            indizes = Content.ProblemData.TestIndizes.ToArray();
     225            predictedValues = Content.EstimatedTestValues.ToArray();
     226            break;
     227        }
     228        series.Points.DataBindXY(indizes, predictedValues);
     229        chart.DataManipulator.InsertEmptyPoints(1, IntervalType.Number, series.Name);
     230        chart.Legends[series.Legend].ForeColor = Color.Black;
     231        UpdateCursorInterval();
     232        chart.Refresh();
     233      }
     234    }
     235
     236    private void chart_MouseMove(object sender, MouseEventArgs e) {
     237      HitTestResult result = chart.HitTest(e.X, e.Y);
     238      if (result.ChartElementType == ChartElementType.LegendItem && result.Series.Name != TARGETVARIABLE_SERIES_NAME)
     239        Cursor = Cursors.Hand;
     240      else
     241        Cursor = Cursors.Default;
     242    }
     243    private void chart_MouseDown(object sender, MouseEventArgs e) {
     244      HitTestResult result = chart.HitTest(e.X, e.Y);
     245      if (result.ChartElementType == ChartElementType.LegendItem && result.Series.Name != TARGETVARIABLE_SERIES_NAME) {
     246        ToggleSeriesData(result.Series);
     247      }
     248    }
     249
     250    private void chart_CustomizeLegend(object sender, CustomizeLegendEventArgs e) {
     251      if (chart.Series.Count != 4) return;
     252      e.LegendItems[0].Cells[1].ForeColor = this.chart.Series[TARGETVARIABLE_SERIES_NAME].Points.Count == 0 ? Color.Gray : Color.Black;
     253      e.LegendItems[1].Cells[1].ForeColor = this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME].Points.Count == 0 ? Color.Gray : Color.Black;
     254      e.LegendItems[2].Cells[1].ForeColor = this.chart.Series[ESTIMATEDVALUES_TEST_SERIES_NAME].Points.Count == 0 ? Color.Gray : Color.Black;
     255      e.LegendItems[3].Cells[1].ForeColor = this.chart.Series[ESTIMATEDVALUES_ALL_SERIES_NAME].Points.Count == 0 ? Color.Gray : Color.Black;
     256    }
    203257  }
    204258}
  • branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionScatterPlotView.Designer.cs

    r5809 r6784  
    6464      this.chart.Size = new System.Drawing.Size(527, 392);
    6565      this.chart.TabIndex = 1;
     66      this.chart.PostPaint += new System.EventHandler<System.Windows.Forms.DataVisualization.Charting.ChartPaintEventArgs>(this.chart_PostPaint);
     67      this.chart.CustomizeLegend += new System.EventHandler<System.Windows.Forms.DataVisualization.Charting.CustomizeLegendEventArgs>(this.chart_CustomizeLegend);
     68      this.chart.MouseDown += new System.Windows.Forms.MouseEventHandler(this.chart_MouseDown);
    6669      this.chart.MouseMove += new System.Windows.Forms.MouseEventHandler(this.chart_MouseMove);
    67       this.chart.MouseDown += new System.Windows.Forms.MouseEventHandler(this.chart_MouseDown);
    68       this.chart.CustomizeLegend += new System.EventHandler<System.Windows.Forms.DataVisualization.Charting.CustomizeLegendEventArgs>(chart_CustomizeLegend);
    6970      //
    70       // ScatterPlotView
     71      // RegressionSolutionScatterPlotView
    7172      //
     73      this.AllowDrop = true;
    7274      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    7375      this.Controls.Add(this.chart);
    74       this.Name = "ScatterPlotView";
    75       this.AllowDrop = true;
     76      this.Name = "RegressionSolutionScatterPlotView";
    7677      this.Size = new System.Drawing.Size(527, 392);
    7778      ((System.ComponentModel.ISupportInitialize)(this.chart)).EndInit();
  • branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionScatterPlotView.cs

    r6647 r6784  
    130130        if (this.chart.Series[ALL_SERIES].Points.Count > 0)
    131131          this.chart.Series[ALL_SERIES].Points.DataBindXY(Content.EstimatedValues.ToArray(), "",
    132             dataset.GetVariableValues(targetVariableName), "");
     132            dataset.GetDoubleValues(targetVariableName).ToArray(), "");
    133133        if (this.chart.Series[TRAINING_SERIES].Points.Count > 0)
    134134          this.chart.Series[TRAINING_SERIES].Points.DataBindXY(Content.EstimatedTrainingValues.ToArray(), "",
    135             dataset.GetEnumeratedVariableValues(targetVariableName, Content.ProblemData.TrainingIndizes).ToArray(), "");
     135            dataset.GetDoubleValues(targetVariableName, Content.ProblemData.TrainingIndizes).ToArray(), "");
    136136        if (this.chart.Series[TEST_SERIES].Points.Count > 0)
    137137          this.chart.Series[TEST_SERIES].Points.DataBindXY(Content.EstimatedTestValues.ToArray(), "",
    138            dataset.GetEnumeratedVariableValues(targetVariableName, Content.ProblemData.TestIndizes).ToArray(), "");
    139 
    140         double max = Content.EstimatedTrainingValues.Concat(Content.EstimatedTestValues.Concat(Content.EstimatedValues.Concat(dataset.GetVariableValues(targetVariableName)))).Max();
    141         double min = Content.EstimatedTrainingValues.Concat(Content.EstimatedTestValues.Concat(Content.EstimatedValues.Concat(dataset.GetVariableValues(targetVariableName)))).Min();
     138           dataset.GetDoubleValues(targetVariableName, Content.ProblemData.TestIndizes).ToArray(), "");
     139
     140        double max = Content.EstimatedTrainingValues.Concat(Content.EstimatedTestValues.Concat(Content.EstimatedValues.Concat(dataset.GetDoubleValues(targetVariableName)))).Max();
     141        double min = Content.EstimatedTrainingValues.Concat(Content.EstimatedTestValues.Concat(Content.EstimatedValues.Concat(dataset.GetDoubleValues(targetVariableName)))).Min();
    142142
    143143        max = max + 0.2 * Math.Abs(max);
     
    177177          case ALL_SERIES:
    178178            predictedValues = Content.EstimatedValues.ToArray();
    179             targetValues = Content.ProblemData.Dataset.GetVariableValues(targetVariableName);
     179            targetValues = Content.ProblemData.Dataset.GetDoubleValues(targetVariableName).ToArray();
    180180            break;
    181181          case TRAINING_SERIES:
    182182            predictedValues = Content.EstimatedTrainingValues.ToArray();
    183             targetValues = Content.ProblemData.Dataset.GetEnumeratedVariableValues(targetVariableName, Content.ProblemData.TrainingIndizes).ToArray();
     183            targetValues = Content.ProblemData.Dataset.GetDoubleValues(targetVariableName, Content.ProblemData.TrainingIndizes).ToArray();
    184184            break;
    185185          case TEST_SERIES:
    186186            predictedValues = Content.EstimatedTestValues.ToArray();
    187             targetValues = Content.ProblemData.Dataset.GetEnumeratedVariableValues(targetVariableName, Content.ProblemData.TestIndizes).ToArray();
     187            targetValues = Content.ProblemData.Dataset.GetDoubleValues(targetVariableName, Content.ProblemData.TestIndizes).ToArray();
    188188            break;
    189189        }
     
    219219      e.LegendItems[2].Cells[1].ForeColor = this.chart.Series[TEST_SERIES].Points.Count == 0 ? Color.Gray : Color.Black;
    220220    }
     221
     222    private void chart_PostPaint(object sender, ChartPaintEventArgs e) {
     223      var chartArea = e.ChartElement as ChartArea;
     224      if (chartArea != null) {
     225        ChartGraphics chartGraphics = e.ChartGraphics;
     226        using (Pen p = new Pen(Color.DarkGray)) {
     227          double xmin = chartArea.AxisX.ScaleView.ViewMinimum;
     228          double xmax = chartArea.AxisX.ScaleView.ViewMaximum;
     229          double ymin = chartArea.AxisY.ScaleView.ViewMinimum;
     230          double ymax = chartArea.AxisY.ScaleView.ViewMaximum;
     231
     232          if (xmin > ymax || ymin > xmax) return;
     233
     234          PointF start = PointF.Empty;
     235          start.X = (float)chartGraphics.GetPositionFromAxis(chartArea.Name, chartArea.AxisX.AxisName, Math.Max(xmin, ymin));
     236          start.Y = (float)chartGraphics.GetPositionFromAxis(chartArea.Name, chartArea.AxisY.AxisName, Math.Max(xmin, ymin));
     237          PointF end = PointF.Empty;
     238          end.X = (float)chartGraphics.GetPositionFromAxis(chartArea.Name, chartArea.AxisX.AxisName, Math.Min(xmax, ymax));
     239          end.Y = (float)chartGraphics.GetPositionFromAxis(chartArea.Name, chartArea.AxisY.AxisName, Math.Min(xmax, ymax));
     240
     241          chartGraphics.Graphics.DrawLine(p, chartGraphics.GetAbsolutePoint(start), chartGraphics.GetAbsolutePoint(end));
     242        }
     243      }
     244    }
    221245  }
    222246}
  • branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis.Views/3.4/Solution Views/ClusteringSolutionView.cs

    r6675 r6784  
    2121
    2222using System.Windows.Forms;
     23using HeuristicLab.Core;
    2324using HeuristicLab.MainForm;
    2425
     
    3940    protected override void itemsListView_DragEnter(object sender, DragEventArgs e) {
    4041      validDragOperation = false;
    41       if (!ReadOnly && (e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) is ClusteringProblemData)) {
    42         validDragOperation = true;
     42      if (ReadOnly) return;
     43
     44      var dropData = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
     45      if (dropData is ClusteringProblemData) validDragOperation = true;
     46      else if (dropData is IValueParameter) {
     47        var param = (IValueParameter)dropData;
     48        if (param.Value is ClusteringProblemData) validDragOperation = true;
    4349      }
    4450    }
  • branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis.Views/3.4/Solution Views/DataAnalysisSolutionView.cs

    r6675 r6784  
    2525using System.Linq;
    2626using System.Windows.Forms;
     27using HeuristicLab.Core;
    2728using HeuristicLab.Core.Views;
    2829using HeuristicLab.MainForm;
     
    139140    protected override void itemsListView_DragEnter(object sender, DragEventArgs e) {
    140141      validDragOperation = false;
    141       if (!ReadOnly && (e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) is DataAnalysisProblemData)) {
    142         validDragOperation = true;
     142      if (ReadOnly) return;
     143
     144      var dropData = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
     145      if (dropData is DataAnalysisProblemData) validDragOperation = true;
     146      else if (dropData is IValueParameter) {
     147        var param = (IValueParameter)dropData;
     148        if (param.Value is DataAnalysisProblemData) validDragOperation = true;
    143149      }
    144150    }
     
    146152    protected override void itemsListView_DragDrop(object sender, DragEventArgs e) {
    147153      if (e.Effect != DragDropEffects.None) {
    148         if (e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) is DataAnalysisProblemData) {
    149           DataAnalysisProblemData problemData = (DataAnalysisProblemData)e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
     154        var dropData = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
     155        if (dropData is DataAnalysisProblemData) {
     156          DataAnalysisProblemData problemData = (DataAnalysisProblemData)dropData;
    150157          Content.ProblemData = (DataAnalysisProblemData)problemData.Clone();
     158        } else if (dropData is IValueParameter) {
     159          var param = (IValueParameter)dropData;
     160          DataAnalysisProblemData problemData = param.Value as DataAnalysisProblemData;
     161          if (problemData != null)
     162            Content.ProblemData = (DataAnalysisProblemData)problemData.Clone();
    151163        }
    152164      }
  • branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis.Views/3.4/Solution Views/NamedDataAnalysisSolutionView.cs

    r6675 r6784  
    3030  [Content(typeof(DataAnalysisSolution), true)]
    3131  public partial class NamedDataAnalysisSolutionView : NamedItemView {
     32    private Type contentType;
     33    private DataAnalysisSolutionView view;
     34
    3235    public NamedDataAnalysisSolutionView() {
    3336      InitializeComponent();
     
    4144    protected override void OnContentChanged() {
    4245      base.OnContentChanged();
    43       panel.Controls.Clear();
    4446
    45       if (Content != null) {
     47      if (Content == null) {
     48        panel.Controls.Clear();
     49      } else if (Content.GetType() == contentType && view != null) {
     50        view.Content = Content;
     51      } else {
     52        view = null;
     53        contentType = Content.GetType();
     54        panel.Controls.Clear();
    4655        var viewType = MainFormManager.GetViewTypes(Content.GetType(), true).Where(t => typeof(DataAnalysisSolutionView).IsAssignableFrom(t)).FirstOrDefault();
    4756        if (viewType != null) {
    48           var view = (DataAnalysisSolutionView)Activator.CreateInstance(viewType);
     57          view = (DataAnalysisSolutionView)Activator.CreateInstance(viewType);
    4958          view.Dock = DockStyle.Fill;
    5059          view.Content = Content;
Note: See TracChangeset for help on using the changeset viewer.