Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/12/16 11:17:07 (7 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).
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.