- Timestamp:
- 03/07/17 15:32:44 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataPreprocessing Enhancements/HeuristicLab.DataPreprocessing/3.4/Content/ScatterPlotContent.cs
r14525 r14724 25 25 using HeuristicLab.Analysis; 26 26 using HeuristicLab.Common; 27 using HeuristicLab.Problems.DataAnalysis;28 27 using HeuristicLab.Visualization.ChartControlsExtensions; 29 28 … … 55 54 scatterPlot.VisualProperties.XAxisMinimumFixedValue = axisMin; 56 55 scatterPlot.VisualProperties.XAxisMaximumFixedValue = axisMax; 57 } catch (ArgumentOutOfRangeException) { } // error during CalculateOptimalAxisInterval 56 } 57 catch (ArgumentOutOfRangeException) { } // error during CalculateOptimalAxisInterval 58 58 try { 59 59 double axisMin, axisMax, axisInterval; … … 63 63 scatterPlot.VisualProperties.YAxisMinimumFixedValue = axisMin; 64 64 scatterPlot.VisualProperties.YAxisMaximumFixedValue = axisMax; 65 } catch (ArgumentOutOfRangeException) { } // error during CalculateOptimalAxisInterval 65 } 66 catch (ArgumentOutOfRangeException) { } // error during CalculateOptimalAxisInterval 66 67 } 67 68 68 if (variableNameGroup == null || variableNameGroup == "-") { 69 70 //No Grouping 71 if (string.IsNullOrEmpty(variableNameGroup) || variableNameGroup == "-") { 69 72 ScatterPlotDataRow scdr = new ScatterPlotDataRow(variableNameX + " - " + variableNameY, "", validPoints); 70 73 scdr.VisualProperties.IsVisibleInLegend = false; 71 74 scatterPlot.Rows.Add(scdr); 72 } else { 73 var groupValues = PreprocessingData.GetValues<double>(PreprocessingData.GetColumnIndex(variableNameGroup)); 74 var data = points.Zip(groupValues, (p, g) => new { p, g }) 75 .Where(x => !double.IsNaN(x.p.X) && !double.IsNaN(x.p.Y) && !double.IsInfinity(x.p.X) && !double.IsInfinity(x.p.Y)) 76 .ToList(); 75 return scatterPlot; 76 } 77 77 78 foreach (var groupValue in groupValues.Distinct().OrderBy(g => g)) { 79 var values = data.Where(x => x.g == groupValue || (double.IsNaN(x.g) && double.IsNaN(groupValue))).Select(v => v.p); 80 var row = new ScatterPlotDataRow(string.Format("{0} ({1})", variableNameGroup, groupValue), "", values) { 81 Name = groupValue.ToString("R"), 82 VisualProperties = { PointSize = 6 } 83 }; 84 scatterPlot.Rows.Add(row); 85 } 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 foreach (var group in groups) { 92 var scdr = new ScatterPlotDataRow(); 93 scdr.Name = group.Key; 94 scdr.VisualProperties.IsVisibleInLegend = true; 95 scdr.VisualProperties.PointSize = 6; 96 scdr.Points.AddRange(group); 97 scatterPlot.Rows.Add(scdr); 86 98 } 87 99 return scatterPlot; 88 100 } 89 101 90 public DataRow GetCorrelationRow(string variableNameX, string variableNameY) {91 var xValues = PreprocessingData.GetValues<double>(PreprocessingData.GetColumnIndex(variableNameX));92 var yValues = PreprocessingData.GetValues<double>(PreprocessingData.GetColumnIndex(variableNameY));93 94 double k, d;95 OnlineCalculatorError err;96 OnlineLinearScalingParameterCalculator.Calculate(xValues, yValues, out k, out d, out err);97 double p = OnlinePearsonsRCalculator.Calculate(xValues, yValues, out err);98 99 var data = new double[xValues.Count];100 for (int i = 0; i < xValues.Count; i++) {101 data[i]= k * i + d;102 }103 104 return new DataRow(string.Format("Correlation (R²={0})", p*p), "", data);105 }106 102 } 107 103 }
Note: See TracChangeset
for help on using the changeset viewer.