Changeset 14029 for branches/crossvalidation-2434/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression
- Timestamp:
- 07/08/16 14:40:02 (8 years ago)
- Location:
- branches/crossvalidation-2434
- Files:
-
- 8 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/crossvalidation-2434
- Property svn:mergeinfo changed
-
branches/crossvalidation-2434/HeuristicLab.Problems.DataAnalysis.Views
- Property svn:mergeinfo changed
-
branches/crossvalidation-2434/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionEnsembleSolutionModelView.cs
r12012 r14029 63 63 protected override void SetEnabledStateOfControls() { 64 64 base.SetEnabledStateOfControls(); 65 addButton.Enabled = Content != null && !Content.IsReadOnly && !Locked;66 removeButton.Enabled = Content != null && !Content.IsReadOnly && !Locked && itemsListView.SelectedItems.Count > 0;65 addButton.Enabled = false; 66 removeButton.Enabled = Content != null && !Content.IsReadOnly && !Locked && !ReadOnly && itemsListView.SelectedItems.Count > 0; 67 67 itemsListView.Enabled = Content != null && !Locked; 68 68 detailsGroupBox.Enabled = Content != null && itemsListView.SelectedItems.Count == 1; 69 sortAscendingButton.Enabled = false; 70 sortDescendingButton.Enabled = false; 69 71 } 72 73 //forbid sorting 74 protected override void SortItemsListView(SortOrder sortOrder) { } 70 75 71 76 protected override void itemsListView_DragEnter(object sender, DragEventArgs e) { -
branches/crossvalidation-2434/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionErrorCharacteristicsCurveView.Designer.cs
r12493 r14029 46 46 private void InitializeComponent() { 47 47 this.components = new System.ComponentModel.Container(); 48 System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea 2= new System.Windows.Forms.DataVisualization.Charting.ChartArea();49 System.Windows.Forms.DataVisualization.Charting.Legend legend 2= new System.Windows.Forms.DataVisualization.Charting.Legend();48 System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); 49 System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend(); 50 50 this.chart = new HeuristicLab.Visualization.ChartControlsExtensions.EnhancedChart(); 51 51 this.label1 = new System.Windows.Forms.Label(); … … 57 57 // chart 58 58 // 59 this.chart.AllowDrop = true; 59 60 this.chart.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 60 61 | System.Windows.Forms.AnchorStyles.Left) 61 62 | System.Windows.Forms.AnchorStyles.Right))); 62 chartArea 2.Name = "ChartArea1";63 this.chart.ChartAreas.Add(chartArea 2);64 legend 2.Alignment = System.Drawing.StringAlignment.Center;65 legend 2.Docking = System.Windows.Forms.DataVisualization.Charting.Docking.Top;66 legend 2.Name = "Legend1";67 this.chart.Legends.Add(legend 2);63 chartArea1.Name = "ChartArea1"; 64 this.chart.ChartAreas.Add(chartArea1); 65 legend1.Alignment = System.Drawing.StringAlignment.Center; 66 legend1.Docking = System.Windows.Forms.DataVisualization.Charting.Docking.Top; 67 legend1.Name = "Legend1"; 68 this.chart.Legends.Add(legend1); 68 69 this.chart.Location = new System.Drawing.Point(6, 28); 69 70 this.chart.Name = "chart"; … … 71 72 this.chart.TabIndex = 0; 72 73 this.chart.Text = "chart"; 74 this.chart.DragDrop += new System.Windows.Forms.DragEventHandler(this.chart_DragDrop); 75 this.chart.DragEnter += new System.Windows.Forms.DragEventHandler(this.chart_DragEnter); 73 76 this.chart.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.Chart_MouseDoubleClick); 74 77 this.chart.MouseMove += new System.Windows.Forms.MouseEventHandler(this.chart_MouseMove); -
branches/crossvalidation-2434/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionErrorCharacteristicsCurveView.cs
r12642 r14029 25 25 using System.Windows.Forms; 26 26 using System.Windows.Forms.DataVisualization.Charting; 27 using HeuristicLab.Algorithms.DataAnalysis; 27 28 using HeuristicLab.Common; 28 29 using HeuristicLab.MainForm; 30 using HeuristicLab.Optimization; 29 31 30 32 namespace HeuristicLab.Problems.DataAnalysis.Views { … … 62 64 } 63 65 66 // the view holds one regression solution as content but also contains several other regression solutions for comparison 67 // the following invariants must hold 68 // (Solutions.IsEmpty && Content == null) || 69 // (Solutions[0] == Content && Solutions.All(s => s.ProblemData.TargetVariable == Content.TargetVariable)) 70 64 71 public new IRegressionSolution Content { 65 72 get { return (IRegressionSolution)base.Content; } 66 73 set { base.Content = value; } 67 74 } 75 76 private readonly IList<IRegressionSolution> solutions = new List<IRegressionSolution>(); 77 public IEnumerable<IRegressionSolution> Solutions { 78 get { return solutions.AsEnumerable(); } 79 } 80 68 81 public IRegressionProblemData ProblemData { 69 82 get { … … 86 99 protected virtual void Content_ModelChanged(object sender, EventArgs e) { 87 100 if (InvokeRequired) Invoke((Action<object, EventArgs>)Content_ModelChanged, sender, e); 88 else UpdateChart(); 101 else { 102 // recalculate baseline solutions (for symbolic regression models the features used in the model might have changed) 103 solutions.Clear(); // remove all 104 solutions.Add(Content); // re-add the first solution 105 // and recalculate all other solutions 106 foreach (var sol in CreateBaselineSolutions()) { 107 solutions.Add(sol); 108 } 109 UpdateChart(); 110 } 89 111 } 90 112 protected virtual void Content_ProblemDataChanged(object sender, EventArgs e) { 91 113 if (InvokeRequired) Invoke((Action<object, EventArgs>)Content_ProblemDataChanged, sender, e); 92 114 else { 115 // recalculate baseline solutions 116 solutions.Clear(); // remove all 117 solutions.Add(Content); // re-add the first solution 118 // and recalculate all other solutions 119 foreach (var sol in CreateBaselineSolutions()) { 120 solutions.Add(sol); 121 } 93 122 UpdateChart(); 94 123 } … … 96 125 protected override void OnContentChanged() { 97 126 base.OnContentChanged(); 127 // the content object is always stored as the first element in solutions 128 solutions.Clear(); 129 ReadOnly = Content == null; 130 if (Content != null) { 131 // recalculate all solutions 132 solutions.Add(Content); 133 if (ProblemData.TrainingIndices.Any()) { 134 foreach (var sol in CreateBaselineSolutions()) 135 solutions.Add(sol); 136 // more solutions can be added by drag&drop 137 } 138 } 98 139 UpdateChart(); 99 140 } … … 109 150 if (cmbSamples.SelectedItem.ToString() == TestSamples && !ProblemData.TestIndices.Any()) return; 110 151 111 if (Content.ProblemData.TrainingIndices.Any()) { 112 AddRegressionSolution(CreateConstantSolution()); 113 } 114 115 AddRegressionSolution(Content); 152 foreach (var sol in Solutions) { 153 AddSeries(sol); 154 } 116 155 117 156 chart.ChartAreas[0].AxisX.Title = residualComboBox.SelectedItem.ToString(); 118 157 } 119 158 120 protected void Add RegressionSolution(IRegressionSolution solution) {159 protected void AddSeries(IRegressionSolution solution) { 121 160 if (chart.Series.Any(s => s.Name == solution.Name)) return; 122 161 … … 239 278 } 240 279 241 #region Baseline242 280 private void Chart_MouseDoubleClick(object sender, MouseEventArgs e) { 243 281 HitTestResult result = chart.HitTest(e.X, e.Y); … … 247 285 } 248 286 249 private ConstantRegressionSolution CreateConstantSolution() { 287 protected virtual IEnumerable<IRegressionSolution> CreateBaselineSolutions() { 288 yield return CreateConstantSolution(); 289 yield return CreateLinearSolution(); 290 } 291 292 private IRegressionSolution CreateConstantSolution() { 250 293 double averageTrainingTarget = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndices).Average(); 251 var model = new Constant RegressionModel(averageTrainingTarget);252 var solution = new ConstantRegressionSolution(model, (IRegressionProblemData)ProblemData.Clone());253 solution.Name = "Baseline ";294 var model = new ConstantModel(averageTrainingTarget, ProblemData.TargetVariable); 295 var solution = model.CreateRegressionSolution(ProblemData); 296 solution.Name = "Baseline (constant)"; 254 297 return solution; 255 298 } 256 #endregion 299 private IRegressionSolution CreateLinearSolution() { 300 double rmsError, cvRmsError; 301 var solution = LinearRegression.CreateLinearRegressionSolution((IRegressionProblemData)ProblemData.Clone(), out rmsError, out cvRmsError); 302 solution.Name = "Baseline (linear)"; 303 return solution; 304 } 257 305 258 306 private void chart_MouseMove(object sender, MouseEventArgs e) { … … 265 313 } 266 314 315 private void chart_DragDrop(object sender, DragEventArgs e) { 316 if (e.Data.GetDataPresent(HeuristicLab.Common.Constants.DragDropDataFormat)) { 317 318 var data = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat); 319 var dataAsRegressionSolution = data as IRegressionSolution; 320 var dataAsResult = data as IResult; 321 322 if (dataAsRegressionSolution != null) { 323 solutions.Add((IRegressionSolution)dataAsRegressionSolution.Clone()); 324 } else if (dataAsResult != null && dataAsResult.Value is IRegressionSolution) { 325 solutions.Add((IRegressionSolution)dataAsResult.Value.Clone()); 326 } 327 328 UpdateChart(); 329 } 330 } 331 332 private void chart_DragEnter(object sender, DragEventArgs e) { 333 e.Effect = DragDropEffects.None; 334 if (!e.Data.GetDataPresent(HeuristicLab.Common.Constants.DragDropDataFormat)) return; 335 336 var data = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat); 337 var dataAsRegressionSolution = data as IRegressionSolution; 338 var dataAsResult = data as IResult; 339 340 if (!ReadOnly && 341 (dataAsRegressionSolution != null || (dataAsResult != null && dataAsResult.Value is IRegressionSolution))) { 342 e.Effect = DragDropEffects.Copy; 343 } 344 } 345 267 346 private void residualComboBox_SelectedIndexChanged(object sender, EventArgs e) { 268 347 UpdateChart(); -
branches/crossvalidation-2434/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionEstimatedValuesView.cs
r12012 r14029 25 25 using HeuristicLab.Data.Views; 26 26 using HeuristicLab.MainForm; 27 using HeuristicLab.MainForm.WindowsForms;28 27 29 28 namespace HeuristicLab.Problems.DataAnalysis.Views { … … 68 67 } 69 68 70 pr ivatevoid Content_ProblemDataChanged(object sender, EventArgs e) {69 protected virtual void Content_ProblemDataChanged(object sender, EventArgs e) { 71 70 OnContentChanged(); 72 71 } 73 72 74 pr ivatevoid Content_ModelChanged(object sender, EventArgs e) {73 protected virtual void Content_ModelChanged(object sender, EventArgs e) { 75 74 OnContentChanged(); 76 75 } … … 81 80 } 82 81 83 private void UpdateEstimatedValues() { 82 protected virtual StringMatrix CreateValueMatrix() { 83 string[,] values = new string[Content.ProblemData.Dataset.Rows, 7]; 84 85 double[] target = Content.ProblemData.Dataset.GetDoubleValues(Content.ProblemData.TargetVariable).ToArray(); 86 var estimated = Content.EstimatedValues.GetEnumerator(); 87 var estimated_training = Content.EstimatedTrainingValues.GetEnumerator(); 88 var estimated_test = Content.EstimatedTestValues.GetEnumerator(); 89 90 foreach (var row in Content.ProblemData.TrainingIndices) { 91 estimated_training.MoveNext(); 92 values[row, 3] = estimated_training.Current.ToString(); 93 } 94 95 foreach (var row in Content.ProblemData.TestIndices) { 96 estimated_test.MoveNext(); 97 values[row, 4] = estimated_test.Current.ToString(); 98 } 99 100 foreach (var row in Enumerable.Range(0, Content.ProblemData.Dataset.Rows)) { 101 estimated.MoveNext(); 102 double est = estimated.Current; 103 double res = Math.Abs(est - target[row]); 104 values[row, 0] = row.ToString(); 105 values[row, 1] = target[row].ToString(); 106 values[row, 2] = est.ToString(); 107 values[row, 5] = Math.Abs(res).ToString(); 108 values[row, 6] = Math.Abs(res / target[row]).ToString(); 109 } 110 111 var matrix = new StringMatrix(values); 112 matrix.ColumnNames = new string[] { "Id", TARGETVARIABLE_SERIES_NAME, ESTIMATEDVALUES_SERIES_NAME, ESTIMATEDVALUES_TRAINING_SERIES_NAME, ESTIMATEDVALUES_TEST_SERIES_NAME, "Absolute Error (all)", "Relative Error (all)" }; 113 matrix.SortableView = true; 114 return matrix; 115 } 116 117 protected virtual void UpdateEstimatedValues() { 84 118 if (InvokeRequired) Invoke((Action)UpdateEstimatedValues); 85 119 else { 86 120 StringMatrix matrix = null; 87 121 if (Content != null) { 88 string[,] values = new string[Content.ProblemData.Dataset.Rows, 7]; 89 90 double[] target = Content.ProblemData.Dataset.GetDoubleValues(Content.ProblemData.TargetVariable).ToArray(); 91 var estimated = Content.EstimatedValues.GetEnumerator(); 92 var estimated_training = Content.EstimatedTrainingValues.GetEnumerator(); 93 var estimated_test = Content.EstimatedTestValues.GetEnumerator(); 94 95 foreach (var row in Content.ProblemData.TrainingIndices) { 96 estimated_training.MoveNext(); 97 values[row, 3] = estimated_training.Current.ToString(); 98 } 99 100 foreach (var row in Content.ProblemData.TestIndices) { 101 estimated_test.MoveNext(); 102 values[row, 4] = estimated_test.Current.ToString(); 103 } 104 105 foreach (var row in Enumerable.Range(0, Content.ProblemData.Dataset.Rows)) { 106 estimated.MoveNext(); 107 double est = estimated.Current; 108 double res = Math.Abs(est - target[row]); 109 values[row, 0] = row.ToString(); 110 values[row, 1] = target[row].ToString(); 111 values[row, 2] = est.ToString(); 112 values[row, 5] = Math.Abs(res).ToString(); 113 values[row, 6] = Math.Abs(res / target[row]).ToString(); 114 } 115 116 matrix = new StringMatrix(values); 117 matrix.ColumnNames = new string[] { "Id", TARGETVARIABLE_SERIES_NAME, ESTIMATEDVALUES_SERIES_NAME, ESTIMATEDVALUES_TRAINING_SERIES_NAME, ESTIMATEDVALUES_TEST_SERIES_NAME, "Absolute Error (all)", "Relative Error (all)" }; 118 matrix.SortableView = true; 122 matrix = CreateValueMatrix(); 119 123 } 120 124 matrixView.Content = matrix; -
branches/crossvalidation-2434/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionLineChartView.cs
r12012 r14029 26 26 using System.Windows.Forms.DataVisualization.Charting; 27 27 using HeuristicLab.MainForm; 28 using HeuristicLab.Visualization.ChartControlsExtensions; 28 29 29 30 namespace HeuristicLab.Problems.DataAnalysis.Views { … … 96 97 this.ToggleSeriesData(this.chart.Series[ESTIMATEDVALUES_ALL_SERIES_NAME]); 97 98 99 // set the y-axis bounds 100 var axisY = this.chart.ChartAreas[0].AxisY; 101 double min = double.MaxValue, max = double.MinValue; 102 foreach (var point in chart.Series.SelectMany(x => x.Points)) { 103 if (!point.YValues.Any() || double.IsInfinity(point.YValues[0]) || double.IsNaN(point.YValues[0])) 104 continue; 105 var y = point.YValues[0]; 106 if (y < min) 107 min = y; 108 if (y > max) 109 max = y; 110 } 111 112 double axisMin, axisMax, axisInterval; 113 ChartUtil.CalculateOptimalAxisInterval(min, max, out axisMin, out axisMax, out axisInterval); 114 axisY.Minimum = axisMin; 115 axisY.Maximum = axisMax; 116 axisY.Interval = axisInterval; 117 98 118 UpdateCursorInterval(); 99 119 this.UpdateStripLines(); -
branches/crossvalidation-2434/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionScatterPlotView.cs
r12509 r14029 26 26 using HeuristicLab.MainForm; 27 27 using HeuristicLab.MainForm.WindowsForms; 28 using HeuristicLab.Visualization.ChartControlsExtensions; 28 29 29 30 namespace HeuristicLab.Problems.DataAnalysis.Views { … … 35 36 private const string TEST_SERIES = "Test samples"; 36 37 38 private const int OPACITY_LEVEL = 150; 39 37 40 public new IRegressionSolution Content { 38 41 get { return (IRegressionSolution)base.Content; } … … 59 62 this.chart.TextAntiAliasingQuality = TextAntiAliasingQuality.High; 60 63 this.chart.AxisViewChanged += new EventHandler<System.Windows.Forms.DataVisualization.Charting.ViewEventArgs>(chart_AxisViewChanged); 64 65 //make series colors semi transparent 66 this.chart.ApplyPaletteColors(); 67 this.chart.Series[ALL_SERIES].Color = Color.FromArgb(OPACITY_LEVEL, this.chart.Series[ALL_SERIES].Color); 68 this.chart.Series[TRAINING_SERIES].Color = Color.FromArgb(OPACITY_LEVEL, this.chart.Series[TRAINING_SERIES].Color); 69 this.chart.Series[TEST_SERIES].Color = Color.FromArgb(OPACITY_LEVEL, this.chart.Series[TEST_SERIES].Color); 70 71 //change all markers to circles 72 this.chart.Series[ALL_SERIES].MarkerStyle = MarkerStyle.Circle; 73 this.chart.Series[TRAINING_SERIES].MarkerStyle = MarkerStyle.Circle; 74 this.chart.Series[TEST_SERIES].MarkerStyle = MarkerStyle.Circle; 61 75 62 76 //configure axis … … 156 170 double min = Content.EstimatedTrainingValues.Concat(Content.EstimatedTestValues.Concat(Content.EstimatedValues.Concat(dataset.GetDoubleValues(targetVariableName)))).Min(); 157 171 158 max = max + 0.2 * Math.Abs(max); 159 min = min - 0.2 * Math.Abs(min); 160 161 double interestingValuesRange = max - min; 162 int digits = Math.Max(0, 3 - (int)Math.Log10(interestingValuesRange)); 163 164 max = Math.Round(max, digits); 165 min = Math.Round(min, digits); 166 167 this.chart.ChartAreas[0].AxisX.Maximum = max; 168 this.chart.ChartAreas[0].AxisX.Minimum = min; 169 this.chart.ChartAreas[0].AxisY.Maximum = max; 170 this.chart.ChartAreas[0].AxisY.Minimum = min; 172 double axisMin, axisMax, axisInterval; 173 ChartUtil.CalculateOptimalAxisInterval(min, max, out axisMin, out axisMax, out axisInterval); 174 this.chart.ChartAreas[0].AxisX.Maximum = axisMax; 175 this.chart.ChartAreas[0].AxisX.Minimum = axisMin; 176 this.chart.ChartAreas[0].AxisX.Interval = axisInterval; 177 this.chart.ChartAreas[0].AxisY.Maximum = axisMax; 178 this.chart.ChartAreas[0].AxisY.Minimum = axisMin; 179 this.chart.ChartAreas[0].AxisY.Interval = axisInterval; 180 171 181 UpdateCursorInterval(); 172 182 }
Note: See TracChangeset
for help on using the changeset viewer.