Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/14/17 10:29:51 (8 years ago)
Author:
pfleck
Message:

#2709 merged to stable

Location:
stable
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.DataPreprocessing

    • Property svn:mergeinfo set to (toggle deleted branches)
      /branches/DataPreprocessing Enhancements/HeuristicLab.DataPreprocessingmergedeligible
      /branches/crossvalidation-2434/HeuristicLab.DataPreprocessingmergedeligible
      /trunk/sources/HeuristicLab.DataPreprocessingmergedeligible
      /branches/1721-RandomForestPersistence/HeuristicLab.DataPreprocessing10321-10322
      /branches/Algorithms.GradientDescent/HeuristicLab.DataPreprocessing5516-5520
      /branches/Benchmarking/sources/HeuristicLab.DataPreprocessing6917-7005
      /branches/CloningRefactoring/HeuristicLab.DataPreprocessing4656-4721
      /branches/CodeEditor/HeuristicLab.DataPreprocessing11700-11806
      /branches/DataAnalysis Refactoring/HeuristicLab.DataPreprocessing5471-5808
      /branches/DataAnalysis SolutionEnsembles/HeuristicLab.DataPreprocessing5815-6180
      /branches/DataAnalysis/HeuristicLab.DataPreprocessing4458-4459,​4462,​4464
      /branches/DataPreprocessing/HeuristicLab.DataPreprocessing10085-11101
      /branches/GP.Grammar.Editor/HeuristicLab.DataPreprocessing6284-6795
      /branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.DataPreprocessing5060
      /branches/HLScript/HeuristicLab.DataPreprocessing10331-10358
      /branches/HeuristicLab.DatasetRefactor/sources/HeuristicLab.DataPreprocessing11570-12508
      /branches/HeuristicLab.Problems.DataAnalysis.Trading/HeuristicLab.DataPreprocessing6123-9799
      /branches/HeuristicLab.Problems.Orienteering/HeuristicLab.DataPreprocessing11130-12721
      /branches/HiveStatistics/sources/HeuristicLab.DataPreprocessing12440-12877
      /branches/LogResidualEvaluator/HeuristicLab.DataPreprocessing10202-10483
      /branches/NET40/sources/HeuristicLab.DataPreprocessing5138-5162
      /branches/NSGA-II Changes/HeuristicLab.DataPreprocessing12033-12122
      /branches/ParallelEngine/HeuristicLab.DataPreprocessing5175-5192
      /branches/ProblemInstancesRegressionAndClassification/HeuristicLab.DataPreprocessing7568-7810
      /branches/QAPAlgorithms/HeuristicLab.DataPreprocessing6350-6627
      /branches/Restructure trunk solution/HeuristicLab.DataPreprocessing6828
      /branches/RuntimeOptimizer/HeuristicLab.DataPreprocessing8943-9078
      /branches/ScatterSearch (trunk integration)/HeuristicLab.DataPreprocessing7787-8333
      /branches/SlaveShutdown/HeuristicLab.DataPreprocessing8944-8956
      /branches/SpectralKernelForGaussianProcesses/HeuristicLab.DataPreprocessing10204-10479
      /branches/SuccessProgressAnalysis/HeuristicLab.DataPreprocessing5370-5682
      /branches/Trunk/HeuristicLab.DataPreprocessing6829-6865
      /branches/UnloadJobs/HeuristicLab.DataPreprocessing9168-9215
      /branches/VNS/HeuristicLab.DataPreprocessing5594-5752
      /branches/histogram/HeuristicLab.DataPreprocessing5959-6341
      /branches/symbreg-factors-2650/HeuristicLab.DataPreprocessing14232-14825
      /trunk/sources/HeuristicLab.Problems.TestFunctions.MultiObjective/HeuristicLab.DataPreprocessing14175
  • stable/HeuristicLab.DataPreprocessing/3.4

  • stable/HeuristicLab.DataPreprocessing/3.4/Content/ScatterPlotContent.cs

    r14186 r15242  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    23 using System.Drawing;
    2424using System.Linq;
    2525using HeuristicLab.Analysis;
    2626using HeuristicLab.Common;
    27 using HeuristicLab.Core;
     27using HeuristicLab.Visualization.ChartControlsExtensions;
    2828
    2929namespace HeuristicLab.DataPreprocessing {
    3030
    31   [Item("ScatterPlot", "Represents a scatter plot.")]
    32   public class ScatterPlotContent : PreprocessingChartContent {
     31  public abstract class ScatterPlotContent : PreprocessingChartContent {
     32    public string GroupingVariable { get; set; }
    3333
    34     public string SelectedXVariable { get; set; }
    35     public string SelectedYVariable { get; set; }
    36     public string SelectedColorVariable { get; set; }
    37 
    38     public ScatterPlotContent(IFilteredPreprocessingData preprocessingData)
     34    protected ScatterPlotContent(IFilteredPreprocessingData preprocessingData)
    3935      : base(preprocessingData) {
    4036    }
    4137
    42     public ScatterPlotContent(ScatterPlotContent content, Cloner cloner)
     38    protected ScatterPlotContent(ScatterPlotContent content, Cloner cloner)
    4339      : base(content, cloner) {
    44       this.SelectedXVariable = content.SelectedXVariable;
    45       this.SelectedYVariable = content.SelectedYVariable;
    46       this.SelectedColorVariable = content.SelectedColorVariable;
    4740    }
    4841
    49     public static new Image StaticItemImage {
    50       get { return HeuristicLab.Common.Resources.VSImageLibrary.Performance; }
    51     }
    52 
    53     public override IDeepCloneable Clone(Cloner cloner) {
    54       return new ScatterPlotContent(this, cloner);
    55     }
    56 
    57     public ScatterPlot CreateScatterPlot(string variableNameX, string variableNameY, string variableNameColor = "-") {
     42    public static ScatterPlot CreateScatterPlot(IFilteredPreprocessingData preprocessingData, string variableNameX, string variableNameY, string variableNameGroup = "-", LegendOrder legendOrder = LegendOrder.Alphabetically) {
    5843      ScatterPlot scatterPlot = new ScatterPlot();
    5944
    60       IList<double> xValues = PreprocessingData.GetValues<double>(PreprocessingData.GetColumnIndex(variableNameX));
    61       IList<double> yValues = PreprocessingData.GetValues<double>(PreprocessingData.GetColumnIndex(variableNameY));
    62       if (variableNameColor == null || variableNameColor == "-") {
    63         List<Point2D<double>> points = new List<Point2D<double>>();
     45      IList<double> xValues = preprocessingData.GetValues<double>(preprocessingData.GetColumnIndex(variableNameX));
     46      IList<double> yValues = preprocessingData.GetValues<double>(preprocessingData.GetColumnIndex(variableNameY));
    6447
    65         for (int i = 0; i < xValues.Count; i++) {
    66           Point2D<double> point = new Point2D<double>(xValues[i], yValues[i]);
    67           points.Add(point);
    68         }
     48      var points = xValues.Zip(yValues, (x, y) => new Point2D<double>(x, y)).ToList();
     49      var validPoints = points.Where(p => !double.IsNaN(p.X) && !double.IsNaN(p.Y) && !double.IsInfinity(p.X) && !double.IsInfinity(p.Y)).ToList();
     50      if (validPoints.Any()) {
     51        try {
     52          double axisMin, axisMax, axisInterval;
     53          ChartUtil.CalculateOptimalAxisInterval(validPoints.Min(p => p.X), validPoints.Max(p => p.X), out axisMin, out axisMax, out axisInterval);
     54          scatterPlot.VisualProperties.XAxisMinimumAuto = false;
     55          scatterPlot.VisualProperties.XAxisMaximumAuto = false;
     56          scatterPlot.VisualProperties.XAxisMinimumFixedValue = axisMin;
     57          scatterPlot.VisualProperties.XAxisMaximumFixedValue = axisMax;
     58        } catch (ArgumentOutOfRangeException) { } // error during CalculateOptimalAxisInterval
     59        try {
     60          double axisMin, axisMax, axisInterval;
     61          ChartUtil.CalculateOptimalAxisInterval(validPoints.Min(p => p.Y), validPoints.Max(p => p.Y), out axisMin, out axisMax, out axisInterval);
     62          scatterPlot.VisualProperties.YAxisMinimumAuto = false;
     63          scatterPlot.VisualProperties.YAxisMaximumAuto = false;
     64          scatterPlot.VisualProperties.YAxisMinimumFixedValue = axisMin;
     65          scatterPlot.VisualProperties.YAxisMaximumFixedValue = axisMax;
     66        } catch (ArgumentOutOfRangeException) { } // error during CalculateOptimalAxisInterval
     67      }
    6968
    70         ScatterPlotDataRow scdr = new ScatterPlotDataRow(variableNameX + " - " + variableNameY, "", points);
     69
     70      //No Grouping
     71      if (string.IsNullOrEmpty(variableNameGroup) || variableNameGroup == "-") {
     72        ScatterPlotDataRow scdr = new ScatterPlotDataRow(variableNameX + " - " + variableNameY, "", validPoints);
     73        scdr.VisualProperties.IsVisibleInLegend = false;
    7174        scatterPlot.Rows.Add(scdr);
     75        return scatterPlot;
     76      }
    7277
    73       } else {
    74         var colorValues = PreprocessingData.GetValues<double>(PreprocessingData.GetColumnIndex(variableNameColor));
    75         var data = xValues.Zip(yValues, (x, y) => new { x, y }).Zip(colorValues, (v, c) => new { v.x, v.y, c }).ToList();
    76         var gradients = ColorGradient.Colors;
    77         int curGradient = 0;
    78         int numColors = colorValues.Distinct().Count();
    79         foreach (var colorValue in colorValues.Distinct()) {
    80           var values = data.Where(x => x.c == colorValue);
    81           var row = new ScatterPlotDataRow(
    82             variableNameX + " - " + variableNameY + " (" + colorValue + ")",
    83             "",
    84             values.Select(v => new Point2D<double>(v.x, v.y)),
    85             new ScatterPlotDataRowVisualProperties() { Color = gradients[curGradient] });
    86           curGradient += gradients.Count / numColors;
    87           scatterPlot.Rows.Add(row);
    88         }
     78      //Grouping
     79      int groupVariableIndex = preprocessingData.GetColumnIndex(variableNameGroup);
     80      var groupingValues = Enumerable.Empty<string>();
     81
     82      if (preprocessingData.VariableHasType<double>(groupVariableIndex)) {
     83        groupingValues = preprocessingData.GetValues<double>(groupVariableIndex).Select(x => x.ToString());
     84      } else if (preprocessingData.VariableHasType<string>(groupVariableIndex)) {
     85        groupingValues = preprocessingData.GetValues<string>(groupVariableIndex);
     86      } else if (preprocessingData.VariableHasType<DateTime>(groupVariableIndex)) {
     87        groupingValues = preprocessingData.GetValues<DateTime>(groupVariableIndex).Select(x => x.ToString());
     88      }
     89      var groups = groupingValues.Zip(validPoints, Tuple.Create).GroupBy(t => t.Item1, t => t.Item2);
     90
     91      if (legendOrder == LegendOrder.Alphabetically)
     92        groups = groups.OrderBy(x => x.Key, new NaturalStringComparer());
     93
     94      foreach (var group in groups) {
     95        var scdr = new ScatterPlotDataRow {
     96          Name = group.Key,
     97          VisualProperties = {
     98            IsVisibleInLegend = true,
     99            PointSize = 6
     100          }
     101        };
     102        scdr.Points.AddRange(group);
     103        scatterPlot.Rows.Add(scdr);
    89104      }
    90105      return scatterPlot;
Note: See TracChangeset for help on using the changeset viewer.