Changeset 14474


Ignore:
Timestamp:
12/12/16 11:17:07 (3 years ago)
Author:
pfleck
Message:

#2709

  • Improved legend description for grouped histogram and scatterplots.
  • Fixed initial size of points for scatterplots.
  • Added correlation calculation for scatterplots (not used yet).
Location:
branches/DataPreprocessing Enhancements
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/DataPreprocessing Enhancements/HeuristicLab.DataPreprocessing.Views/3.4/HistogramView.cs

    r14459 r14474  
    6262      } else {
    6363        dt.VisualProperties.Title = variableName;
    64         //var valuesPerClass = row.Values.Zip(Classification, (value, @class) => new { value, @class })
    65         //                        .GroupBy(x => x.@class)
    66         //                        .ToDictionary(x => x.Key, x => x.Select(v => v.value));
    67         var valuesPerClass = row.Values.Select((i, index) => new { i, j = Classification.ToList()[index] })
    68                                        .GroupBy((x) => x.j)
    69                                        .ToDictionary(x => x.Key, x => x.Select(v => v.i)
    70                                        .ToList());
     64        var valuesPerClass = row.Values.Zip(Classification, (value, @class) => new { value, @class })
     65                                .GroupBy(x => x.@class)
     66                                .ToDictionary(x => x.Key, x => x.Select(v => v.value));
    7167        foreach (var entry in valuesPerClass) {
    72           var classRow = new DataRow(entry.Key.ToString());
     68          var classRow = new DataRow(string.Format("{0} ({1})", classifierComboBox.SelectedItem, entry.Key));
    7369          classRow.VisualProperties.ChartType = DataRowVisualProperties.DataRowChartType.Histogram;
    7470          classRow.Values.AddRange(entry.Value);
  • branches/DataPreprocessing Enhancements/HeuristicLab.DataPreprocessing.Views/3.4/ScatterPlotSingleView.cs

    r14472 r14474  
    7171          comboBoxGroup.SelectedIndex = 0;
    7272          UpdateScatterPlot();
    73           if (scatterPlotControl.Content != null)
    74             foreach (var row in scatterPlotControl.Content.Rows)
    75               row.VisualProperties.PointSize = 6;
    7673        }
    7774      }
  • branches/DataPreprocessing Enhancements/HeuristicLab.DataPreprocessing/3.4/Content/ScatterPlotContent.cs

    r14472 r14474  
    2525using HeuristicLab.Analysis;
    2626using HeuristicLab.Common;
     27using HeuristicLab.Problems.DataAnalysis;
    2728using HeuristicLab.Visualization.ChartControlsExtensions;
    2829
     
    3839    }
    3940
    40     public ScatterPlot CreateScatterPlot(string variableNameX, string variableNameY, string variableNameColor = "-") {
     41    public ScatterPlot CreateScatterPlot(string variableNameX, string variableNameY, string variableNameGroup = "-") {
    4142      ScatterPlot scatterPlot = new ScatterPlot();
    4243
     
    6061      } catch (ArgumentOutOfRangeException) { } // missing values lead to NaNs
    6162
    62       if (variableNameColor == null || variableNameColor == "-") {
     63      if (variableNameGroup == null || variableNameGroup == "-") {
    6364        List<Point2D<double>> points = new List<Point2D<double>>();
    6465
     
    6869        }
    6970
    70         ScatterPlotDataRow scdr = new ScatterPlotDataRow(variableNameX + " - " + variableNameY, "", points);
     71        ScatterPlotDataRow scdr = new ScatterPlotDataRow(variableNameX + " - " + variableNameY, "", points) {
     72          VisualProperties = { PointSize = 6 }
     73        };
    7174        scdr.VisualProperties.IsVisibleInLegend = false;
    7275        scatterPlot.Rows.Add(scdr);
    7376
    7477      } else {
    75         var colorValues = PreprocessingData.GetValues<double>(PreprocessingData.GetColumnIndex(variableNameColor));
    76         var data = xValues.Zip(yValues, (x, y) => new { x, y }).Zip(colorValues, (v, c) => new { v.x, v.y, c }).ToList();
    77         var gradients = ColorGradient.Colors;
    78         int curGradient = 0;
    79         int numColors = colorValues.Distinct().Count();
    80         foreach (var colorValue in colorValues.Distinct()) {
    81           var values = data.Where(x => x.c == colorValue);
     78        var groupValues = PreprocessingData.GetValues<double>(PreprocessingData.GetColumnIndex(variableNameGroup));
     79        var data = xValues.Zip(yValues, (x, y) => new { x, y }).Zip(groupValues, (v, c) => new { v.x, v.y, c }).ToList();
     80        foreach (var groupValue in groupValues.Distinct()) {
     81          var values = data.Where(x => x.c == groupValue);
    8282          var row = new ScatterPlotDataRow(
    83             variableNameX + " - " + variableNameY + " (" + colorValue + ")",
     83            variableNameGroup + " (" + groupValue + ")",
    8484            "",
    85             values.Select(v => new Point2D<double>(v.x, v.y)),
    86             new ScatterPlotDataRowVisualProperties() { Color = gradients[curGradient] });
    87           curGradient += gradients.Count / numColors;
     85            values.Select(v => new Point2D<double>(v.x, v.y))) {
     86            VisualProperties = { PointSize = 6 }
     87          };
    8888          scatterPlot.Rows.Add(row);
    8989        }
     
    9191      return scatterPlot;
    9292    }
     93
     94    public DataRow GetCorrelationRow(string variableNameX, string variableNameY) {
     95      var xValues = PreprocessingData.GetValues<double>(PreprocessingData.GetColumnIndex(variableNameX));
     96      var yValues = PreprocessingData.GetValues<double>(PreprocessingData.GetColumnIndex(variableNameY));
     97
     98      double k, d;
     99      OnlineCalculatorError err;
     100      OnlineLinearScalingParameterCalculator.Calculate(xValues, yValues, out k, out d, out err);
     101      double p = OnlinePearsonsRCalculator.Calculate(xValues, yValues, out err);
     102
     103      var data = new double[xValues.Count];
     104      for (int i = 0; i < xValues.Count; i++) {
     105        data[i]= k * i + d;
     106      }
     107
     108      return new DataRow(string.Format("Correlation (R²={0})", p*p), "", data);
     109    }
    93110  }
    94111}
Note: See TracChangeset for help on using the changeset viewer.