Changeset 14724
- Timestamp:
- 03/07/17 15:32:44 (8 years ago)
- Location:
- branches/DataPreprocessing Enhancements
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataPreprocessing Enhancements/HeuristicLab.DataPreprocessing.Views/3.4/ScatterPlotSingleView.Designer.cs
r14525 r14724 144 144 // comboBoxGroup 145 145 // 146 this.comboBoxGroup.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 146 this.comboBoxGroup.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 147 147 | System.Windows.Forms.AnchorStyles.Right))); 148 148 this.comboBoxGroup.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Suggest; 149 149 this.comboBoxGroup.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems; 150 this.comboBoxGroup.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; 150 151 this.comboBoxGroup.FormattingEnabled = true; 151 152 this.comboBoxGroup.Location = new System.Drawing.Point(51, 94); … … 158 159 // comboBoxYVariable 159 160 // 160 this.comboBoxYVariable.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 161 this.comboBoxYVariable.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 161 162 | System.Windows.Forms.AnchorStyles.Right))); 162 163 this.comboBoxYVariable.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Suggest; … … 172 173 // comboBoxXVariable 173 174 // 174 this.comboBoxXVariable.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 175 this.comboBoxXVariable.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 175 176 | System.Windows.Forms.AnchorStyles.Right))); 176 177 this.comboBoxXVariable.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Suggest; … … 200 201 // regressionTypeComboBox 201 202 // 202 this.regressionTypeComboBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 203 this.regressionTypeComboBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 203 204 | System.Windows.Forms.AnchorStyles.Right))); 204 205 this.regressionTypeComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; … … 212 213 // polynomialRegressionOrderNumericUpDown 213 214 // 214 this.polynomialRegressionOrderNumericUpDown.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 215 this.polynomialRegressionOrderNumericUpDown.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 215 216 | System.Windows.Forms.AnchorStyles.Right))); 216 217 this.polynomialRegressionOrderNumericUpDown.Location = new System.Drawing.Point(51, 47); … … 287 288 // gradientPictureBox 288 289 // 289 this.gradientPictureBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 290 this.gradientPictureBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 290 291 | System.Windows.Forms.AnchorStyles.Left))); 291 292 this.gradientPictureBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; -
branches/DataPreprocessing Enhancements/HeuristicLab.DataPreprocessing.Views/3.4/ScatterPlotSingleView.cs
r14525 r14724 35 35 [View("Scatter Plot Single View")] 36 36 [Content(typeof(SingleScatterPlotContent), true)] 37 public partial class ScatterPlotSingleView : ItemView {38 39 private readonly string NoGroupItem = " -";37 public sealed partial class ScatterPlotSingleView : ItemView { 38 private const int MAX_DISTINCT_VALUES_FOR_GROUPING = 20; 39 private readonly string NoGroupItem = ""; 40 40 41 41 public new SingleScatterPlotContent Content { … … 51 51 } 52 52 53 public void InitData() { 53 protected override void SetEnabledStateOfControls() { 54 base.SetEnabledStateOfControls(); 55 useGradientCheckBox.Enabled = (string)comboBoxGroup.SelectedItem != NoGroupItem; 56 gradientPanel.Visible = useGradientCheckBox.Enabled && useGradientCheckBox.Checked; ; 57 } 58 59 protected override void OnContentChanged() { 60 base.OnContentChanged(); 61 if (Content != null) { 62 InitData(); 63 } 64 } 65 66 private void InitData() { 54 67 IEnumerable<string> variables = Content.PreprocessingData.GetDoubleVariableNames(); 55 68 56 // add variables to combo boxes57 69 comboBoxXVariable.Items.Clear(); 58 70 comboBoxYVariable.Items.Clear(); 59 71 comboBoxGroup.Items.Clear(); 72 60 73 comboBoxXVariable.Items.AddRange(variables.ToArray()); 61 74 comboBoxYVariable.Items.AddRange(variables.ToArray()); 62 75 comboBoxGroup.Items.Add(NoGroupItem); 63 for (int i = 0; i < Content.PreprocessingData.Columns; ++i) { 64 if (Content.PreprocessingData.VariableHasType<double>(i)) { 65 //double distinctValueCount = Content.PreprocessingData.GetValues<double>(i).GroupBy(x => x).Count(); 66 //if (distinctValueCount <= 20) 67 comboBoxGroup.Items.Add(Content.PreprocessingData.GetVariableName(i)); 68 } 69 } 76 foreach (string var in GetVariableNamesForGrouping(Content.PreprocessingData)) { 77 comboBoxGroup.Items.Add(var); 78 } 79 comboBoxGroup.SelectedItem = Content.SelectedGroupVariable; 70 80 71 81 // use x and y variable from content … … 84 94 } 85 95 86 protected override void OnContentChanged() {87 base.OnContentChanged();88 if (Content != null) {89 InitData();90 }91 }92 93 protected override void SetEnabledStateOfControls() {94 base.SetEnabledStateOfControls();95 useGradientCheckBox.Enabled = (string)comboBoxGroup.SelectedItem != NoGroupItem;96 gradientPanel.Visible = useGradientCheckBox.Enabled && useGradientCheckBox.Checked; ;97 }98 99 96 private void UpdateScatterPlot() { 100 97 if (comboBoxXVariable.SelectedItem != null && comboBoxYVariable.SelectedItem != null && comboBoxGroup.SelectedItem != null) { … … 103 100 var groupVariable = (string)comboBoxGroup.SelectedItem; 104 101 105 bool isGroupingActive = groupVariable != NoGroupItem;106 double min = 0, max = 1;107 if (isGroupingActive) {108 var groupValues = Content.PreprocessingData.GetValues<double>(Content.PreprocessingData.GetColumnIndex(groupVariable))109 .Distinct().OrderBy(x => x).ToList();110 min = groupValues.FirstOrDefault(x => !double.IsNaN(x));111 max = groupValues.LastOrDefault(x => !double.IsNaN(x));112 }113 102 ScatterPlot scatterPlot = Content.CreateScatterPlot(xVariable, yVariable, groupVariable); 103 //rows are saved and removed to avoid firing of visual property changed events 114 104 var rows = scatterPlot.Rows.ToList(); 115 105 scatterPlot.Rows.Clear(); … … 122 112 row.VisualProperties.PolynomialRegressionOrder = order; 123 113 row.VisualProperties.IsVisibleInLegend = !useGradientCheckBox.Checked; 124 if (isGroupingActive && useGradientCheckBox.Checked)125 row.VisualProperties.Color = GetColor(double.Parse(row.Name), min, max);126 114 } 127 115 scatterPlot.Rows.AddRange(rows); … … 133 121 scatterPlotControl.Content = scatterPlot; 134 122 135 if (isGroupingActive) {136 gradientMinimumLabel.Text = min.ToString("G5");137 gradientMaximumLabel.Text = max.ToString("G5");138 }139 140 123 //save selected x and y variable in content 141 124 this.Content.SelectedXVariable = (string)comboBoxXVariable.SelectedItem; … … 149 132 UpdateScatterPlot(); 150 133 var newPlot = scatterPlotControl.Content; 151 152 134 153 135 if (oldPlot == null || newPlot == null) return; … … 183 165 184 166 private void comboBoxGroup_SelectedIndexChanged(object sender, EventArgs e) { 185 useGradientCheckBox.Enabled = (string)comboBoxGroup.SelectedItem != NoGroupItem ;167 useGradientCheckBox.Enabled = (string)comboBoxGroup.SelectedItem != NoGroupItem && Content.PreprocessingData.GetDoubleVariableNames().Contains((string)comboBoxGroup.SelectedItem); 186 168 gradientPanel.Visible = useGradientCheckBox.Enabled && useGradientCheckBox.Checked; 187 169 UpdateScatterPlot(); … … 201 183 202 184 private void UpdateRegressionLine() { 185 if (Content == null) return; 186 scatterPlotControl.Content.Rows.Clear(); 187 203 188 var regressionType = (RegressionType)regressionTypeComboBox.SelectedValue; 204 189 int order = (int)polynomialRegressionOrderNumericUpDown.Value; 205 190 206 191 var rows = scatterPlotControl.Content.Rows.ToList(); 207 scatterPlotControl.Content.Rows.Clear();208 192 foreach (var row in rows) { 209 193 row.VisualProperties.IsRegressionVisibleInLegend = false; … … 258 242 } 259 243 260 private void BatchRowUpdate(Action<ScatterPlotDataRow> rowAction) { 261 var scatterPlot = scatterPlotControl.Content; 262 var rows = scatterPlot.Rows.ToList(); 263 // remove rows and re-add them later to avoid firing visual property changd events 264 scatterPlot.Rows.Clear(); 265 foreach (var row in rows) { 266 rowAction(row); 267 } 268 scatterPlot.Rows.AddRange(rows); 244 private static IEnumerable<string> GetVariableNamesForGrouping(IPreprocessingData preprocessingData) { 245 var variableNames = new List<string>(); 246 247 for (int i = 0; i < preprocessingData.Columns; ++i) { 248 int distinctValues = Int32.MaxValue; 249 if (preprocessingData.VariableHasType<double>(i)) 250 distinctValues = preprocessingData.GetValues<double>(i).GroupBy(x => x).Count(); 251 else if (preprocessingData.VariableHasType<string>(i)) 252 distinctValues = preprocessingData.GetValues<string>(i).GroupBy(x => x).Count(); 253 else if (preprocessingData.VariableHasType<DateTime>(i)) 254 distinctValues = preprocessingData.GetValues<DateTime>(i).GroupBy(x => x).Count(); 255 256 if (distinctValues <= MAX_DISTINCT_VALUES_FOR_GROUPING) 257 variableNames.Add(preprocessingData.GetVariableName(i)); 258 } 259 return variableNames; 269 260 } 270 261 } -
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.